Class: Xpub::CallBook::CallEpubBuilder
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 CallEpubBuilder.
69
70
71
72
73
74
|
# File 'lib/xpub/dsl/builder.rb', line 69
def initialize(name, book)
@vars = []
@meta = []
@vars << ['title', book.title] if book.title != ''
super name, book
end
|
Instance Method Details
#_build_resource(files, _option) ⇒ Object
126
127
128
|
# File 'lib/xpub/dsl/builder.rb', line 126
def _build_resource(files, _option)
copy_to_tmp files
end
|
#build(option) ⇒ Object
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/xpub/dsl/builder.rb', line 155
def build(option)
FileUtils.mkdir_p(tmp_path('')) unless FileTest.exist?(tmp_path(''))
build_epub_metadata option
pandoc_option = pandoc_option(option).concat(vars_option).concat(meta_option).concat(@book.src_files.map(&:full_path))
cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', json_path, '-t', 'json'].concat(pandoc_option), option if option['pandoc-json-output']
cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', epub_path, '-t', 'epub3'].concat(pandoc_option), option
end
|
146
147
148
149
150
151
152
153
|
# File 'lib/xpub/dsl/builder.rb', line 146
def build_epub_metadata(option)
f = open metadata_template_path
erb = ERB.new f.read, nil, '-'
f.close
f = open metadata_path, 'w'
f.write erb.result(binding)
f.close
end
|
#epub_path ⇒ Object
118
119
120
|
# File 'lib/xpub/dsl/builder.rb', line 118
def epub_path
output_path(@book.name) + '.epub'
end
|
#filter_option ⇒ Object
98
99
100
|
# File 'lib/xpub/dsl/builder.rb', line 98
def filter_option
"--filter=#{Dir.getwd}/theme/#{theme}/#{@name}/#{filter}"
end
|
#json_path ⇒ Object
122
123
124
|
# File 'lib/xpub/dsl/builder.rb', line 122
def json_path
tmp_path(@book.name) + '.json'
end
|
76
77
78
79
80
81
82
83
|
# File 'lib/xpub/dsl/builder.rb', line 76
def meta_option
result = []
@meta.concat([['page-progression-direction', page_progression_direction]]).each do |m|
result << '-M'
result << "#{m[0]}=#{m[1]}"
end
result
end
|
106
107
108
|
# File 'lib/xpub/dsl/builder.rb', line 106
def metadata_option
'--epub-metadata=' + metadata_path
end
|
110
111
112
|
# File 'lib/xpub/dsl/builder.rb', line 110
def metadata_path
tmp_path("#{@book.name}.#{metadata}")
end
|
114
115
116
|
# File 'lib/xpub/dsl/builder.rb', line 114
def metadata_template_path
"#{Dir.getwd}/theme/#{theme}/#{@name}/#{metadata}.erb"
end
|
#pandoc_option(option) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/xpub/dsl/builder.rb', line 130
def pandoc_option(option)
option = [
'--epub-chapter-level=1',
'--toc',
'-f',
'markdown_phpextra+hard_line_breaks+raw_html',
'-s',
template_option,
filter_option,
stylesheet_option,
metadata_option
]
option << '--epub-cover-image=' + src_path(cover_image) if cover_image
option
end
|
#stylesheet_option ⇒ Object
102
103
104
|
# File 'lib/xpub/dsl/builder.rb', line 102
def stylesheet_option
"--epub-stylesheet=#{Dir.getwd}/theme/#{theme}/#{@name}/#{stylesheet}"
end
|
#template_option ⇒ Object
94
95
96
|
# File 'lib/xpub/dsl/builder.rb', line 94
def template_option
"--template=#{Dir.getwd}/theme/#{theme}/#{@name}/#{template}"
end
|
#vars_option ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/xpub/dsl/builder.rb', line 85
def vars_option
result = []
@vars.concat([[:book_name, @book.name]]).each do |v|
result << '-V'
result << "#{v[0]}=#{v[1]}"
end
result
end
|