-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathapplication.rb
83 lines (62 loc) · 3.03 KB
/
application.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
75
76
77
78
79
80
require 'rubygems'
require 'bundler'
Bundler.require
require './helpers/magicrocco'
require './helpers/codepostprocessing'
class Application < Sinatra::Base
get '/' do
erb :front
end
get '/create_html/*' do
asciidoc_file = "/" + params[:splat][0]
output_folder = File.join(File.dirname(asciidoc_file), "noc_html")
@document = AsciiDoc::AsciiDocument.new(asciidoc_file, {:debug_xml_to_file => File.join(output_folder, "index.xml") })
@document.render(:html, :template => File.join(output_folder, "views"), :output => File.join(output_folder, "index.html"))
"Done!"
end
get '/create_html_chapters/*' do
asciidoc_file = "/" + params[:splat][0]
output_folder = File.join(File.dirname(asciidoc_file), "noc_html")
@document = AsciiDoc::AsciiDocument.new(asciidoc_file, {:debug_xml_to_file => File.join(output_folder, "index.xml") })
@document.render(:html_chapters, :template => File.join(output_folder, "views"), :output => File.join(output_folder, "index.html"))
"Done!"
end
get '/create_pdf/*' do
asciidoc_file = "/" + params[:splat][0]
output_folder = File.join(File.dirname(asciidoc_file), "noc_pdf")
startTime = Time.now
puts "///////// Starting Render: #{startTime}"
# create asciidocument
@document = AsciiDoc::AsciiDocument.new(asciidoc_file, { :debug_xml_to_file => File.join(output_folder, "index.xml") })
puts "Parsed Asciidoc after: #{Time.now-startTime} seconds"
#render html
@document.render(:html, :template => File.join(output_folder, "views"), :output => File.join(output_folder, "index.html"))
puts "Rendered HTML after: #{Time.now-startTime} seconds"
# render page count pdf
@document.render(:pdf, :html_file => File.join(output_folder, "index.html"),
:output => File.join(output_folder, "page_count.pdf"),
:prince_args => [
["--script", File.join(output_folder, "page_count", "page_count.js")],
["--style", File.join(output_folder, "page_count", "page_count.css")],
["-i", "html5"],
[">", File.join(output_folder, "page_count", "out.js")]
]
)
puts "Rendered Page Count PDF after: #{Time.now-startTime} seconds"
#render final pdf
@document.render(:pdf, :html_file => File.join(output_folder, "index.html"),
:output => File.join(output_folder, "index.pdf"),
:prince_args => [
["--script", File.join(output_folder, "page_count", "page_filter.js")],
["--script", File.join(output_folder, "page_count", "out.js")],
"--verbose",
["-i", "html5"]
]
)
puts "Rendered PDF after: #{Time.now-startTime} seconds"
"Done in in: #{Time.now-startTime} seconds"
end
not_found do
erb :notfound
end
end