Skip to content

Commit

Permalink
Try to use actionpack gem to generate guide when Rails is not vendored
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Mar 17, 2009
1 parent 18eb80c commit dc88847
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 155 deletions.
28 changes: 19 additions & 9 deletions railties/guides/rails_guides.rb
@@ -1,17 +1,28 @@
pwd = File.dirname(__FILE__)
$: << pwd
$: << File.join(pwd, "../../activesupport/lib")
$: << File.join(pwd, "../../actionpack/lib")

require "action_controller"
require "action_view"
begin
as_lib = File.join(pwd, "../../activesupport/lib")
ap_lib = File.join(pwd, "../../actionpack/lib")

$: << as_lib if File.directory?(as_lib)
$: << ap_lib if File.directory?(ap_lib)

require "action_controller"
require "action_view"
rescue LoadError
require 'rubygems'
gem "actionpack", '>= 2.3'

require "action_controller"
require "action_view"
end

# Require rubygems after loading Action View
require 'rubygems'
begin
gem 'RedCloth', '>= 4.1.1'# Need exactly 4.1.1
require 'rubygems'
gem 'RedCloth', '>= 4.1.1'
rescue Gem::LoadError
$stderr.puts %(Missing the RedCloth 4.1.1 gem.\nPlease `gem install -v=4.1.1 RedCloth` to generate the guides.)
$stderr.puts %(Generating Guides requires RedCloth 4.1.1+)
exit 1
end

Expand All @@ -22,7 +33,6 @@ module RailsGuides
autoload :Indexer, "rails_guides/indexer"
autoload :Helpers, "rails_guides/helpers"
autoload :TextileExtensions, "rails_guides/textile_extensions"
autoload :Levenshtein, "rails_guides/levenshtein"
end

RedCloth.send(:include, RailsGuides::TextileExtensions)
Expand Down
34 changes: 0 additions & 34 deletions railties/guides/rails_guides/generator.rb
Expand Up @@ -57,7 +57,6 @@ def generate_guide(guide)

result = view.render(:layout => 'layout', :text => textile(body))
f.write result
warn_about_broken_links(result)
end
end
end
Expand Down Expand Up @@ -135,38 +134,5 @@ def with_workaround_for_notextile(body)
code_blocks[$1.to_i]
end
end

def warn_about_broken_links(html)
anchors = extract_anchors(html)
check_fragment_identifiers(html, anchors)
end

def extract_anchors(html)
# Textile generates headers with IDs computed from titles.
anchors = Set.new
html.scan(/<h\d\s+id="([^"]+)/).flatten.each do |anchor|
if anchors.member?(anchor)
puts "*** DUPLICATE HEADER ID: #{anchor}, please consider rewording"
else
anchors << anchor
end
end

# Also, footnotes are rendered as paragraphs this way.
anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten)
return anchors
end

def check_fragment_identifiers(html, anchors)
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)
guess = anchors.min { |a, b|
Levenshtein.distance(fragment_identifier, a) <=> Levenshtein.distance(fragment_identifier, b)
}
puts "*** BROKEN LINK: ##{fragment_identifier}, perhaps you meant ##{guess}."
end
end
end
end
end
112 changes: 0 additions & 112 deletions railties/guides/rails_guides/levenshtein.rb

This file was deleted.

0 comments on commit dc88847

Please sign in to comment.