review 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +90 -66
- data/.travis.yml +1 -1
- data/Gemfile +0 -1
- data/NEWS.ja.md +82 -0
- data/NEWS.md +83 -0
- data/README.md +5 -3
- data/Rakefile +8 -8
- data/bin/review +1 -5
- data/bin/review-catalog-converter +22 -27
- data/bin/review-check +36 -43
- data/bin/review-checkdep +10 -15
- data/bin/review-compile +37 -55
- data/bin/review-epubmaker +4 -5
- data/bin/review-index +21 -29
- data/bin/review-init +26 -37
- data/bin/review-pdfmaker +0 -2
- data/bin/review-preproc +25 -45
- data/bin/review-validate +19 -18
- data/bin/review-vol +15 -27
- data/doc/config.yml.sample +5 -2
- data/doc/format.ja.md +20 -1
- data/doc/format.md +21 -5
- data/doc/images/review-generate.png +0 -0
- data/lib/epubmaker.rb +1 -3
- data/lib/epubmaker/content.rb +24 -27
- data/lib/epubmaker/epubcommon.rb +135 -148
- data/lib/epubmaker/epubv2.rb +39 -46
- data/lib/epubmaker/epubv3.rb +93 -103
- data/lib/epubmaker/producer.rb +138 -151
- data/lib/epubmaker/zip_exporter.rb +21 -26
- data/lib/review/book.rb +3 -6
- data/lib/review/book/base.rb +78 -103
- data/lib/review/book/chapter.rb +36 -40
- data/lib/review/book/compilable.rb +28 -31
- data/lib/review/book/image_finder.rb +6 -13
- data/lib/review/book/index.rb +100 -121
- data/lib/review/book/page_metric.rb +2 -7
- data/lib/review/book/part.rb +18 -20
- data/lib/review/book/volume.rb +9 -13
- data/lib/review/builder.rb +81 -116
- data/lib/review/catalog.rb +15 -19
- data/lib/review/compiler.rb +64 -83
- data/lib/review/configure.rb +87 -97
- data/lib/review/converter.rb +2 -7
- data/lib/review/epubbuilder.rb +1 -3
- data/lib/review/epubmaker.rb +213 -205
- data/lib/review/exception.rb +2 -4
- data/lib/review/extentions.rb +0 -1
- data/lib/review/extentions/hash.rb +2 -2
- data/lib/review/extentions/string.rb +5 -30
- data/lib/review/htmlbuilder.rb +320 -375
- data/lib/review/htmltoc.rb +4 -7
- data/lib/review/htmlutils.rb +29 -32
- data/lib/review/i18n.rb +33 -44
- data/lib/review/i18n.yml +3 -3
- data/lib/review/idgxmlbuilder.rb +309 -345
- data/lib/review/latexbuilder.rb +175 -212
- data/lib/review/latexindex.rb +2 -8
- data/lib/review/latexutils.rb +33 -43
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +21 -0
- data/lib/review/makerhelper.rb +1 -4
- data/lib/review/markdownbuilder.rb +44 -53
- data/lib/review/md2inaobuilder.rb +6 -12
- data/lib/review/pdfmaker.rb +143 -173
- data/lib/review/preprocessor.rb +64 -101
- data/lib/review/rstbuilder.rb +126 -158
- data/lib/review/sec_counter.rb +18 -34
- data/lib/review/template.rb +4 -5
- data/lib/review/textbuilder.rb +2 -3
- data/lib/review/textutils.rb +7 -13
- data/lib/review/tocparser.rb +31 -56
- data/lib/review/tocprinter.rb +26 -52
- data/lib/review/topbuilder.rb +219 -247
- data/lib/review/unfold.rb +15 -24
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +75 -99
- data/lib/review/webtocprinter.rb +15 -20
- data/lib/review/yamlloader.rb +13 -15
- data/review.gemspec +20 -22
- data/templates/latex/layout.tex.erb +2 -2
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/web/html/layout-html5.html.erb +2 -2
- data/test/assets/black.eps +280 -0
- data/test/assets/fit.png +0 -0
- data/test/assets/large.gif +0 -0
- data/test/assets/large.jpg +0 -0
- data/test/assets/large.png +0 -0
- data/test/assets/large.svg +65 -0
- data/test/assets/test_template.tex +1 -1
- data/test/book_test_helper.rb +2 -2
- data/test/run_test.rb +4 -4
- data/test/sample-book/src/Rakefile +21 -22
- data/test/syntax-book/Gemfile +4 -0
- data/test/syntax-book/Rakefile +72 -0
- data/test/syntax-book/appA.re +22 -0
- data/test/syntax-book/bib.re +6 -0
- data/test/syntax-book/catalog.yml +15 -0
- data/test/syntax-book/ch01.re +136 -0
- data/test/syntax-book/ch02.re +351 -0
- data/test/syntax-book/ch03.re +82 -0
- data/test/syntax-book/config.yml +35 -0
- data/test/syntax-book/images/ball.png +0 -0
- data/test/syntax-book/images/cover.jpg +0 -0
- data/test/syntax-book/images/fractal.png +0 -0
- data/test/syntax-book/images/img3-1.png +0 -0
- data/test/syntax-book/images/inlineicon.jpg +0 -0
- data/test/syntax-book/images/logic.png +0 -0
- data/test/syntax-book/images/logic2.png +0 -0
- data/test/syntax-book/images/puzzle.jpg +0 -0
- data/test/syntax-book/images/table.jpg +0 -0
- data/test/syntax-book/part2.re +6 -0
- data/test/syntax-book/pre01.re +26 -0
- data/test/syntax-book/review-ext.rb +14 -0
- data/test/syntax-book/sty/jumoline.sty +310 -0
- data/test/syntax-book/sty/reviewmacro.sty +39 -0
- data/test/syntax-book/style.css +494 -0
- data/test/syntax-book/syntax.dic +2 -0
- data/test/test_book.rb +106 -111
- data/test/test_book_chapter.rb +21 -22
- data/test/test_book_part.rb +3 -5
- data/test/test_builder.rb +11 -22
- data/test/test_catalog.rb +17 -18
- data/test/test_catalog_converter_cmd.rb +5 -5
- data/test/test_compiler.rb +18 -16
- data/test/test_configure.rb +35 -38
- data/test/test_converter.rb +3 -4
- data/test/test_epub3maker.rb +136 -117
- data/test/test_epubmaker.rb +107 -114
- data/test/test_epubmaker_cmd.rb +2 -4
- data/test/test_extentions_hash.rb +32 -33
- data/test/test_helper.rb +9 -11
- data/test/test_htmlbuilder.rb +454 -420
- data/test/test_htmltoc.rb +8 -12
- data/test/test_htmlutils.rb +0 -2
- data/test/test_i18n.rb +159 -150
- data/test/test_idgxmlbuilder.rb +190 -197
- data/test/test_image_finder.rb +21 -22
- data/test/test_index.rb +24 -29
- data/test/test_latexbuilder.rb +274 -264
- data/test/test_lineinput.rb +7 -10
- data/test/test_location.rb +7 -7
- data/test/test_makerhelper.rb +13 -25
- data/test/test_markdownbuilder.rb +23 -26
- data/test/test_md2inaobuilder.rb +8 -11
- data/test/test_pdfmaker.rb +114 -123
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +3 -5
- data/test/test_rstbuilder.rb +92 -97
- data/test/test_template.rb +3 -7
- data/test/test_textutils.rb +27 -27
- data/test/test_tocparser.rb +2 -2
- data/test/test_topbuilder.rb +98 -103
- data/test/test_webtocprinter.rb +5 -6
- data/test/test_yamlloader.rb +42 -42
- data/test/test_zip_exporter.rb +12 -18
- metadata +86 -9
- data/lib/review/ewbbuilder.rb +0 -382
data/lib/epubmaker/producer.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
1
|
# = producer.rb -- EPUB producer.
|
|
4
2
|
#
|
|
5
3
|
# Copyright (c) 2010-2017 Kenshi Muto
|
|
@@ -25,12 +23,12 @@ module EPUBMaker
|
|
|
25
23
|
# Array of content objects.
|
|
26
24
|
attr_accessor :contents
|
|
27
25
|
# Parameter hash.
|
|
28
|
-
attr_accessor :
|
|
26
|
+
attr_accessor :config
|
|
29
27
|
# Message resource object.
|
|
30
28
|
attr_reader :res
|
|
31
29
|
|
|
32
30
|
# Take YAML +file+ and return parameter hash.
|
|
33
|
-
def
|
|
31
|
+
def self.load(file)
|
|
34
32
|
raise "Can't open #{file}." if file.nil? || !File.exist?(file)
|
|
35
33
|
loader = ReVIEW::YAMLLoader.new
|
|
36
34
|
loader.load_file(file)
|
|
@@ -40,52 +38,48 @@ module EPUBMaker
|
|
|
40
38
|
def load(file)
|
|
41
39
|
raise "Can't open #{file}." if file.nil? || !File.exist?(file)
|
|
42
40
|
loader = ReVIEW::YAMLLoader.new
|
|
43
|
-
|
|
41
|
+
merge_config(@config.deep_merge(loader.load_file(file)))
|
|
44
42
|
end
|
|
45
43
|
|
|
46
44
|
# Construct producer object.
|
|
47
|
-
# +
|
|
45
|
+
# +config+ takes initial parameter hash. This parameters can be overriden by EPUBMaker#load or EPUBMaker#merge_config.
|
|
48
46
|
# +version+ takes EPUB version (default is 2).
|
|
49
|
-
def initialize(
|
|
47
|
+
def initialize(config = nil, version = nil)
|
|
50
48
|
@contents = []
|
|
51
|
-
@
|
|
49
|
+
@config = ReVIEW::Configure.new
|
|
52
50
|
@epub = nil
|
|
53
|
-
@
|
|
51
|
+
@config['epubversion'] = version unless version.nil?
|
|
54
52
|
@res = ReVIEW::I18n
|
|
55
53
|
|
|
56
|
-
if
|
|
57
|
-
merge_params(params)
|
|
58
|
-
end
|
|
54
|
+
merge_config(config) if config
|
|
59
55
|
end
|
|
60
56
|
|
|
61
57
|
def coverimage
|
|
62
|
-
return nil unless
|
|
58
|
+
return nil unless config['coverimage']
|
|
63
59
|
@contents.each do |item|
|
|
64
|
-
if item.media.start_with?('image') && item.file =~ /#{
|
|
60
|
+
if item.media.start_with?('image') && item.file =~ /#{config['coverimage']}\Z/
|
|
65
61
|
return item.file
|
|
66
62
|
end
|
|
67
63
|
end
|
|
68
|
-
|
|
64
|
+
nil
|
|
69
65
|
end
|
|
70
66
|
|
|
71
|
-
# Update parameters by merging from new parameter hash +
|
|
72
|
-
def
|
|
73
|
-
@
|
|
67
|
+
# Update parameters by merging from new parameter hash +config+.
|
|
68
|
+
def merge_config(config)
|
|
69
|
+
@config.deep_merge!(config)
|
|
74
70
|
complement
|
|
75
71
|
|
|
76
|
-
unless @
|
|
77
|
-
case @
|
|
72
|
+
unless @config['epubversion'].nil?
|
|
73
|
+
case @config['epubversion'].to_i
|
|
78
74
|
when 2
|
|
79
75
|
@epub = EPUBMaker::EPUBv2.new(self)
|
|
80
76
|
when 3
|
|
81
77
|
@epub = EPUBMaker::EPUBv3.new(self)
|
|
82
78
|
else
|
|
83
|
-
raise "Invalid EPUB version (#{@
|
|
79
|
+
raise "Invalid EPUB version (#{@config['epubversion']}.)"
|
|
84
80
|
end
|
|
85
81
|
end
|
|
86
|
-
if
|
|
87
|
-
ReVIEW::I18n.locale = params["language"]
|
|
88
|
-
end
|
|
82
|
+
ReVIEW::I18n.locale = config['language'] if config['language']
|
|
89
83
|
support_legacy_maker
|
|
90
84
|
end
|
|
91
85
|
|
|
@@ -103,7 +97,7 @@ module EPUBMaker
|
|
|
103
97
|
|
|
104
98
|
# Write ncx file to IO object +wobj+. +indentarray+ defines prefix
|
|
105
99
|
# string for each level.
|
|
106
|
-
def ncx(wobj, indentarray=[])
|
|
100
|
+
def ncx(wobj, indentarray = [])
|
|
107
101
|
s = @epub.ncx(indentarray)
|
|
108
102
|
wobj.puts s if !s.nil? && !wobj.nil?
|
|
109
103
|
end
|
|
@@ -115,10 +109,10 @@ module EPUBMaker
|
|
|
115
109
|
end
|
|
116
110
|
|
|
117
111
|
# Write cover file to IO object +wobj+.
|
|
118
|
-
# If Producer#
|
|
112
|
+
# If Producer#config["coverimage"] is defined, it will be used for
|
|
119
113
|
# the cover image.
|
|
120
114
|
def cover(wobj)
|
|
121
|
-
type =
|
|
115
|
+
type = @config['epubversion'] >= 3 ? 'cover' : nil
|
|
122
116
|
s = @epub.cover(type)
|
|
123
117
|
wobj.puts s if !s.nil? && !wobj.nil?
|
|
124
118
|
end
|
|
@@ -143,22 +137,20 @@ module EPUBMaker
|
|
|
143
137
|
|
|
144
138
|
# Add informations of figure files in +path+ to contents array.
|
|
145
139
|
# +base+ defines a string to remove from path name.
|
|
146
|
-
def import_imageinfo(path, base=nil, allow_exts=nil)
|
|
140
|
+
def import_imageinfo(path, base = nil, allow_exts = nil)
|
|
147
141
|
return nil unless File.exist?(path)
|
|
148
|
-
allow_exts = @
|
|
142
|
+
allow_exts = @config['image_ext'] if allow_exts.nil?
|
|
149
143
|
Dir.foreach(path) do |f|
|
|
150
144
|
next if f.start_with?('.')
|
|
151
|
-
if f =~ /\.(#{allow_exts.join(
|
|
152
|
-
path.chop! if path =~
|
|
145
|
+
if f =~ /\.(#{allow_exts.join('|')})\Z/i
|
|
146
|
+
path.chop! if path =~ %r{/\Z}
|
|
153
147
|
if base.nil?
|
|
154
|
-
@contents.push(EPUBMaker::Content.new(
|
|
148
|
+
@contents.push(EPUBMaker::Content.new('file' => "#{path}/#{f}"))
|
|
155
149
|
else
|
|
156
|
-
@contents.push(EPUBMaker::Content.new(
|
|
150
|
+
@contents.push(EPUBMaker::Content.new('file' => "#{path.sub(base + '/', '')}/#{f}"))
|
|
157
151
|
end
|
|
158
152
|
end
|
|
159
|
-
if FileTest.directory?("#{path}/#{f}")
|
|
160
|
-
import_imageinfo("#{path}/#{f}", base)
|
|
161
|
-
end
|
|
153
|
+
import_imageinfo("#{path}/#{f}", base) if FileTest.directory?("#{path}/#{f}")
|
|
162
154
|
end
|
|
163
155
|
end
|
|
164
156
|
|
|
@@ -167,12 +159,12 @@ module EPUBMaker
|
|
|
167
159
|
# Produce EPUB file +epubfile+.
|
|
168
160
|
# +basedir+ points the directory has contents (default: current directory.)
|
|
169
161
|
# +tmpdir+ defines temporary directory.
|
|
170
|
-
def produce(epubfile, basedir=nil, tmpdir=nil)
|
|
162
|
+
def produce(epubfile, basedir = nil, tmpdir = nil)
|
|
171
163
|
current = Dir.pwd
|
|
172
164
|
basedir = current if basedir.nil?
|
|
173
165
|
|
|
174
166
|
new_tmpdir = tmpdir.nil? ? Dir.mktmpdir : tmpdir
|
|
175
|
-
epubfile = "#{current}/#{epubfile}" if epubfile !~
|
|
167
|
+
epubfile = "#{current}/#{epubfile}" if epubfile !~ %r{\A/}
|
|
176
168
|
|
|
177
169
|
# FIXME: error check
|
|
178
170
|
File.unlink(epubfile) if File.exist?(epubfile)
|
|
@@ -185,115 +177,110 @@ module EPUBMaker
|
|
|
185
177
|
end
|
|
186
178
|
|
|
187
179
|
def call_hook(filename, *params)
|
|
188
|
-
if !filename.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
end
|
|
180
|
+
return if !filename.present? || !File.exist?(filename) || !FileTest.executable?(filename)
|
|
181
|
+
if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
|
|
182
|
+
warn 'hook is prohibited in safe mode. ignored.'
|
|
183
|
+
else
|
|
184
|
+
system(filename, *params)
|
|
194
185
|
end
|
|
195
186
|
end
|
|
196
187
|
|
|
197
188
|
def isbn_hyphen
|
|
198
|
-
str = @
|
|
189
|
+
str = @config['isbn'].to_s
|
|
199
190
|
|
|
200
|
-
if str =~ /\A\d{10}\Z/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
"#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}"
|
|
204
|
-
else
|
|
205
|
-
nil
|
|
206
|
-
end
|
|
191
|
+
return "#{str[0..0]}-#{str[1..5]}-#{str[6..8]}-#{str[9..9]}" if str =~ /\A\d{10}\Z/
|
|
192
|
+
return "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}" if str =~ /\A\d{13}\Z/
|
|
193
|
+
nil
|
|
207
194
|
end
|
|
208
195
|
|
|
209
196
|
private
|
|
210
197
|
|
|
211
198
|
# Complement parameters.
|
|
212
199
|
def complement
|
|
213
|
-
@
|
|
214
|
-
defaults = ReVIEW::Configure.new.merge(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
@
|
|
200
|
+
@config['htmlext'] = 'html' if @config['htmlext'].nil?
|
|
201
|
+
defaults = ReVIEW::Configure.new.merge(
|
|
202
|
+
'language' => 'ja',
|
|
203
|
+
'date' => Time.now.strftime('%Y-%m-%d'),
|
|
204
|
+
'modified' => Time.now.strftime('%Y-%02m-%02dT%02H:%02M:%02SZ'),
|
|
205
|
+
'isbn' => nil,
|
|
206
|
+
'toclevel' => 2,
|
|
207
|
+
'stylesheet' => [],
|
|
208
|
+
'epubversion' => 3,
|
|
209
|
+
'htmlversion' => 5,
|
|
210
|
+
'secnolevel' => 2,
|
|
211
|
+
'pre_secnolevel' => 0,
|
|
212
|
+
'post_secnolevel' => 1,
|
|
213
|
+
'part_secnolevel' => 1,
|
|
214
|
+
'titlepage' => true,
|
|
215
|
+
'titlefile' => nil,
|
|
216
|
+
'originaltitlefile' => nil,
|
|
217
|
+
'profile' => nil,
|
|
218
|
+
'colophon' => nil,
|
|
219
|
+
'colophon_order' => %w[aut csl trl dsr ill edt pbl prt pht],
|
|
220
|
+
'direction' => 'ltr',
|
|
221
|
+
'epubmaker' => {
|
|
222
|
+
'flattoc' => nil,
|
|
223
|
+
'flattocindent' => true,
|
|
224
|
+
'ncx_indent' => [],
|
|
225
|
+
'zip_stage1' => 'zip -0Xq',
|
|
226
|
+
'zip_stage2' => 'zip -Xr9Dq',
|
|
227
|
+
'zip_addpath' => nil,
|
|
228
|
+
'hook_beforeprocess' => nil,
|
|
229
|
+
'hook_afterfrontmatter' => nil,
|
|
230
|
+
'hook_afterbody' => nil,
|
|
231
|
+
'hook_afterbackmatter' => nil,
|
|
232
|
+
'hook_aftercopyimage' => nil,
|
|
233
|
+
'hook_prepack' => nil,
|
|
234
|
+
'rename_for_legacy' => nil,
|
|
235
|
+
'verify_target_images' => nil,
|
|
236
|
+
'force_include_images' => [],
|
|
237
|
+
'cover_linear' => nil
|
|
238
|
+
},
|
|
239
|
+
'externallink' => true,
|
|
240
|
+
'imagedir' => 'images',
|
|
241
|
+
'fontdir' => 'fonts',
|
|
242
|
+
'image_ext' => %w[png gif jpg jpeg svg ttf woff otf],
|
|
243
|
+
'image_maxpixels' => 4_000_000,
|
|
244
|
+
'font_ext' => %w[ttf woff otf]
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
@config = defaults.deep_merge(@config)
|
|
248
|
+
@config['title'] = @config['booktitle'] unless @config['title']
|
|
261
249
|
|
|
262
250
|
deprecated_parameters = {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
251
|
+
'ncxindent' => 'epubmaker:ncxindent',
|
|
252
|
+
'flattoc' => 'epubmaker:flattoc',
|
|
253
|
+
'flattocindent' => 'epubmaker:flattocindent',
|
|
254
|
+
'hook_beforeprocess' => 'epubmaker:hook_beforeprocess',
|
|
255
|
+
'hook_afterfrontmatter' => 'epubmaker:hook_afterfrontmatter',
|
|
256
|
+
'hook_afterbody' => 'epubmaker:hook_afterbody',
|
|
257
|
+
'hook_afterbackmatter' => 'epubmaker:hook_afterbackmatter',
|
|
258
|
+
'hook_aftercopyimage' => 'epubmaker:hook_aftercopyimage',
|
|
259
|
+
'hook_prepack' => 'epubmaker:hook_prepack',
|
|
260
|
+
'rename_for_legacy' => 'epubmaker:rename_for_legacy',
|
|
261
|
+
'zip_stage1' => 'epubmaker:zip_stage1',
|
|
262
|
+
'zip_stage2' => 'epubmaker:zip_stage2',
|
|
263
|
+
'zip_addpath' => 'epubmaker:zip_addpath',
|
|
264
|
+
'verify_target_images' => 'epubmaker:verify_target_images',
|
|
265
|
+
'force_include_images' => 'epubmaker:force_include_images',
|
|
266
|
+
'cover_linear' => 'epubmaker:cover_linear'
|
|
279
267
|
}
|
|
280
268
|
|
|
281
269
|
deprecated_parameters.each_pair do |k, v|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
end
|
|
270
|
+
next if @config[k].nil?
|
|
271
|
+
sa = v.split(':', 2)
|
|
272
|
+
warn "Parameter #{k} is deprecated. Use:\n#{sa[0]}:\n #{sa[1]}: ...\n\n"
|
|
273
|
+
@config[sa[0]][sa[1]] = @config[k]
|
|
274
|
+
@config.delete(k)
|
|
288
275
|
end
|
|
289
276
|
|
|
290
|
-
@
|
|
277
|
+
@config['htmlversion'] = 5 if @config['epubversion'] >= 3
|
|
291
278
|
|
|
292
|
-
@
|
|
293
|
-
@
|
|
279
|
+
@config.maker = 'epubmaker'
|
|
280
|
+
@config['cover'] = "#{@config['bookname']}.#{@config['htmlext']}" unless @config['cover']
|
|
294
281
|
|
|
295
282
|
%w[bookname title].each do |k|
|
|
296
|
-
raise "Key #{k} must have a value. Abort." unless @
|
|
283
|
+
raise "Key #{k} must have a value. Abort." unless @config[k]
|
|
297
284
|
end
|
|
298
285
|
# array
|
|
299
286
|
%w[subject aut
|
|
@@ -302,8 +289,8 @@ module EPUBMaker
|
|
|
302
289
|
adp ann arr art asn aut aqt aft aui ant bkp clb cmm dsr edt
|
|
303
290
|
ill lyr mdc mus nrt oth pht pbl prt red rev spn ths trc trl
|
|
304
291
|
stylesheet rights].each do |item|
|
|
305
|
-
next unless @
|
|
306
|
-
@
|
|
292
|
+
next unless @config[item]
|
|
293
|
+
@config[item] = [@config[item]] if @config[item].is_a?(String)
|
|
307
294
|
end
|
|
308
295
|
# optional
|
|
309
296
|
# type, format, identifier, source, relation, coverpage, aut
|
|
@@ -311,36 +298,36 @@ module EPUBMaker
|
|
|
311
298
|
|
|
312
299
|
def support_legacy_maker
|
|
313
300
|
# legacy review-epubmaker support
|
|
314
|
-
if @
|
|
315
|
-
@
|
|
316
|
-
@epub.legacy_cover_and_title_file(@
|
|
317
|
-
@
|
|
318
|
-
warn
|
|
301
|
+
if @config['flag_legacy_coverfile'].nil? && !@config['coverfile'].nil? && File.exist?(@config['coverfile'])
|
|
302
|
+
@config['cover'] = "#{@config['bookname']}-cover.#{@config['htmlext']}"
|
|
303
|
+
@epub.legacy_cover_and_title_file(@config['coverfile'], @config['cover'])
|
|
304
|
+
@config['flag_legacy_coverfile'] = true
|
|
305
|
+
warn %Q(Parameter 'coverfile' is obsolete. Please use 'cover' and make complete html file with header and footer.)
|
|
319
306
|
end
|
|
320
307
|
|
|
321
|
-
if @
|
|
322
|
-
@
|
|
323
|
-
@
|
|
324
|
-
@epub.legacy_cover_and_title_file(@
|
|
325
|
-
@
|
|
326
|
-
warn
|
|
308
|
+
if @config['flag_legacy_titlepagefile'].nil? && !@config['titlepagefile'].nil? && File.exist?(@config['titlepagefile'])
|
|
309
|
+
@config['titlefile'] = "#{@config['bookname']}-title.#{@config['htmlext']}"
|
|
310
|
+
@config['titlepage'] = true
|
|
311
|
+
@epub.legacy_cover_and_title_file(@config['titlepagefile'], @config['titlefile'])
|
|
312
|
+
@config['flag_legacy_titlepagefile'] = true
|
|
313
|
+
warn %Q(Parameter 'titlepagefile' is obsolete. Please use 'titlefile' and make complete html file with header and footer.)
|
|
327
314
|
end
|
|
328
315
|
|
|
329
|
-
if @
|
|
330
|
-
@
|
|
331
|
-
@epub.legacy_cover_and_title_file(@
|
|
332
|
-
@
|
|
333
|
-
warn
|
|
316
|
+
if @config['flag_legacy_backcoverfile'].nil? && !@config['backcoverfile'].nil? && File.exist?(@config['backcoverfile'])
|
|
317
|
+
@config['backcover'] = "#{@config['bookname']}-backcover.#{@config['htmlext']}"
|
|
318
|
+
@epub.legacy_cover_and_title_file(@config['backcoverfile'], @config['backcover'])
|
|
319
|
+
@config['flag_legacy_backcoverfile'] = true
|
|
320
|
+
warn %Q(Parameter 'backcoverfile' is obsolete. Please use 'backcover' and make complete html file with header and footer.)
|
|
334
321
|
end
|
|
335
322
|
|
|
336
|
-
if @
|
|
337
|
-
@
|
|
338
|
-
@
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
@params["flag_legacy_pubhistory"] = true
|
|
342
|
-
warn "Parameter 'pubhistory' is obsolete. Please use 'history' array."
|
|
323
|
+
if @config['flag_legacy_pubhistory'].nil? && @config['pubhistory']
|
|
324
|
+
@config['history'] = [[]]
|
|
325
|
+
@config['pubhistory'].split("\n").each { |date| @config['history'][0].push(date.sub(/(\d+)年(\d+)月(\d+)日/, '\1-\2-\3')) }
|
|
326
|
+
@config['flag_legacy_pubhistory'] = true
|
|
327
|
+
warn %Q(Parameter 'pubhistory' is obsolete. Please use 'history' array.)
|
|
343
328
|
end
|
|
329
|
+
|
|
330
|
+
true
|
|
344
331
|
end
|
|
345
332
|
end
|
|
346
333
|
end
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
1
|
# Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
|
|
4
2
|
#
|
|
5
3
|
# This program is free software.
|
|
@@ -13,21 +11,19 @@ begin
|
|
|
13
11
|
require 'zip'
|
|
14
12
|
rescue LoadError
|
|
15
13
|
## I cannot find rubyzip library, so I use external zip command.
|
|
16
|
-
warn
|
|
14
|
+
warn 'rubyzip not found, so use external zip command'
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
module EPUBMaker
|
|
20
|
-
|
|
21
18
|
##
|
|
22
19
|
# Export into zip file for EPUB producer.
|
|
23
20
|
#
|
|
24
21
|
class ZipExporter
|
|
25
|
-
|
|
26
22
|
attr_reader :tmpdir
|
|
27
23
|
|
|
28
|
-
def initialize(tmpdir,
|
|
24
|
+
def initialize(tmpdir, config)
|
|
29
25
|
@tmpdir = tmpdir
|
|
30
|
-
@
|
|
26
|
+
@config = config
|
|
31
27
|
end
|
|
32
28
|
|
|
33
29
|
def export_zip(epubfile)
|
|
@@ -39,43 +35,42 @@ module EPUBMaker
|
|
|
39
35
|
end
|
|
40
36
|
|
|
41
37
|
def export_zip_extcmd(epubfile)
|
|
42
|
-
stage1 = @
|
|
43
|
-
path1 = stage1[0] ||
|
|
44
|
-
opt1 = stage1[1] ||
|
|
45
|
-
stage2 = @
|
|
46
|
-
path2 = stage2[0] ||
|
|
47
|
-
opt2 = stage2[1] ||
|
|
38
|
+
stage1 = @config['epubmaker']['zip_stage1'].to_s.split
|
|
39
|
+
path1 = stage1[0] || 'zip'
|
|
40
|
+
opt1 = stage1[1] || '-0Xq'
|
|
41
|
+
stage2 = @config['epubmaker']['zip_stage2'].to_s.split
|
|
42
|
+
path2 = stage2[0] || 'zip'
|
|
43
|
+
opt2 = stage2[1] || '-Xr9Dq'
|
|
48
44
|
|
|
49
|
-
Dir.chdir(tmpdir) do
|
|
50
|
-
system(path1, opt1, epubfile,
|
|
51
|
-
addpath = @
|
|
45
|
+
Dir.chdir(tmpdir) do
|
|
46
|
+
system(path1, opt1, epubfile, 'mimetype')
|
|
47
|
+
addpath = @config['epubmaker']['zip_addpath']
|
|
52
48
|
if addpath
|
|
53
|
-
system(path2, opt2, epubfile,
|
|
49
|
+
system(path2, opt2, epubfile, 'META-INF', 'OEBPS', addpath)
|
|
54
50
|
else
|
|
55
|
-
system(path2, opt2, epubfile,
|
|
51
|
+
system(path2, opt2, epubfile, 'META-INF', 'OEBPS')
|
|
56
52
|
end
|
|
57
53
|
end
|
|
58
54
|
end
|
|
59
55
|
|
|
60
56
|
def export_zip_rubyzip(epubfile)
|
|
61
|
-
Dir.chdir(tmpdir) do
|
|
57
|
+
Dir.chdir(tmpdir) do
|
|
62
58
|
Zip::OutputStream.open(epubfile) do |epub|
|
|
63
59
|
root_pathname = Pathname.new(tmpdir)
|
|
64
|
-
# relpath = Pathname.new(File.join(tmpdir,'mimetype')).relative_path_from(root_pathname)
|
|
65
60
|
epub.put_next_entry('mimetype', nil, nil, Zip::Entry::STORED)
|
|
66
|
-
epub <<
|
|
61
|
+
epub << 'application/epub+zip'
|
|
67
62
|
|
|
68
|
-
export_zip_rubyzip_addpath(epub, File.join(tmpdir,'META-INF'), root_pathname)
|
|
69
|
-
export_zip_rubyzip_addpath(epub, File.join(tmpdir,'OEBPS'), root_pathname)
|
|
70
|
-
if @
|
|
71
|
-
export_zip_rubyzip_addpath(epub, File.join(tmpdir, @
|
|
63
|
+
export_zip_rubyzip_addpath(epub, File.join(tmpdir, 'META-INF'), root_pathname)
|
|
64
|
+
export_zip_rubyzip_addpath(epub, File.join(tmpdir, 'OEBPS'), root_pathname)
|
|
65
|
+
if @config['zip_addpath'].present?
|
|
66
|
+
export_zip_rubyzip_addpath(epub, File.join(tmpdir, @config['zip_addpath']), root_pathname)
|
|
72
67
|
end
|
|
73
68
|
end
|
|
74
69
|
end
|
|
75
70
|
end
|
|
76
71
|
|
|
77
72
|
def export_zip_rubyzip_addpath(epub, dirname, rootdir)
|
|
78
|
-
Dir[File.join(dirname,'**','**')].each do |path|
|
|
73
|
+
Dir[File.join(dirname, '**', '**')].each do |path|
|
|
79
74
|
next if File.directory?(path)
|
|
80
75
|
relpath = Pathname.new(path).relative_path_from(rootdir)
|
|
81
76
|
epub.put_next_entry(relpath)
|