Skip to content
Browse files

let the indexer pass element IDs to the guides generator to avoid cou…

…pling, links to sections whose title has textile markup are fixed as well
  • Loading branch information...
1 parent bd45029 commit 247b9563ac81f6e66bc3c5af8e280adad66258a4 @fxn fxn committed Feb 22, 2009
Showing with 37 additions and 31 deletions.
  1. +31 −29 railties/guides/rails_guides/generator.rb
  2. +6 −2 railties/guides/rails_guides/indexer.rb
View
60 railties/guides/rails_guides/generator.rb
@@ -25,36 +25,40 @@ def generate
end
guides.each do |guide|
- guide =~ /(.*?)(\.erb)?\.textile/
- name = $1
-
- puts "Generating #{name}"
-
- file = File.join(output, "#{name}.html")
- File.open(file, 'w') do |f|
- @view = ActionView::Base.new(view_path)
- @view.extend(Helpers)
-
- if guide =~ /\.erb\.textile/
- # Generate the erb pages with textile formatting - e.g. index/authors
- result = view.render(:layout => 'layout', :file => name)
- f.write textile(result)
- else
- body = File.read(File.join(view_path, guide))
- body = set_header_section(body, @view)
- body = set_index(body, @view)
-
- result = view.render(:layout => 'layout', :text => textile(body))
- f.write result
- end
- end
+ generate_guide(guide)
end
# Copy images and css files to html directory
FileUtils.cp_r File.join(guides_dir, 'images'), File.join(output, 'images')
FileUtils.cp_r File.join(guides_dir, 'files'), File.join(output, 'files')
end
+ def generate_guide(guide)
+ guide =~ /(.*?)(\.erb)?\.textile/
+ name = $1
+
+ puts "Generating #{name}"
+
+ file = File.join(output, "#{name}.html")
+ File.open(file, 'w') do |f|
+ @view = ActionView::Base.new(view_path)
+ @view.extend(Helpers)
+
+ if guide =~ /\.erb\.textile/
+ # Generate the erb pages with textile formatting - e.g. index/authors
+ result = view.render(:layout => 'layout', :file => name)
+ f.write textile(result)
+ else
+ body = File.read(File.join(view_path, guide))
+ body = set_header_section(body, @view)
+ body = set_index(body, @view)
+
+ result = view.render(:layout => 'layout', :text => textile(body))
+ f.write result
+ end
+ end
+ end
+
def set_header_section(body, view)
new_body = body.gsub(/(.*?)endprologue\./m, '').strip
header = $1
@@ -72,21 +76,19 @@ def set_header_section(body, view)
def set_index(body, view)
index = <<-INDEX
<div id="subCol">
- <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" /> Chapters</h3>
+ <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
<ol class="chapters">
- INDEX
+ INDEX
i = Indexer.new(body)
i.index
# Set index for 2 levels
i.level_hash.each do |key, value|
- bookmark = '#' + key.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
- link = view.content_tag(:a, :href => bookmark) { textile(key) }
+ link = view.content_tag(:a, :href => key[:id]) { textile(key[:title]) }
children = value.keys.map do |k|
- bm = '#' + k.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
- l = view.content_tag(:a, :href => bm) { textile(k) }
+ l = view.content_tag(:a, :href => k[:id]) { textile(k[:title]) }
view.content_tag(:li, l)
end
View
8 railties/guides/rails_guides/indexer.rb
@@ -29,13 +29,17 @@ def process(string, current_level= 3, counters = [1])
return level_hash
elsif level == current_level
index = counters.join(".")
- bookmark = '#' + title.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
+ bookmark = '#' + title.gsub(/[^a-z0-9\-_]+/i, '').underscore.dasherize
raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}")
+ key = {
+ :title => title,
+ :id => bookmark
+ }
# Recurse
counters << 1
- level_hash[title.strip] = process(s.post_match, current_level + 1, counters)
+ level_hash[key] = process(s.post_match, current_level + 1, counters)
counters.pop
# Increment the current level

0 comments on commit 247b956

Please sign in to comment.
Something went wrong with that request. Please try again.