mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
let the guides generator warn about broken links
This commit is contained in:
parent
626c724b62
commit
da5549b83f
1 changed files with 18 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'set'
|
||||||
|
|
||||||
module RailsGuides
|
module RailsGuides
|
||||||
class Generator
|
class Generator
|
||||||
attr_reader :output, :view_path, :view, :guides_dir
|
attr_reader :output, :view_path, :view, :guides_dir
|
||||||
|
@ -55,6 +57,7 @@ module RailsGuides
|
||||||
|
|
||||||
result = view.render(:layout => 'layout', :text => textile(body))
|
result = view.render(:layout => 'layout', :text => textile(body))
|
||||||
f.write result
|
f.write result
|
||||||
|
warn_about_broken_links(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -110,5 +113,20 @@ module RailsGuides
|
||||||
t.hard_breaks = false
|
t.hard_breaks = false
|
||||||
t.to_html(:notestuff, :plusplus, :code, :tip)
|
t.to_html(:notestuff, :plusplus, :code, :tip)
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue