-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathascidoc-present
executable file
·102 lines (91 loc) · 3.37 KB
/
ascidoc-present
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env ruby
# for exporting https://github.com/astefanutti/decktape
# decktape -s '1280x820' reveal _dist/jewel-java/index.html output.pdf
require 'fileutils'
require 'listen'
require 'asciidoctor-diagram'
# Compile the content of the directory to a presentation into dir
# @param presentation_dir directory containing sources
def compile_presentation(presentation_dir)
out_dir = "_dist/#{presentation_dir}"
out_dir['src/']=''
puts "Compiling presentation '#{presentation_dir}' into '#{out_dir}'"
system "bundle exec asciidoctor-revealjs -r asciidoctor-diagram --destination-dir=#{out_dir} --out-file=index.html -arevealjsdir=../../_reveal.js #{presentation_dir}/_presentation.adoc"
FileUtils.cp_r "#{presentation_dir}/images", "#{out_dir}"
end
def print_to_pdf(presentation_dir)
out_file = "_print/#{presentation_dir}.pdf"
out_file['src/'] = ''
in_file = "_dist/#{presentation_dir}/index.html"
in_file['src/'] = ''
puts "print presentation '#{presentation_dir}' into '#{out_file}'"
system "decktape -s '1280x820' reveal #{in_file} #{out_file}"
end
# List all directories containing a file named '_presentation.adoc' which marks a presentation
def list_presentation_dirs()
puts 'Search for presentations'
Dir.glob('src/**/_presentation.adoc').map { |p| p.chomp('/_presentation.adoc') }
end
# initializes a file listener to src and recompiles
def configure_recompile()
listener = Listen.to('src') do |modified, added, removed|
puts 'Found changes to files'
(modified.map { |p| p.rpartition('/').first } | added.map { |p| p.rpartition('/').first! } | removed.map { |p| p.rpartition('/').first! })
.each { |p| compile_presentation p }
end
listener.start
puts 'Watch dog started'
sleep
end
# Generates a new presentation skeleton
def generate_new(name)
puts "Generate new presentation '#{name}'"
FileUtils.mkdir_p "src/#{name}"
FileUtils.cp_r '_templates/presentation/.', "src/#{name}"
end
# Prints the help
def print_help()
puts 'asciidoc-present - a small Asciidoctor presentation utility'
puts "USAGE '$ ascidoc-present [clean, build, watch]'"
puts "\tclean/c\t- removes prior build slides"
puts "\tbuild/b\t- builds all presentations"
puts "\twatch/w\t- rebuilds changed presentation on save"
puts "\tprint/p\t- prints all presentations"
puts "\tzip/z\t- prints all presentations"
puts "\tnew/i n\t- generate a new presentation skeleton under name 'n'. New is not chainable!!"
puts "\thelp/h\t- prints this help"
end
def select_presentation
list_presentation_dirs.each_with_index { |p, i| puts "#{i}: #{p}" }
puts 'enter number to select presentation to process: '
i = STDIN.gets.to_i
list_presentation_dirs[i]
end
ARGV.each { |cmd|
case cmd.upcase
when 'CLEAN', 'C'
FileUtils.remove_dir "_dist", force: true
when 'BUILD', 'B'
list_presentation_dirs.each { |p| compile_presentation p }
when 'WATCH', 'W'
configure_recompile
when 'PRINTALL', 'PA'
list_presentation_dirs.each { |p| print_to_pdf p }
when 'PRINT', 'P'
print_to_pdf ARGV[1] != nil ? ARGV[1] : select_presentation
when 'ZIP', 'Z'
print_to_pdf ARGV[1] != nil ? ARGV[1] : select_presentation
when 'NEW', 'N'
if ARGV[1] == nil || ARGV.length != 2
print_help
exit
end
generate_new ARGV[1]
exit
when 'HELP', 'H'
print_help
else
puts "Unable to understand '#{cmd}', type help for further infos"
print_help
end
}