-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathRakefile.rb
83 lines (73 loc) · 2.34 KB
/
Rakefile.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
81
82
83
TARGET_DIR='target'
autoload :FileUtils, 'fileutils'
require 'asciidoctor'
require 'asciidoctor-diagram'
require 'asciidoctor-revealjs'
# TODO: add ability to build only a single assignment/presentation:
# https://stackoverflow.com/questions/9539324
def convert_assignments(doc, assignment_dir)
puts "Converting #{doc}"
Asciidoctor.convert_file doc,
safe: :unsafe,
attributes: <<-ATTRS,
icons=font
source-highlighter=rouge
mmdc=./node_modules/.bin/mmdc
ATTRS
to_file: "#{TARGET_DIR}/#{assignment_dir}/#{File.basename doc, '.*'}.html",
mkdirs: true
end
desc 'Build assignments'
task :assignments => :index do
# convert regular assignment sheets
(FileList.new './assignments/*.adoc').each do |doc|
convert_assignments(doc, 'assignments')
end
# convert "fill in the blanks" style assignment documentation
(FileList.new './fill_in_the_blanks/*.adoc').each do |doc|
convert_assignments(doc, 'fill_in_the_blanks')
end
end
desc 'Build presentations'
task :presentations => :index do
# FIXME: this will break if there's a name collision
FileUtils.cp Dir.glob('./presentations/*/*.{svg,jpg}'), './target'
FileUtils.cp './presentations/slides.css', './target/slides.css'
(FileList.new './presentations/*/*.adoc').each do |doc|
puts "Converting #{doc}"
name = File.basename (File.dirname doc)
Asciidoctor.convert_file doc,
safe: :unsafe,
attributes: <<-ATTRS,
customcss=slides.css
revealjsdir=https://cdn.jsdelivr.net/npm/[email protected]
highlightjs-theme=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/idea.min.css
icons=font
revealjs_height=1080
revealjs_history=true
revealjs_theme=simple
revealjs_transition=none
revealjs_width=1920
source-highlighter=highlightjs
docinfo=shared
docinfodir=../
mmdc=./node_modules/.bin/mmdc
ATTRS
backend: 'revealjs',
to_file: "#{TARGET_DIR}/#{name}.html",
mkdirs: true
end
end
desc 'Build index'
task :index do
Asciidoctor.convert_file './presentations/index.adoc',
safe: :unsafe,
to_file: "#{TARGET_DIR}/index.html",
mkdirs: true
end
desc 'Build all'
task default: [:assignments, :presentations]
desc 'Clean the build directory'
task :clean do
FileUtils.remove_entry_secure TARGET_DIR if File.exist? TARGET_DIR
end