Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

guides: badge insertion was a quick hack, rewrites that

  • Loading branch information...
commit 4e391a3d4976814b623ebd86ee8d7b5fd17e8af5 1 parent eb33f0f
@fxn fxn authored
View
11 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;
+}
View
25 railties/guides/rails_guides/generator.rb
@@ -11,13 +11,14 @@
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 @@ def initialize_dirs(output)
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 @@ def select_only(guides)
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 @@ def generate?(source_file, output_file)
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 @@ def generate_guide(guide, output_file)
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 @@ def check_fragment_identifiers(html, anchors)
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
View
5 railties/guides/source/layout.html.erb
@@ -17,6 +17,11 @@
</head>
<body class="guide">
+ <% if @edge %>
+ <div>
+ <img src="images/edge_badge.png" alt="edge-badge" id="edge-badge" />
+ </div>
+ <% end %>
<div id="topNav">
<div class="wrapper">
<strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
Please sign in to comment.
Something went wrong with that request. Please try again.