-
Notifications
You must be signed in to change notification settings - Fork 188
/
Rakefile
163 lines (140 loc) · 4.77 KB
/
Rakefile
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env rake
require 'asciidoctor'
require 'asciidoctor/doctest'
require 'colorize'
require 'tilt'
require 'rake/testtask'
CONVERTER_FILE = 'lib/asciidoctor-revealjs/converter.rb'
JS_FILE = 'build/asciidoctor-reveal.js'
DIST_FILE = 'dist/main.js'
TEMPLATES_DIR = 'templates'
PUBLIC_DIR = 'public'
file CONVERTER_FILE => FileList["#{TEMPLATES_DIR}/*"] do
build_converter :fast
end
namespace :build do
desc 'Compile Slim templates and generate converter.rb'
task :converter => 'clean' do
# NOTE: use :pretty if you want to debug the generated code
build_converter :fast
end
desc 'Compile Slim templates and generate converter.rb for Opal'
task 'converter:opal' => 'clean' do
build_converter :opal
end
desc "Transcompile to JavaScript and generate #{JS_FILE}"
task :js => 'converter:opal' do
require 'opal'
builder = Opal::Builder.new(compiler_options: {
dynamic_require_severity: :error,
})
builder.append_paths 'lib'
builder.build 'asciidoctor-revealjs'
mkdir_p [File.dirname(JS_FILE), File.dirname(DIST_FILE)]
File.open(JS_FILE, 'w') do |file|
template = File.read('src/asciidoctor-revealjs.tmpl.js')
template['//OPAL-GENERATED-CODE//'] = builder.to_s
file << template
end
File.binwrite "#{JS_FILE}.map", builder.source_map
cp JS_FILE, DIST_FILE, :verbose => true
end
end
task :build => 'build:converter'
task :clean do
rm_rf CONVERTER_FILE
rm_rf PUBLIC_DIR
end
def build_converter(mode = :pretty)
#require 'asciidoctor-templates-compiler'
require_relative 'lib/asciidoctor-templates-compiler'
require 'slim-htag'
generator = if mode == :opal
Temple::Generators::ArrayBuffer.new(freeze_static: false)
else
Temple::Generators::StringBuffer
end
File.open(CONVERTER_FILE, 'w') do |file|
puts "Generating #{file.path} (mode: #{mode})."
Asciidoctor::TemplatesCompiler::RevealjsSlim.compile_converter(
templates_dir: TEMPLATES_DIR,
class_name: 'Asciidoctor::Revealjs::Converter',
register_for: ['revealjs', 'reveal.js'],
backend_info: {
basebackend: 'html',
outfilesuffix: '.html',
filetype: 'html',
supports_templates: true
},
delegate_backend: 'html5',
engine_opts: {
generator: generator,
},
pretty: (mode == :pretty),
output: file
)
end
end
DocTest::RakeTasks.new do |t|
t.output_examples :html, path: 'test/doctest'
t.input_examples :asciidoc, path: [ *DocTest.examples_path, 'examples' ]
t.converter = DocTest::HTML::Converter
t.converter_opts = { backend_name: 'revealjs' }
end
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/asciidoctor-revealjs/*_test.rb']
t.warning = false
end
task 'prepare-converter' do
# Run as an external process to ensure that it will not affect tests
# environment with extra loaded modules (especially slim).
`bundle exec rake #{CONVERTER_FILE}`
require_relative 'lib/asciidoctor-revealjs'
end
namespace :examples do
desc 'Converts all the test slides into fully working examples that you can look in a browser'
# converted slides will be put in examples/ directory
task :convert => 'build:converter' do
require 'slim-htag'
require_relative 'lib/asciidoctor-revealjs'
Dir.glob('examples/*.adoc') do |_file|
print "Converting file #{_file}... "
out = Asciidoctor.convert_file _file,
:safe => 'safe',
:backend => 'revealjs',
:base_dir => 'examples'
if out.instance_of? Asciidoctor::Document
puts "✔️".green
else
puts "✖️".red
end
end
end
task :serve do
puts "View rendered examples at: http://127.0.0.1:5000/"
puts "Exit with Ctrl-C"
Dir.chdir('examples') do
`ruby -run -e httpd . -p 5000 -b 127.0.0.1`
end
end
task :publish do
FileUtils.rm_rf PUBLIC_DIR
Dir.mkdir PUBLIC_DIR
Dir.mkdir "#{PUBLIC_DIR}/reveal.js"
FileUtils.cp 'src/index.html', "#{PUBLIC_DIR}/index.html"
FileUtils.cp_r 'node_modules/reveal.js/', "#{PUBLIC_DIR}"
FileUtils.cp_r 'examples/images/', "#{PUBLIC_DIR}"
FileUtils.cp 'examples/release-4.0.html', "#{PUBLIC_DIR}/release-4.0.html"
FileUtils.cp 'examples/release-4.0.css', "#{PUBLIC_DIR}/release-4.0.css"
FileUtils.cp 'examples/release-4.1.html', "#{PUBLIC_DIR}/release-4.1.html"
FileUtils.cp 'examples/release-4.1.css', "#{PUBLIC_DIR}/release-4.1.css"
FileUtils.cp 'examples/a11y-dark.css', "#{PUBLIC_DIR}/a11y-dark.css"
FileUtils.cp 'examples/release-5.1.html', "#{PUBLIC_DIR}/release-5.1.html"
FileUtils.cp 'examples/release-5.1.css', "#{PUBLIC_DIR}/release-5.1.css"
end
end
task 'test' => 'doctest'
task 'doctest:test' => 'prepare-converter'
task 'doctest:generate' => 'prepare-converter'
# When no task specified, run test.
task :default => :test