diff options
Diffstat (limited to 'railties/guides/rails_guides/generator.rb')
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 670d2bc4db..d0873bfed5 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -11,11 +11,14 @@ require 'rails_guides/levenshtein' module RailsGuides class Generator - attr_reader :guides_dir, :source_dir, :output_dir + attr_reader :guides_dir, :source_dir, :output_dir, :edge + + GUIDES_RE = /\.(?:textile|html\.erb)$/ def initialize(output=nil) initialize_dirs(output) create_output_dir_if_needed + set_edge end def generate @@ -32,7 +35,11 @@ module RailsGuides def create_output_dir_if_needed FileUtils.mkdir_p(output_dir) - end + end + + def set_edge + @edge = ENV['EDGE_GUIDES'] == '1' + end def generate_guides guides_to_generate.each do |guide| @@ -42,7 +49,7 @@ module RailsGuides end def guides_to_generate - guides = Dir.entries(source_dir).grep(/\.textile(?:\.erb)?$/) + guides = Dir.entries(source_dir).grep(GUIDES_RE) ENV.key?("ONLY") ? select_only(guides) : guides end @@ -54,12 +61,12 @@ module RailsGuides end def copy_assets - FileUtils.cp_r(File.join(guides_dir, 'images'), File.join(output_dir, 'images')) - FileUtils.cp_r(File.join(guides_dir, 'files'), File.join(output_dir, 'files')) + FileUtils.cp_r(File.join(guides_dir, 'images'), output_dir) + FileUtils.cp_r(File.join(guides_dir, 'files'), output_dir) end def output_file_for(guide) - guide.sub(/\.textile(?:\.erb)?$/, '.html') + guide.sub(GUIDES_RE, '.html') end def generate?(source_file, output_file) @@ -71,13 +78,12 @@ module RailsGuides 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) + view = ActionView::Base.new(source_dir, :edge => edge) view.extend(Helpers) - - if guide =~ /\.textile\.erb$/ - # Generate the erb pages with textile formatting - e.g. index/authors + + if guide =~ /\.html\.erb$/ + # Generate the special pages like the home. result = view.render(:layout => 'layout', :file => guide) - result = textile(result) else body = File.read(File.join(source_dir, guide)) body = set_header_section(body, view) @@ -87,8 +93,7 @@ module RailsGuides warn_about_broken_links(result) if ENV.key?("WARN_BROKEN_LINKS") end - - result = insert_edge_badge(result) if ENV.key?('INSERT_EDGE_BADGE') + f.write result end end @@ -126,7 +131,7 @@ module RailsGuides view.content_tag(:li, l.html_safe) end - children_ul = view.content_tag(:ul, children.join(" ").html_safe) + children_ul = children.empty? ? "" : view.content_tag(:ul, children.join(" ").html_safe) index << view.content_tag(:li, link.html_safe + children_ul.html_safe) end @@ -199,9 +204,5 @@ module RailsGuides end end end - - def insert_edge_badge(html) - html.sub(/<body[^>]*>/, '\&<img src="images/edge_badge.png" style="position:fixed; right:0px; top:0px; border:none; z-index:100"/>') - end end end |