-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathparse.rb
74 lines (62 loc) · 1.75 KB
/
parse.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$: << 'tools/fdoc/src/'
require 'fdoc.rb'
require 'erb'
include FD
source_dir = 'source/_posts'
public_dir = 'public'
Dir.chdir(source_dir)
files=Dir.glob('*.txt').sort.select{|fn| fn=~/^\d.*.txt/}.map{|fn| open(fn) }
Dir.chdir('../../')
c=nil; p=nil; n=nil; docs=[];
tpl=ERB.new( open('_page.erb').read )
for i in 0..files.length-1
p=c
c=n || FDoc.parse( files[i].read )
docs << c
n=FDoc.parse( files[i+1].read ) rescue nil
html=tpl.result(binding)
fn="#{c.anchor.chomp('-')}.html"
open("#{public_dir}/"+fn,'w'){|f|
f.write( html )
}
puts "#{public_dir}/#{fn}... \t#{File.size("#{public_dir}/"+fn).div(1024).to_s}kb"
#end
end
#parse faq
fn="faq.html"
c=FDoc.parse( open("#{source_dir}/faq.txt").read )
tpl=ERB.new( open('_faq.erb').read )
html=tpl.result(binding)
open("#{public_dir}/#{fn}", 'w'){|f|
f.write( html )
}
puts "#{public_dir}/#{fn}... \t#{File.size("#{public_dir}/"+fn).div(1024).to_s}kb"
#parse resource
c=FDoc.parse( open("#{source_dir}/resource.txt").read )
tpl=ERB.new( open('_faq.erb').read )
html=tpl.result(binding)
open("#{public_dir}/#{fn}", 'w'){|f|
f.write( html )
}
puts "#{public_dir}/#{fn}... \t#{File.size("#{public_dir}/"+fn).div(1024).to_s}kb"
#make content list page
c=Node.new {
olist{
docs.each do |d|
li {
a "#{d.anchor.chomp('-')}.html", d.title
list {
d.h2.each do |s|
li { a "#{d.anchor.chomp('-')}.html\##{s.anchor.chomp('-')}", s.title }
end
}
}
end
}
}
tpl=ERB.new( open('_chapters.erb').read )
html=tpl.result(binding)
f=open("#{public_dir}/chapters.html", 'w')
f.write(html)
f.close
puts "#{public_dir}/chapters.html"