-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
63 lines (55 loc) · 1.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
# -----------------------------------------------------------------------------
# Global constants
# -----------------------------------------------------------------------------
THEME = ENV.fetch('THEME', 'tutorial')
BASE_DIR = File.dirname(__FILE__)
SAMPLES_DIR = 'samples'
DOCKER_IMAGE = 'asciidoctor/docker-asciidoctor'
# -----------------------------------------------------------------------------
# Methods
# -----------------------------------------------------------------------------
def inside_docker?
File.exist?('/.dockerenv')
end
def docker_asciidoctor(program = 'asciidoctor')
return program if inside_docker?
docker_options = [
'--rm',
'--tty',
"--mount type=bind,src=#{BASE_DIR},target=#{BASE_DIR}",
" --workdir=#{BASE_DIR}",
" --user=#{Process.uid}:#{Process.gid}",
DOCKER_IMAGE,
program
]
"docker run " << docker_options.join(' ')
end
def asciidoctor_pdf
docker_asciidoctor('asciidoctor-pdf')
end
def asciidoctor
docker_asciidoctor
end
# -----------------------------------------------------------------------------
# Directories
# -----------------------------------------------------------------------------
directory SAMPLES_DIR
# -----------------------------------------------------------------------------
# Tasks
# -----------------------------------------------------------------------------
task :default => :test
task :test => SAMPLES_DIR do
%w(article book manpage).each do |type|
sh %(#{asciidoctor_pdf} ) +
%(-a pdf-themesdir=. ) +
%(-a pdf-theme=#{THEME}.yml ) +
%(-a pdf-fontsdir=./fonts ) +
%(-a iconsdir=./icons ) +
%(-a doctype=#{type} ) +
%(-o "samples/#{type}.pdf" ) +
%("tests/#{type}.adoc")
end
end
task :clean do
rm Rake::FileList["#{SAMPLES_DIR}/*pdf"]
end