Class: Cheepub::Generator::Latex
Constant Summary
ROLES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#check_params, #execute, #parse_creator
Constructor Details
#initialize(src, params = Hash.new) ⇒ Latex
Returns a new instance of Latex.
10
11
12
13
14
|
# File 'lib/cheepub/generator/latex.rb', line 10
def initialize(src, params = Hash.new)
super
root_dir = File.dirname(src)
@maker = RbLatex::Maker.new(root_dir)
end
|
Instance Attribute Details
#maker ⇒ Object
Returns the value of attribute maker.
8
9
10
|
# File 'lib/cheepub/generator/latex.rb', line 8
def maker
@maker
end
|
Instance Method Details
#add_creator(name, role = "aut") ⇒ Object
21
22
23
|
# File 'lib/cheepub/generator/latex.rb', line 21
def add_creator(name, role = "aut")
@maker.add_creator(name, role)
end
|
#apply_params(params) ⇒ Object
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
|
# File 'lib/cheepub/generator/latex.rb', line 25
def apply_params(params)
@maker.title = params[:title]
add_creator(params[:author])
parse_creator(params[:creator])
@maker.publisher = params[:publisher] if params[:publisher]
@maker.date = params[:date] || Time.now
@maker.lastmodified = params[:lastModified] || Time.now
@maker.page_progression_direction = params[:pageDirection]
if params.key?(:latexCommand)
@maker.latex_command = params[:latexCommand]
end
if params.key?(:dvipdfCommand)
@maker.dvipdf_command = params[:dvipdfCommand]
end
@maker.debug = params[:debug]
if params[:documentClass]
@maker.document_class = params[:documentClass]
end
if params[:titlepage]
@maker.titlepage = params[:titlepage]
end
if params[:colophon]
@maker.colophon = params[:colophon]
end
if params[:colophon_before]
@maker.colophon_before = params[:colophon_before].gsub(/\n/m, "\\par ") + "\\vspace{5mm} \\par\n"
end
if params[:colophon_after]
@maker.colophon_after = params[:colophon_after].gsub(/\n/m, "\\par ")
end
@content.each_with_index do |file, idx|
content = Cheepub::Markdown.new(file, page_direction: params[:pageDirection]).to_latex
filename = "bodymatter_#{idx}.tex"
@maker.add_item(filename, content)
end
end
|
#apply_template(template_file) ⇒ Object
63
64
65
66
|
# File 'lib/cheepub/generator/latex.rb', line 63
def apply_template(template_file)
template = File.read(File.join(Cheepub::TEMPLATES_DIR, template_file))
return ERB.new(template).result(binding)
end
|
#output_file(params) ⇒ Object
16
17
18
19
|
# File 'lib/cheepub/generator/latex.rb', line 16
def output_file(params)
outfile = params[:output] || "book.pdf"
@maker.generate_pdf(outfile, debug: params[:debug])
end
|