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:
parent
bd45029f55
commit
247b9563ac
2 changed files with 37 additions and 31 deletions
|
@ -25,29 +25,7 @@ module RailsGuides
|
|||
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
|
||||
|
@ -55,6 +33,32 @@ module RailsGuides
|
|||
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 @@ 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
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue