-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.ru
41 lines (32 loc) · 886 Bytes
/
config.ru
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
require 'asciidoctor'
require 'erb'
require 'oreilly/snippets'
require 'json'
RENDER_REGEX = /([^\/]*\.asciidoc)\.html$/
INIT_SCRIPT = '<script type="text/javascript" src="init.js"></script>';
class AsciiToHTML
def initialize(app)
@app = app
end
def call(env)
self.render(env)
@app.call(env)
end
protected
def render(env)
puts env["REQUEST_PATH"]
m = RENDER_REGEX.match(env["REQUEST_PATH"])
return unless m
asciidoc = File.read( m[1] )
out = Asciidoctor.render( asciidoc,
:header_footer => true,
:safe => Asciidoctor::SafeMode::SAFE,
:attributes => {'linkcss!' => ''})
File.open( m[0], "w+" ) do |f|
out.gsub!( '</body>', "</body>\n#{INIT_SCRIPT}\n" )
f.write out
end
end
end
use AsciiToHTML
run Rack::Directory.new('.')