forked from amazon-ion/ion-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
183 lines (139 loc) · 4.53 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#version_string = `git describe --tag | cut -d "-" -f 1,2 | tr - .`.chomp
#if version_string.empty?
# version_string = '0'
#end
Version_string = "0.1"
Date_string = Time.now.strftime("%Y-%m-%d")
books = %w{IonSpec Semantics Demo}
image_files = Rake::FileList.new("src/images/*.png", "src/images/*.svg") do |fl|
fl.exclude("~*")
fl.exclude(/^scratch\//)
end
namespace :spec do
directory 'build/images'
desc 'copy images to build dir'
task :images => 'build/images'
image_files.each do |source|
target = source.sub(/^src\/images/, 'build/images')
file target => source do
cp source, target, :verbose => true
if File.extname(target) == ".png"
`pngquant -f #{target}`
end
end
task :images => target
end
task :prereqs => [:images]
#=============================================================================
# AsciiDoctor Processing
def safe_system(app, *args)
ok = system(app, *args)
raise "Could not find #{app}" if ok.nil?
raise "#{app} failed with status #{$?.exitstatus}" unless $?.exitstatus == 0
end
def asciidoctor(*args)
params = [
"--attribute", "revnumber=#{Version_string}",
"--attribute", "revdate=#{Date_string}",
"--trace",
"--verbose",
]
safe_system 'bundle', 'exec', 'asciidoctor', *params, *args
end
def adoc_to_html(adoc, html)
puts "Converting #{adoc} to HTML..."
asciidoctor('--backend', 'html5',
'--out-file', html,
adoc)
end
def adoc_to_xml(adoc, xml)
puts "Converting #{adoc} to DocBook XML..."
asciidoctor('--backend', 'docbook',
'--out-file', xml,
adoc)
end
def adoc_to_pdf(adoc, pdf)
puts "Converting #{adoc} to PDF..."
theming = %w(-a pdf-themesdir=src/themes -a pdf-theme=basic -a pdf-fontsdir=fonts)
stem = %w(-r asciidoctor-mathematical -a mathematical-format=svg)
pdf_params = %w(-a compress)
asciidoctor(*theming, *stem, *pdf_params,
'--require', 'asciidoctor-pdf',
'--backend', 'pdf',
'--out-file', pdf,
adoc)
end
def xml_to_pdf(xml)
puts "Converting #{xml} to PDF..."
book = File.basename(xml, '.xml')
# See our dblatex/README.md for explanation.
# https://www.mankier.com/1/xmlto
xmlto_params = [
"--skip-validation",
# "-vv", # Enables --verbose for dblatex
]
# https://www.mankier.com/1/dblatex
dblatex_params = [
"--param=latex.encoding=utf8",
"--xsl-user=/workspace/dblatex/xsl/ion.xsl",
"--texinputs=/workspace/dblatex/tex",
"--texstyle=ion",
"--texpost=/workspace/dblatex/postprocess.sh",
# "--quiet", # Less verbose, only error messages
# "--verbose", # Show the running commands
"--debug", # Keep the /tmp subdir with tex files
]
# Book-specific XSL stylesheet (overrides the above default)
xsl = "/workspace/dblatex/xsl/#{book}.xsl"
dblatex_params << "--xsl-user=#{xsl}" if File.readable?(xsl)
# Book-specific LaTeX style (overrides the above default)
sty = "/workspace/dblatex/tex/#{book}.sty"
dblatex_params << "--texstyle=#{book}" if File.readable?(sty)
safe_system('xmlto', *xmlto_params,
'--with-dblatex',
'-p', dblatex_params.join(' '),
'-o', 'build',
'pdf',
xml)
end
#=============================================================================
# Generate tasks for each book
books.each do |book|
adoc = "src/#{book}.adoc"
xml = "build/#{book}.xml"
pdf = "build/#{book}.pdf"
html = "build/#{book}.html"
file xml => [:prereqs, adoc] do
adoc_to_xml adoc, xml
end
file html => [:prereqs, adoc] do
adoc_to_html adoc, html
end
file pdf => [:prereqs, xml] do
xml_to_pdf xml
end
task :docbook => xml
task :pdf => pdf
task :html => html
end
task :build => [:html, :pdf, :docbook]
task watch: [:build] do
begin
`bundle exec guard`
end
end
require 'rake/clean'
CLEAN.include('build')
CLOBBER.include('build')
end
task :default => "spec:build"
task :clean => "spec:clean"
desc "Build the book as HTML"
task :html => "spec:html"
desc "Build the book as PDF"
task :pdf => "spec:pdf"
desc "Build the book in all formats"
task :build => "spec:build"
task :watch => "spec:watch"
desc "Build the demo document for checking rendering."
task :demo => "build/Demo.pdf"