From 4e391a3d4976814b623ebd86ee8d7b5fd17e8af5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 2 Apr 2010 14:53:39 -0700 Subject: guides: badge insertion was a quick hack, rewrites that --- railties/guides/files/stylesheets/main.css | 11 +++++++++++ railties/guides/rails_guides/generator.rb | 25 ++++++++++++------------- railties/guides/source/layout.html.erb | 5 +++++ 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/files/stylesheets/main.css b/railties/guides/files/stylesheets/main.css index d377628d73..2fd0a2f37e 100644 --- a/railties/guides/files/stylesheets/main.css +++ b/railties/guides/files/stylesheets/main.css @@ -439,3 +439,14 @@ spurious blank area below with the box background. */ div.important p, div.caution p, div.warning p, div.note p, div.info p { margin-bottom: 0px; } + +/* Edge Badge +--------------------------------------- */ + +#edge-badge { + position: fixed; + right: 0px; + top: 0px; + z-index: 100; + border: none; +} diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index c40bbc32da..d0873bfed5 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -11,13 +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 @@ -34,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| @@ -56,8 +61,8 @@ 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) @@ -73,11 +78,11 @@ 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 =~ /\.html\.erb$/ - # Generate the erb pages with textile formatting - e.g. index/authors + # Generate the special pages like the home. result = view.render(:layout => 'layout', :file => guide) else body = File.read(File.join(source_dir, guide)) @@ -89,8 +94,6 @@ 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 @@ -201,9 +204,5 @@ module RailsGuides end end end - - def insert_edge_badge(html) - html.sub(/]*>/, '\&
edge badge
') - end end end diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index 95be1d2eab..9819db1f89 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -17,6 +17,11 @@ + <% if @edge %> +
+ edge-badge +
+ <% end %>
More at rubyonrails.org: -- cgit v1.2.3