diff --git a/railties/guides/assets/images/rails_guides_kindle_cover.jpg b/railties/guides/assets/images/rails_guides_kindle_cover.jpg new file mode 100644 index 0000000000..9eb16720a9 Binary files /dev/null and b/railties/guides/assets/images/rails_guides_kindle_cover.jpg differ diff --git a/railties/guides/assets/stylesheets/kindle.css b/railties/guides/assets/stylesheets/kindle.css new file mode 100644 index 0000000000..b26cd1786a --- /dev/null +++ b/railties/guides/assets/stylesheets/kindle.css @@ -0,0 +1,11 @@ +p { text-indent: 0; } + +p, H1, H2, H3, H4, H5, H6, H7, H8, table { margin-top: 1em;} + +.pagebreak { page-break-before: always; } +#toc H3 { + text-indent: 1em; +} +#toc .document { + text-indent: 2em; +} \ No newline at end of file diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 6f6d3bda80..f0fdaf9ac2 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -47,6 +47,11 @@ # Set to "1" to indicate generated guides should be marked as edge. This # inserts a badge and changes the preamble of the home page. # +# KINDLE +# Set to "1" to generate the .mobi with all the guides. The kindlegen +# executable must be in your PATH. Google for it if you do not have it +# locally, it is available from Amazon for free. +# # --------------------------------------------------------------------------- require 'set' @@ -65,35 +70,70 @@ module RailsGuides class Generator attr_reader :guides_dir, :source_dir, :output_dir, :edge, :warnings, :all - GUIDES_RE = /\.(?:textile|html\.erb)$/ + GUIDES_RE = /\.(?:textile|erb)$/ def initialize(output=nil) - @lang = ENV['GUIDES_LANGUAGE'] + set_flags_from_environment + + if kindle? + check_for_kindlegen + register_kindle_mime_types + end + initialize_dirs(output) create_output_dir_if_needed - set_flags_from_environment - end - - def generate - generate_guides - copy_assets - end - - private - def initialize_dirs(output) - @guides_dir = File.join(File.dirname(__FILE__), '..') - @source_dir = File.join(@guides_dir, "source", @lang.to_s) - @output_dir = output || File.join(@guides_dir, "output", @lang.to_s) - end - - def create_output_dir_if_needed - FileUtils.mkdir_p(output_dir) end def set_flags_from_environment @edge = ENV['EDGE'] == '1' @warnings = ENV['WARNINGS'] == '1' @all = ENV['ALL'] == '1' + @kindle = ENV['KINDLE'] == '1' + @version = ENV['RAILS_VERSION'] || `git rev-parse --short HEAD`.chomp + @lang = ENV['GUIDES_LANGUAGE'] + end + + def register_kindle_mime_types + Mime::Type.register_alias("application/xml", :opf, %w(opf)) + Mime::Type.register_alias("application/xml", :ncx ,%w(ncx)) + end + + def generate + generate_guides + copy_assets + generate_mobi if kindle? + end + + private + + def kindle? + @kindle + end + + def check_for_kindlegen + if `which kindlegen`.blank? + raise "Can't create a kindle version without `kindlegen`." + end + end + + def generate_mobi + system "kindlegen #{output_dir}/rails_guides.opf -o #{kindle_output_file} > #{output_dir}/kindlegen.out 2>&1" + puts "Guides compiled as Kindle book to #{kindle_output_file}" + puts "(kindlegen log at #{output_dir}/kindlegen.out)." + end + + def kindle_output_file + "rails_guides_#@version%s.mobi" % (@lang.present? ? ".#@lang" : '') + end + + def initialize_dirs(output) + @guides_dir = File.join(File.dirname(__FILE__), '..') + @source_dir = "#@guides_dir/source/#@lang" + @output_dir = output || "#@guides_dir/output/#@lang" + end + + def create_output_dir_if_needed + FileUtils.mkdir_p(output_dir) end def generate_guides @@ -105,6 +145,13 @@ module RailsGuides def guides_to_generate guides = Dir.entries(source_dir).grep(GUIDES_RE) + + if kindle? + Dir.entries("#{source_dir}/kindle").grep(GUIDES_RE).map do |entry| + guides << "kindle/#{entry}" + end + end + ENV.key?('ONLY') ? select_only(guides) : guides end @@ -120,36 +167,47 @@ module RailsGuides end def output_file_for(guide) - guide.sub(GUIDES_RE, '.html') + if guide =~/\.textile$/ + guide.sub(/\.textile$/, '.html') + else + guide.sub(/\.erb$/, '') + end + end + + def output_path_for(output_file) + File.join(output_dir, File.basename(output_file)) end def generate?(source_file, output_file) fin = File.join(source_dir, source_file) - fout = File.join(output_dir, output_file) + fout = output_path_for(output_file) all || !File.exists?(fout) || File.mtime(fout) < File.mtime(fin) end def generate_guide(guide, output_file) - puts "Generating #{output_file}" - File.open(File.join(output_dir, output_file), 'w') do |f| - view = ActionView::Base.new(source_dir, :edge => edge) + output_path = output_path_for(output_file) + puts "Generating #{guide} as #{output_file}" + layout = guide.start_with?('kindle/') ? 'kindle/layout' : 'layout' + + File.open(output_path, 'w') do |f| + view = ActionView::Base.new(source_dir, :version => @version) view.extend(Helpers) - if guide =~ /\.html\.erb$/ + if guide =~ /\.(\w+)\.erb$/ # Generate the special pages like the home. # Passing a template handler in the template name is deprecated. So pass the file name without the extension. - result = view.render(:layout => 'layout', :file => $`) + result = view.render(:layout => layout, :formats => [$1], :file => $`) else body = File.read(File.join(source_dir, guide)) body = set_header_section(body, view) body = set_index(body, view) - result = view.render(:layout => 'layout', :text => textile(body)) + result = view.render(:layout => layout, :text => textile(body)) warn_about_broken_links(result) if @warnings end - f.write result + f.write(result) end end diff --git a/railties/guides/rails_guides/helpers.rb b/railties/guides/rails_guides/helpers.rb index 463df8a7a8..45ad9b9588 100644 --- a/railties/guides/rails_guides/helpers.rb +++ b/railties/guides/rails_guides/helpers.rb @@ -11,6 +11,14 @@ module RailsGuides result << content_tag(:dd, capture(&block)) result end + + def documents_by_section + @documents_by_section ||= YAML.load_file(File.expand_path('../../source/documents.yaml', __FILE__)) + end + + def documents_flat + documents_by_section.map {|section| section['documents']}.flatten + end def author(name, nick, image = 'credits_pic_blank.gif', &block) image = "images/#{image}" diff --git a/railties/guides/source/_license.html.erb b/railties/guides/source/_license.html.erb new file mode 100644 index 0000000000..00b4466f50 --- /dev/null +++ b/railties/guides/source/_license.html.erb @@ -0,0 +1,2 @@ +
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License
+"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.
diff --git a/railties/guides/source/_welcome.html.erb b/railties/guides/source/_welcome.html.erb new file mode 100644 index 0000000000..a5ceeee5f2 --- /dev/null +++ b/railties/guides/source/_welcome.html.erb @@ -0,0 +1,21 @@ ++ These are Edge Guides, based on the current + master branch. +
++ If you are looking for the ones for the stable version please check + http://guides.rubyonrails.org instead. +
+<% else %> ++ These are the new guides for Rails 3. The guides for Rails 2.3 are still available + at http://guides.rubyonrails.org/v2.3.11/. +
+<% end %> ++ These guides are designed to make you immediately productive with Rails, + and to help you understand how all of the pieces fit together. +
diff --git a/railties/guides/source/documents.yaml b/railties/guides/source/documents.yaml new file mode 100644 index 0000000000..dccfefb4fb --- /dev/null +++ b/railties/guides/source/documents.yaml @@ -0,0 +1,153 @@ +- + name: Start Here + documents: + - + name: Getting Started with Rails + url: getting_started.html + description: Everything you need to know to install Rails and create your first application. +- + name: Models + documents: + - + name: Rails Database Migrations + url: migrations.html + description: This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner. + - + name: Active Record Validations and Callbacks + url: active_record_validations_callbacks.html + description: This guide covers how you can use Active Record validations and callbacks. + - + name: Active Record Associations + url: association_basics.html + description: This guide covers all the associations provided by Active Record. + - + name: Active Record Query Interface + url: active_record_querying.html + description: This guide covers the database query interface provided by Active Record. +- + name: Views + documents: + - + name: Layouts and Rendering in Rails + url: layouts_and_rendering.html + description: This guide covers the basic layout features of Action Controller and Action View, including rendering and redirecting, using content_for blocks, and working with partials. + - + name: Action View Form Helpers + url: form_helpers.html + description: Guide to using built-in Form helpers. +- + name: Controllers + documents: + - + name: Action Controller Overview + url: action_controller_overview.html + description: This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics. + - + name: Rails Routing from the Outside In + url: routing.html + description: This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here. +- + name: Digging Deeper + documents: + - + name: Active Support Core Extensions + url: active_support_core_extensions.html + description: This guide documents the Ruby core extensions defined in Active Support. + - + name: Rails Internationalization API + url: i18n.html + description: This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on. + - + name: Action Mailer Basics + url: action_mailer_basics.html + work_in_progress: true + description: This guide describes how to use Action Mailer to send and receive emails. + - + name: Testing Rails Applications + url: testing.html + work_in_progress: true + description: This is a rather comprehensive guide to doing both unit and functional tests in Rails. It covers everything from 'What is a test?' to the testing APIs. Enjoy. + - + name: Securing Rails Applications + url: security.html + description: This guide describes common security problems in web applications and how to avoid them with Rails. + - + name: Debugging Rails Applications + url: debugging_rails_applications.html + description: This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening "behind the scenes" of your code. + - + name: Performance Testing Rails Applications + url: performance_testing.html + description: This guide covers the various ways of performance testing a Ruby on Rails application. + - + name: Configuring Rails Applications + url: configuring.html + description: This guide covers the basic configuration settings for a Rails application. + - + name: Rails Command Line Tools and Rake tasks + url: command_line.html + description: This guide covers the command line tools and rake tasks provided by Rails. + - + name: Caching with Rails + work_in_progress: true + url: caching_with_rails.html + description: Various caching techniques provided by Rails. + - + name: Asset Pipeline + url: asset_pipeline.html + description: This guide documents the asset pipeline. + - + name: The Rails Initialization Process + work_in_progress: true + url: initialization.html + description: This guide explains the internals of the Rails initialization process as of Rails 3.1 +- + name: Extending Rails + documents: + - + name: The Basics of Creating Rails Plugins + work_in_progress: true + url: plugins.html + description: This guide covers how to build a plugin to extend the functionality of Rails. + - + name: Rails on Rack + url: rails_on_rack.html + description: This guide covers Rails integration with Rack and interfacing with other Rack components. + - + name: Creating and Customizing Rails Generators + url: generators.html + description: This guide covers the process of adding a brand new generator to your extension or providing an alternative to an element of a built-in Rails generator (such as providing alternative test stubs for the scaffold generator). +- + name: Contributing to Ruby on Rails + documents: + - + name: Contributing to Ruby on Rails + url: contributing_to_ruby_on_rails.html + description: Rails is not 'somebody else's framework.' This guide covers a variety of ways that you can get involved in the ongoing development of Rails. + - + name: API Documentation Guidelines + url: api_documentation_guidelines.html + description: This guide documents the Ruby on Rails API documentation guidelines. + - + name: Ruby on Rails Guides Guidelines + url: ruby_on_rails_guides_guidelines.html + description: This guide documents the Ruby on Rails guides guidelines. +- + name: Release Notes + documents: + - + name: Ruby on Rails 3.1 Release Notes + url: 3_1_release_notes.html + description: Release notes for Rails 3.1. + - + name: Ruby on Rails 3.0 Release Notes + url: 3_0_release_notes.html + description: Release notes for Rails 3.0. + - + name: Ruby on Rails 2.3 Release Notes + url: 2_3_release_notes.html + description: Release notes for Rails 2.3. + - + name: Ruby on Rails 2.2 Release Notes + url: 2_2_release_notes.html + description: Release notes for Rails 2.2. diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index c9a8c4fa5c..da1a37015b 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -3,28 +3,7 @@ Ruby on Rails Guides <% end %> <% content_for :header_section do %> -- These are Edge Guides, based on the current - master branch. -
-- If you are looking for the ones for the stable version please check - http://guides.rubyonrails.org instead. -
-<% else %> -- These are the new guides for Rails 3. The guides for Rails 2.3 are still available - at http://guides.rubyonrails.org/v2.3.11/. -
-<% end %> -- These guides are designed to make you immediately productive with Rails, - and to help you understand how all of the pieces fit together. -
- +<%= render 'welcome' %> <% end %> <% content_for :index_section do %> @@ -35,157 +14,13 @@ Ruby on Rails Guides <% end %> -Everything you need to know to install Rails and create your first application.
+<% documents_by_section.each do |section| %> +<%= document['description'] %>
+ <% end %> + <% end %> +This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.
-<% end %> - -<%= guide("Active Record Validations and Callbacks", 'active_record_validations_callbacks.html') do %> -This guide covers how you can use Active Record validations and callbacks.
-<% end %> - -<%= guide("Active Record Associations", 'association_basics.html') do %> -This guide covers all the associations provided by Active Record.
-<% end %> - -<%= guide("Active Record Query Interface", 'active_record_querying.html') do %> -This guide covers the database query interface provided by Active Record.
-<% end %> -This guide covers the basic layout features of Action Controller and Action View, including rendering and redirecting, using content_for blocks, and working with partials.
-<% end %> - -<%= guide("Action View Form Helpers", 'form_helpers.html', :work_in_progress => true) do %> -Guide to using built-in Form helpers.
-<% end %> -This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics.
-<% end %> - -<%= guide("Rails Routing from the Outside In", 'routing.html') do %> -This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here.
-<% end %> -This guide documents the Ruby core extensions defined in Active Support.
-<% end %> - -<%= guide("Rails Internationalization API", 'i18n.html') do %> -This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on.
-<% end %> - -<%= guide("Action Mailer Basics", 'action_mailer_basics.html', :work_in_progress => true) do %> -This guide describes how to use Action Mailer to send and receive emails.
-<% end %> - -<%= guide("Testing Rails Applications", 'testing.html', :work_in_progress => true) do %> -This is a rather comprehensive guide to doing both unit and functional tests in Rails. It covers everything from "What is a test?" to the testing APIs. Enjoy.
-<% end %> - -<%= guide("Securing Rails Applications", 'security.html') do %> -This guide describes common security problems in web applications and how to avoid them with Rails.
-<% end %> - -<%= guide("Debugging Rails Applications", 'debugging_rails_applications.html') do %> -This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening "behind the scenes" of your code.
-<% end %> - -<%= guide("Performance Testing Rails Applications", 'performance_testing.html') do %> -This guide covers the various ways of performance testing a Ruby on Rails application.
-<% end %> - -<%= guide("Configuring Rails Applications", 'configuring.html') do %> -This guide covers the basic configuration settings for a Rails application.
-<% end %> - -<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html') do %> -This guide covers the command line tools and rake tasks provided by Rails.
-<% end %> - -<%= guide("Caching with Rails", 'caching_with_rails.html', :work_in_progress => true) do %> -Various caching techniques provided by Rails.
-<% end %> - -<%= guide('Asset Pipeline', 'asset_pipeline.html') do %> -This guide documents the asset pipeline.
-<% end %> -This guide covers how to build a plugin to extend the functionality of Rails.
- <% end %> - - <%= guide("Rails on Rack", 'rails_on_rack.html') do %> -This guide covers Rails integration with Rack and interfacing with other Rack components.
- <% end %> - - <%= guide("Creating and Customizing Rails Generators", 'generators.html') do %> -This guide covers the process of adding a brand new generator to your extension - or providing an alternative to an element of a built-in Rails generator (such as - providing alternative test stubs for the scaffold generator).
- <% end %> -Rails is not "somebody else's framework." This guide covers a variety of ways that you can get involved in the ongoing development of Rails.
- <% end %> - - <%= guide('API Documentation Guidelines', 'api_documentation_guidelines.html') do %> -This guide documents the Ruby on Rails API documentation guidelines.
- <% end %> - - <%= guide('Ruby on Rails Guides Guidelines', 'ruby_on_rails_guides_guidelines.html') do %> -This guide documents the Ruby on Rails guides guidelines.
- <% end %> -Release notes for Rails 3.1.
-<% end %> - -<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %> -Release notes for Rails 3.0.
-<% end %> - -<%= guide("Ruby on Rails 2.3 Release Notes", '2_3_release_notes.html') do %> -Release notes for Rails 2.3.
-<% end %> - -<%= guide("Ruby on Rails 2.2 Release Notes", '2_2_release_notes.html') do %> -Release notes for Rails 2.2.
-<% end %> -