diff options
author | Xavier Noria <fxn@hashref.com> | 2009-02-28 03:24:23 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2009-02-28 03:24:23 +0100 |
commit | da5549b83fe7bf2c36e695e570a12d2fc9e8bbbd (patch) | |
tree | f4ab9751d3a13d764ca0a4021b97630c6515ad06 /railties/guides | |
parent | 626c724b62d86046a96f3d2cdeeffc67e60f40e0 (diff) | |
download | rails-da5549b83fe7bf2c36e695e570a12d2fc9e8bbbd.tar.gz rails-da5549b83fe7bf2c36e695e570a12d2fc9e8bbbd.tar.bz2 rails-da5549b83fe7bf2c36e695e570a12d2fc9e8bbbd.zip |
let the guides generator warn about broken links
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 41d22e37fd..085605a0d4 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 @@ -110,5 +113,20 @@ module RailsGuides t.hard_breaks = false t.to_html(:notestuff, :plusplus, :code, :tip) 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 |