Class: Xpub::CallBook::CallLatexBuilder
Defined Under Namespace
Classes: CallEmptyPageLatexOp, CallImgPageLatexOp, CallInnerTitlePageLatexOp, CallLatexOp
Instance Attribute Summary
Attributes inherited from CallBuilder
#name
Instance Method Summary
collapse
Methods inherited from CallBuilder
#cmd_exec, #copy_to_tmp, #output_path, #src_path, #tmp_path, #validate
Constructor Details
Returns a new instance of CallLatexBuilder.
175
176
177
178
179
180
|
# File 'lib/xpub/dsl/builder.rb', line 175
def initialize(name, book)
@vars = []
@hyoushi = []
@urahyoushi = []
super name, book
end
|
Instance Method Details
#_build_resource(files, option) ⇒ Object
243
244
245
246
247
248
249
250
251
|
# File 'lib/xpub/dsl/builder.rb', line 243
def _build_resource(files, option)
copy_to_tmp files
files.each do |file|
xbb = File.dirname(tmp_path(file.file)) + '/' + File.basename(tmp_path(file.file), '.*') + '.xbb'
unless FileTest.exist?(xbb) && File.mtime(tmp_path(file.file)) <= File.mtime(xbb)
cmd_exec "cd #{Shellwords.shellescape(File.dirname(tmp_path(file.file)))};#{}", [File.basename(file.file)], option
end
end
end
|
#build(option) ⇒ Object
268
269
270
271
272
273
274
275
276
|
# File 'lib/xpub/dsl/builder.rb', line 268
def build(option)
FileUtils.mkdir_p(tmp_path('')) unless FileTest.exist?(tmp_path(''))
build_pandoc option
build_resource option
build_hyoushi option
build_latex option
build_pdf option
end
|
#build_hyoushi(option) ⇒ Object
289
290
291
292
293
294
295
296
|
# File 'lib/xpub/dsl/builder.rb', line 289
def build_hyoushi(option)
open(tmp_path(@book.name + '.before_body.tex'), 'w') do |io|
io.puts @hyoushi.map { |h| h.latex @book, self } .join
end
open(tmp_path(@book.name + '.after_body.tex'), 'w') do |io|
io.puts @urahyoushi.map { |h| h.latex @book, self }.join
end
end
|
#build_latex(option) ⇒ Object
284
285
286
287
|
# File 'lib/xpub/dsl/builder.rb', line 284
def build_latex(option)
cmd_exec latex_cmd, ["-output-directory=#{tmp_path('')}", tex_path], option
cmd_exec latex_cmd, ["-output-directory=#{tmp_path('')}", tex_path], option
end
|
#build_pandoc(option) ⇒ Object
278
279
280
281
282
|
# File 'lib/xpub/dsl/builder.rb', line 278
def build_pandoc(option)
pandoc_option = pandoc_option(option).concat(vars_option).concat(@book.src_files.map(&:full_path))
cmd_exec pandoc_cmd, ['-o', json_path, '-t', 'json'].concat(pandoc_option), option if option['pandoc-json-output']
cmd_exec pandoc_cmd, ['-o', tex_path, '-t', 'latex'].concat(pandoc_option), option
end
|
#build_pdf(option) ⇒ Object
298
299
300
301
302
|
# File 'lib/xpub/dsl/builder.rb', line 298
def build_pdf(option)
unless FileTest.exist?(pdf_path) && (File.mtime(dvi_path) <= File.mtime(pdf_path))
cmd_exec "cd #{Shellwords.shellescape(tmp_path(''))};#{dvipdfm_cmd}", ['-o', pdf_path, dvi_path], option
end
end
|
#build_resource(option) ⇒ Object
253
254
255
|
# File 'lib/xpub/dsl/builder.rb', line 253
def build_resource(option)
_build_resource @book.resource_files, option
end
|
#classoption(param) ⇒ Object
186
187
188
|
# File 'lib/xpub/dsl/builder.rb', line 186
def classoption(param)
@vars << [:classoption, param]
end
|
#documentclass(param) ⇒ Object
182
183
184
|
# File 'lib/xpub/dsl/builder.rb', line 182
def documentclass(param)
@vars << [:documentclass, param]
end
|
#dvi_path ⇒ Object
231
232
233
|
# File 'lib/xpub/dsl/builder.rb', line 231
def dvi_path
tmp_path(@book.name) + '.dvi'
end
|
#filter_option ⇒ Object
219
220
221
|
# File 'lib/xpub/dsl/builder.rb', line 219
def filter_option
"--filter=#{Dir.getwd}/theme/#{theme}/#{@name}/#{filter}"
end
|
#hyoushi_empty_page(name, &block) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/xpub/dsl/page.rb', line 95
def hyoushi_empty_page(name, &block)
call = CallEmptyPageLatexOp.new name, @book, self
call.instance_eval(&block) if block
call.validate
@hyoushi << call
end
|
#hyoushi_image_page(name, &block) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/xpub/dsl/page.rb', line 88
def hyoushi_image_page(name, &block)
call = CallImgPageLatexOp.new name, @book, self
call.instance_eval(&block) if block
call.validate
@hyoushi << call
end
|
#hyoushi_inner_title_page(name, &block) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/xpub/dsl/page.rb', line 102
def hyoushi_inner_title_page(name, &block)
call = CallInnerTitlePageLatexOp.new name, @book, self
call.instance_eval(&block) if block
call.validate
@hyoushi << call
end
|
#json_path ⇒ Object
227
228
229
|
# File 'lib/xpub/dsl/builder.rb', line 227
def json_path
tmp_path(@book.name) + '.json'
end
|
#pandoc_option(_option) ⇒ Object
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/xpub/dsl/builder.rb', line 257
def pandoc_option(_option)
[
'--chapters',
'-f',
'markdown_phpextra+hard_line_breaks+raw_tex',
'-s',
template_option,
filter_option
]
end
|
#pdf_path ⇒ Object
235
236
237
238
239
240
241
|
# File 'lib/xpub/dsl/builder.rb', line 235
def pdf_path
if output
output_path(output) + '.pdf'
else
output_path(@book.name) + '.pdf'
end
end
|
#postchaptername(param) ⇒ Object
202
203
204
|
# File 'lib/xpub/dsl/builder.rb', line 202
def postchaptername(param)
@vars << [:postchaptername, param]
end
|
#postpartname(param) ⇒ Object
194
195
196
|
# File 'lib/xpub/dsl/builder.rb', line 194
def postpartname(param)
@vars << [:postpartname, param]
end
|
#prechaptername(param) ⇒ Object
198
199
200
|
# File 'lib/xpub/dsl/builder.rb', line 198
def prechaptername(param)
@vars << [:prechaptername, param]
end
|
#prepartname(param) ⇒ Object
190
191
192
|
# File 'lib/xpub/dsl/builder.rb', line 190
def prepartname(param)
@vars << [:prepartname, param]
end
|
#template_option ⇒ Object
215
216
217
|
# File 'lib/xpub/dsl/builder.rb', line 215
def template_option
"--template=#{Dir.getwd}/theme/#{theme}/#{@name}/#{template}"
end
|
#tex_path ⇒ Object
223
224
225
|
# File 'lib/xpub/dsl/builder.rb', line 223
def tex_path
tmp_path(@book.name) + '.tex'
end
|
#urahyoushi_empty_page(name, &block) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/xpub/dsl/page.rb', line 116
def urahyoushi_empty_page(name, &block)
call = CallEmptyPageLatexOp.new name, @book, self
call.instance_eval(&block) if block
call.validate
@urahyoushi << call
end
|
#urahyoushi_image_page(name, &block) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/xpub/dsl/page.rb', line 109
def urahyoushi_image_page(name, &block)
call = CallImgPageLatexOp.new name, @book, self
call.instance_eval(&block) if block
call.validate
@urahyoushi << call
end
|
#vars_option ⇒ Object
206
207
208
209
210
211
212
213
|
# File 'lib/xpub/dsl/builder.rb', line 206
def vars_option
result = []
@vars.concat([[:book_name, @book.name]]).each do |v|
result << '-V'
result << "#{v[0]}=#{v[1]}"
end
result
end
|