diff options
Diffstat (limited to 'railties/guides/rails_guides')
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 26 | ||||
-rw-r--r-- | railties/guides/rails_guides/indexer.rb | 2 |
2 files changed, 6 insertions, 22 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 18fdb81810..6c0d9f3c3b 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -57,7 +57,6 @@ module RailsGuides result = view.render(:layout => 'layout', :text => textile(body)) f.write result - warn_about_broken_links(result) end end end @@ -109,8 +108,8 @@ module RailsGuides end def textile(body) - # If the issue with nontextile is fixed just remove the wrapper. - with_workaround_for_nontextile(body) do |body| + # If the issue with notextile is fixed just remove the wrapper. + with_workaround_for_notextile(body) do |body| t = RedCloth.new(body) t.hard_breaks = false t.to_html(:notestuff, :plusplus, :code, :tip) @@ -120,35 +119,20 @@ module RailsGuides # 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) + def with_workaround_for_notextile(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}" + "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n" end body = yield body - body.gsub(%r{<p>dirty_workaround_for_nontextile_(\d+)</p>}) do |_| + body.gsub(%r{<p>dirty_workaround_for_notextile_(\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/indexer.rb b/railties/guides/rails_guides/indexer.rb index 7cb254d0b0..5b5ad3fee1 100644 --- a/railties/guides/rails_guides/indexer.rb +++ b/railties/guides/rails_guides/indexer.rb @@ -29,7 +29,7 @@ module RailsGuides return level_hash elsif level == current_level index = counters.join(".") - bookmark = '#' + title.gsub(/[^a-z0-9\-_]+/i, '').underscore.dasherize + bookmark = '#' + title.strip.downcase.gsub(/\s+|_/, '-').delete('^a-z0-9-') raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}") |