diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-02-28 19:44:25 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-02-28 19:44:25 +0000 |
commit | 0db6c3f51828e1a37e2c7b9245ffa8c12ac59c83 (patch) | |
tree | 6d4655e5982c7194f9c1a57f0a1d888cf93ad290 /railties/guides/rails_guides | |
parent | 5029210914059faa65358b98a9c033a40e803c54 (diff) | |
download | rails-0db6c3f51828e1a37e2c7b9245ffa8c12ac59c83.tar.gz rails-0db6c3f51828e1a37e2c7b9245ffa8c12ac59c83.tar.bz2 rails-0db6c3f51828e1a37e2c7b9245ffa8c12ac59c83.zip |
Merge docrails and update the release notes
Diffstat (limited to 'railties/guides/rails_guides')
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 46 | ||||
-rw-r--r-- | railties/guides/rails_guides/textile_extensions.rb | 4 |
2 files changed, 45 insertions, 5 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 41d22e37fd..18fdb81810 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -1,3 +1,5 @@ +require 'set' + module RailsGuides class Generator attr_reader :output, :view_path, :view, :guides_dir @@ -55,6 +57,7 @@ module RailsGuides result = view.render(:layout => 'layout', :text => textile(body)) f.write result + warn_about_broken_links(result) end end end @@ -106,9 +109,46 @@ module RailsGuides end def textile(body) - t = RedCloth.new(body) - t.hard_breaks = false - t.to_html(:notestuff, :plusplus, :code, :tip) + # If the issue with nontextile is fixed just remove the wrapper. + with_workaround_for_nontextile(body) do |body| + t = RedCloth.new(body) + t.hard_breaks = false + t.to_html(:notestuff, :plusplus, :code, :tip) + end + end + + # For some reason the notextile tag does not always turn off textile. See + # LH ticket of the security guide (#7). As a temporary workaround we deal + # with code blocks by hand. + def with_workaround_for_nontextile(body) + code_blocks = [] + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m| + es = ERB::Util.h($2) + css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 + code_blocks << %{<div class="code_container"><code class="#{css_class}">#{es}</code></div>} + "dirty_workaround_for_nontextile_#{code_blocks.size - 1}" + end + + body = yield body + + body.gsub(%r{<p>dirty_workaround_for_nontextile_(\d+)</p>}) do |_| + code_blocks[$1.to_i] + end + end + + def warn_about_broken_links(html) + # Textile generates headers with IDs computed from titles. + anchors = Set.new(html.scan(/<h\d\s+id="([^"]+)/).flatten) + # Also, footnotes are rendered as paragraphs this way. + anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten) + + # Check fragment identifiers. + html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier| + next if fragment_identifier == 'mainCol' # in layout, jumps to some DIV + unless anchors.member?(fragment_identifier) + puts "BROKEN LINK: ##{fragment_identifier}" + end + end end end end diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb index 7ebbf0090e..b22be5752d 100644 --- a/railties/guides/rails_guides/textile_extensions.rb +++ b/railties/guides/rails_guides/textile_extensions.rb @@ -31,10 +31,10 @@ module RailsGuides end def code(body) - body.gsub!(/\<(yaml|shell|ruby|erb|html|sql)\>(.*?)\<\/\1\>/m) do |m| + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m| es = ERB::Util.h($2) css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 - "<notextile><code class='#{css_class}'>#{es}\n</code></notextile>" + %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>} end end end |