aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/rails_guides
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-04-02 14:53:39 -0700
committerXavier Noria <fxn@hashref.com>2010-04-02 14:53:39 -0700
commit4e391a3d4976814b623ebd86ee8d7b5fd17e8af5 (patch)
tree55defc38eb29b6a47ea099778cb5990066dfc85a /railties/guides/rails_guides
parenteb33f0fe74f5a503963fae03be3f4b511dd53c59 (diff)
downloadrails-4e391a3d4976814b623ebd86ee8d7b5fd17e8af5.tar.gz
rails-4e391a3d4976814b623ebd86ee8d7b5fd17e8af5.tar.bz2
rails-4e391a3d4976814b623ebd86ee8d7b5fd17e8af5.zip
guides: badge insertion was a quick hack, rewrites that
Diffstat (limited to 'railties/guides/rails_guides')
-rw-r--r--railties/guides/rails_guides/generator.rb25
1 files changed, 12 insertions, 13 deletions
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(/<body[^>]*>/, '\&<div><img src="images/edge_badge.png" alt="edge badge" style="position:fixed; right:0px; top:0px; border:none; z-index:100"/></div>')
- end
end
end