continue on user guide generator
This commit is contained in:
parent
9f00063d57
commit
5f1ad78e8c
@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>RScons User Guide - Version <%= version %></title>
|
||||
<title>RScons User Guide - Version <%= Rscons::VERSION %></title>
|
||||
<style>
|
||||
body {
|
||||
max-width: 140ex;
|
||||
|
@ -4,11 +4,9 @@ require "erb"
|
||||
require "fileutils"
|
||||
require "redcarpet"
|
||||
require "syntax"
|
||||
require "syntax/convertors/html"
|
||||
require "rscons/version"
|
||||
|
||||
renderer = Redcarpet::Render::HTML.new
|
||||
markdown = Redcarpet::Markdown.new(renderer)
|
||||
|
||||
def load_file(file_name)
|
||||
contents = File.read(file_name)
|
||||
contents.gsub(/\$\{include (.*?)\}/) do |match|
|
||||
@ -17,17 +15,62 @@ def load_file(file_name)
|
||||
end
|
||||
end
|
||||
|
||||
class Generator
|
||||
class Section
|
||||
attr_reader :name
|
||||
attr_reader :contents
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@contents = ""
|
||||
end
|
||||
def append(contents)
|
||||
@contents += contents
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(input, output_file, multi_file)
|
||||
@sections = [Section.new("index")]
|
||||
@lines = input.lines
|
||||
while @lines.size > 0
|
||||
line = @lines.slice!(0)
|
||||
if line =~ /^```(.*)$/
|
||||
@sections.last.append(gather_code_section($1))
|
||||
else
|
||||
@sections.last.append(line)
|
||||
end
|
||||
end
|
||||
|
||||
renderer = Redcarpet::Render::HTML.new
|
||||
markdown = Redcarpet::Markdown.new(renderer)
|
||||
body = markdown.render(@sections.last.contents)
|
||||
|
||||
template = File.read("rb/assets/user_guide.html.erb")
|
||||
erb = ERB.new(template, nil, "<>")
|
||||
html_result = erb.result(binding.clone)
|
||||
File.open(output_file, "w") do |fh|
|
||||
fh.write(html_result)
|
||||
end
|
||||
end
|
||||
|
||||
def gather_code_section(syntax)
|
||||
code = ""
|
||||
loop do
|
||||
line = @lines.slice!(0)
|
||||
if line =~ /^```/
|
||||
break
|
||||
end
|
||||
code += line
|
||||
end
|
||||
if syntax != ""
|
||||
convertor = Syntax::Convertors::HTML.for_syntax(syntax)
|
||||
convertor.convert(code)
|
||||
else
|
||||
"<pre>#{code}</pre>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
input = load_file("doc/user_guide.md")
|
||||
|
||||
version = Rscons::VERSION
|
||||
body = markdown.render(input)
|
||||
template = File.read("rb/assets/user_guide.html.erb")
|
||||
|
||||
erb = ERB.new(template, nil, "<>")
|
||||
html_result = erb.result
|
||||
|
||||
FileUtils.rm_rf("gen/user_guide")
|
||||
FileUtils.mkdir_p("gen/user_guide")
|
||||
File.open("gen/user_guide/user_guide.html", "w") do |fh|
|
||||
fh.write(html_result)
|
||||
end
|
||||
Generator.new(input, "gen/user_guide/user_guide.html", false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user