user guide: preparing for multi-page generation
This commit is contained in:
parent
22b007df3a
commit
5f71781806
@ -1,6 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>RScons User Guide - Version <%= Rscons::VERSION %></title>
|
<title>RScons User Guide<%= subpage_title %> - Version <%= Rscons::VERSION %></title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #CCC;
|
background-color: #CCC;
|
||||||
|
@ -34,9 +34,9 @@ class Generator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(input, output_file, multi_file)
|
def initialize(input, output_file, multi_page)
|
||||||
current_page =
|
current_page =
|
||||||
if multi_file
|
if multi_page
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
File.basename(output_file)
|
File.basename(output_file)
|
||||||
@ -66,23 +66,37 @@ class Generator
|
|||||||
|
|
||||||
renderer = Redcarpet::Render::HTML.new
|
renderer = Redcarpet::Render::HTML.new
|
||||||
@markdown_renderer = Redcarpet::Markdown.new(renderer)
|
@markdown_renderer = Redcarpet::Markdown.new(renderer)
|
||||||
content = render_toc
|
|
||||||
@sections.each do |section|
|
|
||||||
content += render_section(section)
|
|
||||||
end
|
|
||||||
changelog = @markdown_renderer.render(File.read("CHANGELOG.md"))
|
changelog = @markdown_renderer.render(File.read("CHANGELOG.md"))
|
||||||
content.gsub!("${changelog}", changelog)
|
|
||||||
content.gsub!(%r{\$\{#(.+?)\}}) do |match|
|
pages = {"toc" => render_toc}
|
||||||
section_name = $1
|
@sections.each do |section|
|
||||||
href = get_link_to_section(section_name)
|
pages[section.page] ||= ""
|
||||||
%[<a href="#{href}">#{section_name}</a>]
|
pages[section.page] += render_section(section)
|
||||||
|
end
|
||||||
|
|
||||||
|
pages.each do |title, contents|
|
||||||
|
contents.gsub!("${changelog}", changelog)
|
||||||
|
contents.gsub!(%r{\$\{#(.+?)\}}) do |match|
|
||||||
|
section_name = $1
|
||||||
|
href = get_link_to_section(section_name)
|
||||||
|
%[<a href="#{href}">#{section_name}</a>]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
template = File.read("rb/assets/user_guide.html.erb")
|
template = File.read("rb/assets/user_guide.html.erb")
|
||||||
erb = ERB.new(template, nil, "<>")
|
erb = ERB.new(template, nil, "<>")
|
||||||
html_result = erb.result(binding.clone)
|
|
||||||
File.open(output_file, "w") do |fh|
|
if multi_page
|
||||||
fh.write(html_result)
|
# TODO
|
||||||
|
else
|
||||||
|
subpage_title = ""
|
||||||
|
content = pages.reduce("") do |result, (title, contents)|
|
||||||
|
result + contents
|
||||||
|
end
|
||||||
|
html_result = erb.result(binding.clone)
|
||||||
|
File.open(output_file, "w") do |fh|
|
||||||
|
fh.write(html_result)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -98,8 +112,8 @@ class Generator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_section(section)
|
def render_section(section)
|
||||||
content = %[<a name="#{section.anchor}" />]
|
%[<a name="#{section.anchor}" />] + \
|
||||||
content + @markdown_renderer.render(section.contents)
|
@markdown_renderer.render(section.contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_anchor(section_number, section_title)
|
def make_anchor(section_number, section_title)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user