Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc88847

Browse files
committedMar 17, 2009
Try to use actionpack gem to generate guide when Rails is not vendored
1 parent 18eb80c commit dc88847

File tree

3 files changed

+19
-155
lines changed

3 files changed

+19
-155
lines changed
 

‎railties/guides/rails_guides.rb

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
pwd = File.dirname(__FILE__)
22
$: << pwd
3-
$: << File.join(pwd, "../../activesupport/lib")
4-
$: << File.join(pwd, "../../actionpack/lib")
53

6-
require "action_controller"
7-
require "action_view"
4+
begin
5+
as_lib = File.join(pwd, "../../activesupport/lib")
6+
ap_lib = File.join(pwd, "../../actionpack/lib")
7+
8+
$: << as_lib if File.directory?(as_lib)
9+
$: << ap_lib if File.directory?(ap_lib)
10+
11+
require "action_controller"
12+
require "action_view"
13+
rescue LoadError
14+
require 'rubygems'
15+
gem "actionpack", '>= 2.3'
16+
17+
require "action_controller"
18+
require "action_view"
19+
end
820

9-
# Require rubygems after loading Action View
10-
require 'rubygems'
1121
begin
12-
gem 'RedCloth', '>= 4.1.1'# Need exactly 4.1.1
22+
require 'rubygems'
23+
gem 'RedCloth', '>= 4.1.1'
1324
rescue Gem::LoadError
14-
$stderr.puts %(Missing the RedCloth 4.1.1 gem.\nPlease `gem install -v=4.1.1 RedCloth` to generate the guides.)
25+
$stderr.puts %(Generating Guides requires RedCloth 4.1.1+)
1526
exit 1
1627
end
1728

@@ -22,7 +33,6 @@ module RailsGuides
2233
autoload :Indexer, "rails_guides/indexer"
2334
autoload :Helpers, "rails_guides/helpers"
2435
autoload :TextileExtensions, "rails_guides/textile_extensions"
25-
autoload :Levenshtein, "rails_guides/levenshtein"
2636
end
2737

2838
RedCloth.send(:include, RailsGuides::TextileExtensions)

‎railties/guides/rails_guides/generator.rb

-34
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def generate_guide(guide)
5757

5858
result = view.render(:layout => 'layout', :text => textile(body))
5959
f.write result
60-
warn_about_broken_links(result)
6160
end
6261
end
6362
end
@@ -135,38 +134,5 @@ def with_workaround_for_notextile(body)
135134
code_blocks[$1.to_i]
136135
end
137136
end
138-
139-
def warn_about_broken_links(html)
140-
anchors = extract_anchors(html)
141-
check_fragment_identifiers(html, anchors)
142-
end
143-
144-
def extract_anchors(html)
145-
# Textile generates headers with IDs computed from titles.
146-
anchors = Set.new
147-
html.scan(/<h\d\s+id="([^"]+)/).flatten.each do |anchor|
148-
if anchors.member?(anchor)
149-
puts "*** DUPLICATE HEADER ID: #{anchor}, please consider rewording"
150-
else
151-
anchors << anchor
152-
end
153-
end
154-
155-
# Also, footnotes are rendered as paragraphs this way.
156-
anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten)
157-
return anchors
158-
end
159-
160-
def check_fragment_identifiers(html, anchors)
161-
html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier|
162-
next if fragment_identifier == 'mainCol' # in layout, jumps to some DIV
163-
unless anchors.member?(fragment_identifier)
164-
guess = anchors.min { |a, b|
165-
Levenshtein.distance(fragment_identifier, a) <=> Levenshtein.distance(fragment_identifier, b)
166-
}
167-
puts "*** BROKEN LINK: ##{fragment_identifier}, perhaps you meant ##{guess}."
168-
end
169-
end
170-
end
171137
end
172138
end

‎railties/guides/rails_guides/levenshtein.rb

-112
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.