-
Notifications
You must be signed in to change notification settings - Fork 3
/
Guardfile
39 lines (33 loc) · 1.05 KB
/
Guardfile
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
require 'asciidoctor'
require 'erb'
require 'oreilly/snippets'
init_script = '<script type="text/javascript" src="init.js"></script>';
Oreilly::Snippets.config( flatten: true, skip_flattening: { java: true } )
guard 'shell' do
watch( /^pre\/[^\.][^\/]*\.asciidoc$/) {|m|
contents = File.read( m[0] )
snippetized = Oreilly::Snippets.process( contents )
snippet_out = m[0].gsub( "pre/", "" )
File.open( snippet_out, "w+" ) do |f|
f.write snippetized
end
}
end
guard 'shell' do
watch( /^[^\/\#]*\.asciidoc$/ ) { |m|
asciidoc = File.read( m[0] )
out = Asciidoctor.render( asciidoc,
:header_footer => true,
:line_numbers => true,
:src_numbered => 'numbered',
:safe => Asciidoctor::SafeMode::SAFE,
:attributes => {'linkcss!' => ''})
File.open( m[0]+ ".html", "w+" ) do |f|
out.gsub!( '</body>', "</body>\n#{init_script}\n" )
f.write out
end
}
end
guard 'livereload' do
watch(%r{^.+\.(css|js|html)$})
end