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
|
end
|
||||||
|
|
||||||
guides.each do |guide|
|
guides.each do |guide|
|
||||||
guide =~ /(.*?)(\.erb)?\.textile/
|
generate_guide(guide)
|
||||||
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
|
end
|
||||||
|
|
||||||
# Copy images and css files to html directory
|
# 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')
|
FileUtils.cp_r File.join(guides_dir, 'files'), File.join(output, 'files')
|
||||||
end
|
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)
|
def set_header_section(body, view)
|
||||||
new_body = body.gsub(/(.*?)endprologue\./m, '').strip
|
new_body = body.gsub(/(.*?)endprologue\./m, '').strip
|
||||||
header = $1
|
header = $1
|
||||||
|
@ -72,21 +76,19 @@ module RailsGuides
|
||||||
def set_index(body, view)
|
def set_index(body, view)
|
||||||
index = <<-INDEX
|
index = <<-INDEX
|
||||||
<div id="subCol">
|
<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">
|
<ol class="chapters">
|
||||||
INDEX
|
INDEX
|
||||||
|
|
||||||
i = Indexer.new(body)
|
i = Indexer.new(body)
|
||||||
i.index
|
i.index
|
||||||
|
|
||||||
# Set index for 2 levels
|
# Set index for 2 levels
|
||||||
i.level_hash.each do |key, value|
|
i.level_hash.each do |key, value|
|
||||||
bookmark = '#' + key.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
|
link = view.content_tag(:a, :href => key[:id]) { textile(key[:title]) }
|
||||||
link = view.content_tag(:a, :href => bookmark) { textile(key) }
|
|
||||||
|
|
||||||
children = value.keys.map do |k|
|
children = value.keys.map do |k|
|
||||||
bm = '#' + k.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
|
l = view.content_tag(:a, :href => k[:id]) { textile(k[:title]) }
|
||||||
l = view.content_tag(:a, :href => bm) { textile(k) }
|
|
||||||
view.content_tag(:li, l)
|
view.content_tag(:li, l)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,17 @@ module RailsGuides
|
||||||
return level_hash
|
return level_hash
|
||||||
elsif level == current_level
|
elsif level == current_level
|
||||||
index = counters.join(".")
|
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}")
|
raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}")
|
||||||
|
|
||||||
|
key = {
|
||||||
|
:title => title,
|
||||||
|
:id => bookmark
|
||||||
|
}
|
||||||
# Recurse
|
# Recurse
|
||||||
counters << 1
|
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
|
counters.pop
|
||||||
|
|
||||||
# Increment the current level
|
# Increment the current level
|
||||||
|
|
Loading…
Reference in a new issue