1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

let the indexer pass element IDs to the guides generator to avoid coupling, links to sections whose title has textile markup are fixed as well

This commit is contained in:
Xavier Noria 2009-02-22 00:29:11 +01:00
parent bd45029f55
commit 247b9563ac
2 changed files with 37 additions and 31 deletions

View file

@ -25,6 +25,15 @@ module RailsGuides
end
guides.each do |guide|
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
@ -50,11 +59,6 @@ module RailsGuides
end
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 set_header_section(body, view)
new_body = body.gsub(/(.*?)endprologue\./m, '').strip
header = $1
@ -72,7 +76,7 @@ module RailsGuides
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
@ -81,12 +85,10 @@ module RailsGuides
# 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 file

@ -29,13 +29,17 @@ module RailsGuides
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