review 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +43 -1
  3. data/.rubocop_todo.yml +605 -0
  4. data/.travis.yml +9 -0
  5. data/ChangeLog +4 -0
  6. data/Dockerfile +22 -0
  7. data/README.rdoc +1 -1
  8. data/Rakefile +1 -1
  9. data/bin/review-check +8 -21
  10. data/bin/review-compile +9 -15
  11. data/bin/review-epubmaker-legacy +6 -6
  12. data/bin/review-index +2 -13
  13. data/bin/review-preproc +1 -14
  14. data/bin/review-validate +1 -1
  15. data/bin/review-vol +1 -13
  16. data/doc/NEWS.ja.md +22 -0
  17. data/doc/NEWS.md +22 -0
  18. data/doc/quickstart.ja.md +1 -1
  19. data/doc/quickstart.md +1 -1
  20. data/lib/epubmaker/content.rb +3 -3
  21. data/lib/epubmaker/epubcommon.rb +91 -108
  22. data/lib/epubmaker/epubv2.rb +14 -67
  23. data/lib/epubmaker/epubv3.rb +25 -59
  24. data/lib/epubmaker/producer.rb +12 -0
  25. data/lib/review/book/base.rb +12 -4
  26. data/lib/review/book/compilable.rb +1 -3
  27. data/lib/review/book/index.rb +4 -4
  28. data/lib/review/builder.rb +6 -11
  29. data/lib/review/compiler.rb +7 -7
  30. data/lib/review/configure.rb +20 -8
  31. data/lib/review/epubbuilder.rb +1 -1
  32. data/lib/review/epubmaker.rb +52 -122
  33. data/lib/review/ewbbuilder.rb +4 -4
  34. data/lib/review/exception.rb +1 -1
  35. data/lib/review/htmlbuilder.rb +49 -54
  36. data/lib/review/htmltoc.rb +45 -0
  37. data/lib/review/htmlutils.rb +3 -3
  38. data/lib/review/i18n.rb +6 -2
  39. data/lib/review/i18n.yml +1 -1
  40. data/lib/review/idgxmlbuilder.rb +4 -5
  41. data/lib/review/inaobuilder.rb +1 -1
  42. data/lib/review/latexbuilder.rb +2 -2
  43. data/lib/review/latexutils.rb +6 -6
  44. data/lib/review/markdownbuilder.rb +4 -3
  45. data/lib/review/pdfmaker.rb +92 -92
  46. data/lib/review/preprocessor.rb +14 -51
  47. data/lib/review/template.rb +21 -0
  48. data/lib/review/textbuilder.rb +1 -1
  49. data/lib/review/textutils.rb +0 -28
  50. data/lib/review/tocparser.rb +3 -3
  51. data/lib/review/tocprinter.rb +8 -31
  52. data/lib/review/topbuilder.rb +2 -3
  53. data/lib/review/unfold.rb +2 -2
  54. data/lib/review/version.rb +1 -1
  55. data/review.gemspec +2 -1
  56. data/templates/html/layout-html5.html.erb +17 -0
  57. data/templates/html/layout-xhtml1.html.erb +20 -0
  58. data/templates/ncx/epubv2.ncx.erb +11 -0
  59. data/templates/opf/epubv2.opf.erb +21 -0
  60. data/templates/opf/epubv3.opf.erb +18 -0
  61. data/templates/xml/container.xml.erb +6 -0
  62. data/test/assets/test.xml.erb +3 -0
  63. data/test/test.re +1 -1
  64. data/test/test_book.rb +4 -4
  65. data/test/test_book_chapter.rb +0 -76
  66. data/test/test_book_part.rb +1 -1
  67. data/test/test_builder.rb +0 -49
  68. data/test/test_configure.rb +50 -0
  69. data/test/test_htmlbuilder.rb +54 -4
  70. data/test/test_htmltoc.rb +32 -0
  71. data/test/test_i18n.rb +3 -5
  72. data/test/test_idgxmlbuilder.rb +0 -2
  73. data/test/test_inaobuilder.rb +2 -4
  74. data/test/test_latexbuilder.rb +2 -4
  75. data/test/test_lineinput.rb +0 -18
  76. data/test/test_markdownbuilder.rb +5 -4
  77. data/test/test_pdfmaker.rb +11 -10
  78. data/test/test_template.rb +26 -0
  79. data/test/test_topbuilder.rb +0 -2
  80. metadata +35 -4
  81. data/rubocop-todo.yml +0 -456
@@ -28,6 +28,10 @@ module EPUBMaker
28
28
  "application/epub+zip"
29
29
  end
30
30
 
31
+ def opf_path
32
+ "OEBPS/#{@producer.params["bookname"]}.opf"
33
+ end
34
+
31
35
  def opf_coverimage
32
36
  s = ""
33
37
  if @producer.params["coverimage"]
@@ -112,66 +116,53 @@ EOT
112
116
 
113
117
  # Return container content.
114
118
  def container
115
- s = <<EOT
116
- <?xml version="1.0" encoding="UTF-8"?>
117
- <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
118
- <rootfiles>
119
- <rootfile full-path="OEBPS/#{@producer.params["bookname"]}.opf" media-type="application/oebps-package+xml" />
120
- </rootfiles>
121
- </container>
122
- EOT
123
- s
119
+ @opf_path = opf_path
120
+ tmplfile = File.expand_path('./xml/container.xml.erb', ReVIEW::Template::TEMPLATE_DIR)
121
+ tmpl = ReVIEW::Template.load(tmplfile)
122
+ tmpl.result(binding)
124
123
  end
125
124
 
126
125
  # Return cover content.
127
126
  def cover(type=nil)
128
- bodyext = type.nil? ? "" : " epub:type=\"#{type}\""
127
+ @body_ext = type.nil? ? "" : " epub:type=\"#{type}\""
129
128
 
130
- s = common_header
131
- s << <<EOT
132
- <title>#{CGI.escapeHTML(@producer.params["title"])}</title>
133
- </head>
134
- <body#{bodyext}>
135
- EOT
136
- if @producer.params["coverimage"].nil?
137
- s << <<EOT
138
- <h1 class="cover-title">#{CGI.escapeHTML(@producer.params["title"])}</h1>
139
- EOT
140
- else
141
- file = nil
142
- @producer.contents.each do |item|
143
- if item.media =~ /\Aimage/ && item.file =~ /#{@producer.params["coverimage"]}\Z/ # /
144
- file = item.file
145
- break
146
- end
129
+ if @producer.params["coverimage"]
130
+ file = @producer.coverimage
131
+ if !file
132
+ raise "coverimage #{@producer.params["coverimage"]} not found. Abort."
147
133
  end
148
- raise "coverimage #{@producer.params["coverimage"]} not found. Abort." if file.nil?
149
- s << <<EOT
134
+ @body = <<-EOT
150
135
  <div id="cover-image" class="cover-image">
151
136
  <img src="#{file}" alt="#{CGI.escapeHTML(@producer.params["title"])}" class="max"/>
152
137
  </div>
153
- EOT
138
+ EOT
139
+ else
140
+ @body = <<-EOT
141
+ <h1 class="cover-title">#{CGI.escapeHTML(@producer.params["title"])}</h1>
142
+ EOT
154
143
  end
155
144
 
156
- s << <<EOT
157
- </body>
158
- </html>
159
- EOT
160
- s
145
+ @title = @producer.params['title']
146
+ @language = @producer.params['language']
147
+ @stylesheets = @producer.params["stylesheet"]
148
+ if @producer.params["htmlversion"].to_i == 5
149
+ tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
150
+ else
151
+ tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
152
+ end
153
+ tmpl = ReVIEW::Template.load(tmplfile)
154
+ tmpl.result(binding)
161
155
  end
162
156
 
163
157
  # Return title (copying) content.
164
158
  def titlepage
165
- s = common_header
166
- s << <<EOT
167
- <title>#{CGI.escapeHTML(@producer.params["title"])}</title>
168
- </head>
169
- <body>
170
- <h1 class="tp-title">#{CGI.escapeHTML(@producer.params["title"])}</h1>
171
- EOT
159
+ @title = @producer.params["title"]
172
160
 
161
+ @body = <<EOT
162
+ <h1 class="tp-title">#{CGI.escapeHTML(@title)}</h1>
163
+ EOT
173
164
  if @producer.params["aut"]
174
- s << <<EOT
165
+ @body << <<EOT
175
166
  <p>
176
167
  <br />
177
168
  <br />
@@ -182,7 +173,7 @@ EOT
182
173
 
183
174
  publisher = @producer.params["pbl"] || @producer.params["prt"] # XXX Backward Compatiblity
184
175
  if publisher
185
- s << <<EOT
176
+ @body << <<EOT
186
177
  <p>
187
178
  <br />
188
179
  <br />
@@ -193,67 +184,66 @@ EOT
193
184
  EOT
194
185
  end
195
186
 
196
- s << <<EOT
197
- </body>
198
- </html>
199
- EOT
200
-
201
- s
187
+ @language = @producer.params['language']
188
+ @stylesheets = @producer.params["stylesheet"]
189
+ if @producer.params["htmlversion"].to_i == 5
190
+ tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
191
+ else
192
+ tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
193
+ end
194
+ tmpl = ReVIEW::Template.load(tmplfile)
195
+ tmpl.result(binding)
202
196
  end
203
197
 
204
198
  # Return colophon content.
205
199
  def colophon
206
- s = common_header
207
- s << <<EOT
208
- <title>#{@producer.res.v("colophontitle")}</title>
209
- </head>
210
- <body>
200
+ @title = @producer.res.v("colophontitle")
201
+ @body = <<EOT
211
202
  <div class="colophon">
212
203
  EOT
213
204
 
214
205
  if @producer.params["subtitle"].nil?
215
- s << <<EOT
206
+ @body << <<EOT
216
207
  <p class="title">#{CGI.escapeHTML(@producer.params["title"])}</p>
217
208
  EOT
218
209
  else
219
- s << <<EOT
210
+ @body << <<EOT
220
211
  <p class="title">#{CGI.escapeHTML(@producer.params["title"])}<br /><span class="subtitle">#{CGI.escapeHTML(@producer.params["subtitle"])}</span></p>
221
212
  EOT
222
213
  end
223
214
 
224
215
  if @producer.params["date"] || @producer.params["history"]
225
- s << %Q[ <div class="pubhistory">\n]
216
+ @body << %Q[ <div class="pubhistory">\n]
226
217
  if @producer.params["history"]
227
218
  @producer.params["history"].each_with_index do |items, edit|
228
219
  items.each_with_index do |item, rev|
229
220
  editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
230
221
  revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
231
222
  if item =~ /\A\d+\-\d+\-\d+\Z/
232
- s << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
223
+ @body << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
233
224
  else
234
225
  # custom date with string
235
226
  item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
236
- s << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
227
+ @body << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
237
228
  end
238
229
  end
239
230
  end
240
231
  end
241
232
  else
242
- s << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
233
+ @body << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
243
234
  end
244
- s << %Q[ </div>\n]
235
+ @body << %Q[ </div>\n]
245
236
  end
246
237
 
247
- s << %Q[ <table class="colophon">\n]
248
- s << %Q[ <tr><th>#{@producer.res.v("aut")}</th><td>#{CGI.escapeHTML(@producer.params["aut"].join(", "))}</td></tr>\n] unless @producer.params["aut"].nil?
249
- s << %Q[ <tr><th>#{@producer.res.v("csl")}</th><td>#{CGI.escapeHTML(@producer.params["csl"].join(", "))}</td></tr>\n] unless @producer.params["csl"].nil?
250
- s << %Q[ <tr><th>#{@producer.res.v("trl")}</th><td>#{CGI.escapeHTML(@producer.params["trl"].join(", "))}</td></tr>\n] unless @producer.params["trl"].nil?
251
- s << %Q[ <tr><th>#{@producer.res.v("dsr")}</th><td>#{CGI.escapeHTML(@producer.params["dsr"].join(", "))}</td></tr>\n] unless @producer.params["dsr"].nil?
252
- s << %Q[ <tr><th>#{@producer.res.v("ill")}</th><td>#{CGI.escapeHTML(@producer.params["ill"].join(", "))}</td></tr>\n] unless @producer.params["ill"].nil?
253
- s << %Q[ <tr><th>#{@producer.res.v("edt")}</th><td>#{CGI.escapeHTML(@producer.params["edt"].join(", "))}</td></tr>\n] unless @producer.params["edt"].nil?
254
- s << %Q[ <tr><th>#{@producer.res.v("pbl")}</th><td>#{CGI.escapeHTML(@producer.params["pbl"].join(", "))}</td></tr>\n] unless @producer.params["pbl"].nil?
255
- s << %Q[ <tr><th>#{@producer.res.v("prt")}</th><td>#{CGI.escapeHTML(@producer.params["prt"].join(", "))}</td></tr>\n] unless @producer.params["prt"].nil?
256
- s << %Q[ <tr><th>#{@producer.res.v("pht")}</th><td>#{CGI.escapeHTML(@producer.params["pht"].join(", "))}</td></tr>\n] unless @producer.params["pht"].nil?
238
+ @body << %Q[ <table class="colophon">\n]
239
+ @body << %w[aut csl trl dsr ill edt pbl prt pht].map{ |role|
240
+ if @producer.params[role]
241
+ %Q[ <tr><th>#{@producer.res.v(role)}</th><td>#{CGI.escapeHTML(@producer.params[role].join(", "))}</td></tr>\n]
242
+ else
243
+ ""
244
+ end
245
+ }.join("")
246
+
257
247
  if @producer.params["isbn"].to_s =~ /\A\d{10}\Z/ || @producer.params["isbn"].to_s =~ /\A\d{13}\Z/
258
248
  isbn = nil
259
249
  str = @producer.params["isbn"].to_s
@@ -262,21 +252,23 @@ EOT
262
252
  else
263
253
  isbn = "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}"
264
254
  end
265
- s << %Q[ <tr><th>ISBN</th><td>#{isbn}</td></tr>\n]
255
+ @body << %Q[ <tr><th>ISBN</th><td>#{isbn}</td></tr>\n]
266
256
  end
267
- s << <<EOT
268
- </table>
269
- EOT
257
+ @body << %Q[ </table>\n]
270
258
  if !@producer.params["rights"].nil? && @producer.params["rights"].size > 0
271
- s << %Q[ <p class="copyright">#{@producer.params["rights"].join("<br />")}</p>]
259
+ @body << %Q[ <p class="copyright">#{@producer.params["rights"].join("<br />")}</p>]
272
260
  end
261
+ @body << %Q[ </div>\n]
273
262
 
274
- s << <<EOT
275
- </div>
276
- </body>
277
- </html>
278
- EOT
279
- s
263
+ @language = @producer.params['language']
264
+ @stylesheets = @producer.params["stylesheet"]
265
+ if @producer.params["htmlversion"].to_i == 5
266
+ tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
267
+ else
268
+ tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
269
+ end
270
+ tmpl = ReVIEW::Template.load(tmplfile)
271
+ tmpl.result(binding)
280
272
  end
281
273
 
282
274
  def date_to_s(date)
@@ -287,25 +279,24 @@ EOT
287
279
 
288
280
  # Return own toc content.
289
281
  def mytoc
290
- s = common_header
291
- s << <<EOT
292
- <title>#{@producer.res.v("toctitle")}</title>
293
- </head>
294
- <body>
295
- <h1 class="toc-title">#{@producer.res.v("toctitle")}</h1>
296
- EOT
282
+ @title = @producer.res.v("toctitle")
297
283
 
284
+ @body = %Q[ <h1 class="toc-title">#{@producer.res.v("toctitle")}</h1>\n]
298
285
  if @producer.params["epubmaker"]["flattoc"].nil?
299
- s << hierarchy_ncx("ul")
286
+ @body << hierarchy_ncx("ul")
300
287
  else
301
- s << flat_ncx("ul", @producer.params["epubmaker"]["flattocindent"])
288
+ @body << flat_ncx("ul", @producer.params["epubmaker"]["flattocindent"])
302
289
  end
303
290
 
304
- s << <<EOT
305
- </body>
306
- </html>
307
- EOT
308
- s
291
+ @language = @producer.params['language']
292
+ @stylesheets = @producer.params["stylesheet"]
293
+ if @producer.params["htmlversion"].to_i == 5
294
+ tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
295
+ else
296
+ tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
297
+ end
298
+ tmpl = ReVIEW::Template.load(tmplfile)
299
+ tmpl.result(binding)
309
300
  end
310
301
 
311
302
  def hierarchy_ncx(type)
@@ -394,7 +385,7 @@ EOT
394
385
  File.open("#{tmpdir}/META-INF/container.xml", "w") {|f| @producer.container(f) }
395
386
 
396
387
  FileUtils.mkdir_p("#{tmpdir}/OEBPS")
397
- File.open("#{tmpdir}/OEBPS/#{@producer.params["bookname"]}.opf", "w") {|f| @producer.opf(f) }
388
+ File.open(File.join(tmpdir, opf_path), "w") {|f| @producer.opf(f) }
398
389
 
399
390
  if File.exist?("#{basedir}/#{@producer.params["cover"]}")
400
391
  FileUtils.cp("#{basedir}/#{@producer.params["cover"]}", "#{tmpdir}/OEBPS")
@@ -417,21 +408,13 @@ EOT
417
408
  end
418
409
 
419
410
  def legacy_cover_and_title_file(loadfile, writefile)
420
- s = common_header
421
- s << <<EOT
422
- <title>#{@producer.params["booktitle"]}</title>
423
- </head>
424
- <body>
425
- EOT
411
+ @title = @producer.params["booktitle"]
412
+ s = ""
426
413
  File.open(loadfile) do |f|
427
414
  f.each_line do |l|
428
415
  s << l
429
416
  end
430
417
  end
431
- s << <<EOT
432
- </body>
433
- </html>
434
- EOT
435
418
 
436
419
  File.open(writefile, "w") do |f|
437
420
  f.puts s
@@ -23,24 +23,14 @@ module EPUBMaker
23
23
 
24
24
  # Return opf file content.
25
25
  def opf
26
- s = <<EOT
27
- <?xml version="1.0" encoding="UTF-8"?>
28
- <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
29
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
30
- EOT
31
-
32
- s << opf_metainfo
33
- s << opf_coverimage
34
-
35
- s << %Q[ </metadata>\n]
36
-
37
- s << opf_manifest
38
- s << opf_tocx
39
- s << opf_guide
40
-
41
- s << %Q[</package>\n]
42
-
43
- s
26
+ @opf_metainfo = opf_metainfo
27
+ @opf_coverimage = opf_coverimage
28
+ @opf_manifest = opf_manifest
29
+ @opf_toc = opf_tocx
30
+
31
+ tmplfile = File.expand_path('./opf/epubv2.opf.erb', ReVIEW::Template::TEMPLATE_DIR)
32
+ tmpl = ReVIEW::Template.load(tmplfile)
33
+ return tmpl.result(binding)
44
34
  end
45
35
 
46
36
  def opf_metainfo
@@ -121,39 +111,15 @@ EOT
121
111
  s
122
112
  end
123
113
 
124
- def opf_guide
125
- s = ""
126
- s << %Q[ <guide>\n]
127
- s << %Q[ <reference type="cover" title="#{@producer.res.v("covertitle")}" href="#{@producer.params["cover"]}"/>\n]
128
- s << %Q[ <reference type="title-page" title="#{@producer.res.v("titlepagetitle")}" href="titlepage.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["titlepage"].nil?
129
- s << %Q[ <reference type="toc" title="#{@producer.res.v("toctitle")}" href="#{@producer.params["bookname"]}-toc.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["mytoc"].nil?
130
- s << %Q[ <reference type="colophon" title="#{@producer.res.v("colophontitle")}" href="colophon.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["colophon"].nil?
131
- s << %Q[ </guide>\n]
132
- s
133
- end
134
-
135
114
  # Return ncx content. +indentarray+ has prefix marks for each level.
136
115
  def ncx(indentarray)
137
- s = <<EOT
138
- <?xml version="1.0" encoding="UTF-8"?>
139
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
140
- <head>
141
- <meta name="dtb:depth" content="1"/>
142
- <meta name="dtb:totalPageCount" content="0"/>
143
- <meta name="dtb:maxPageNumber" content="0"/>
144
- EOT
145
- s << ncx_isbn
116
+ @ncx_isbn = ncx_isbn
117
+ @ncx_doctitle = ncx_doctitle
118
+ @ncx_navmap = ncx_navmap(indentarray)
146
119
 
147
- s << <<EOT
148
- </head>
149
- EOT
150
- s << ncx_doctitle
151
- s << ncx_navmap(indentarray)
152
-
153
- s << <<EOT
154
- </ncx>
155
- EOT
156
- s
120
+ tmplfile = File.expand_path('./ncx/epubv2.ncx.erb', ReVIEW::Template::TEMPLATE_DIR)
121
+ tmpl = ReVIEW::Template.load(tmplfile)
122
+ return tmpl.result(binding)
157
123
  end
158
124
 
159
125
  # Produce EPUB file +epubfile+.
@@ -169,24 +135,5 @@ EOT
169
135
  export_zip(tmpdir, epubfile)
170
136
  end
171
137
 
172
- private
173
-
174
- # Return common XHTML headder
175
- def common_header
176
- s =<<EOT
177
- <?xml version="1.0" encoding="UTF-8"?>
178
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
179
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{@producer.params["language"]}">
180
- <head>
181
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
182
- <meta http-equiv="Content-Style-Type" content="text/css"/>
183
- <meta name="generator" content="Re:VIEW"/>
184
- EOT
185
-
186
- @producer.params["stylesheet"].each do |file|
187
- s << %Q[ <link rel="stylesheet" type="text/css" href="#{file}"/>\n]
188
- end
189
- s
190
- end
191
138
  end
192
139
  end
@@ -22,23 +22,13 @@ module EPUBMaker
22
22
 
23
23
  # Return opf file content.
24
24
  def opf
25
- s = <<EOT
26
- <?xml version="1.0" encoding="UTF-8"?>
27
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="#{@producer.params["language"]}">
28
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
29
- EOT
30
-
31
- s << opf_metainfo
32
-
33
- s << %Q[ </metadata>\n]
34
-
35
- s << opf_manifest
36
- s << opf_tocx
37
- s << opf_guide # same as ePUB2
25
+ @opf_metainfo = opf_metainfo
26
+ @opf_manifest = opf_manifest
27
+ @opf_toc = opf_tocx
38
28
 
39
- s << %Q[</package>\n]
40
-
41
- s
29
+ tmplfile = File.expand_path('./opf/epubv3.opf.erb', ReVIEW::Template::TEMPLATE_DIR)
30
+ tmpl = ReVIEW::Template.load(tmplfile)
31
+ return tmpl.result(binding)
42
32
  end
43
33
 
44
34
  def opf_metainfo
@@ -155,7 +145,11 @@ EOT
155
145
  end
156
146
 
157
147
  s = ""
158
- s << %Q[ <spine>\n]
148
+ if @producer.params["direction"]
149
+ s << %Q[ <spine page-progression-direction="#{@producer.params["direction"]}">\n]
150
+ else
151
+ s << %Q[ <spine>\n]
152
+ end
159
153
  s << %Q[ <itemref idref="#{@producer.params["bookname"]}" linear="#{cover_linear}"/>\n]
160
154
  s << %Q[ <itemref idref="#{@producer.params["bookname"]}-toc.#{@producer.params["htmlext"]}" />\n] if @producer.params["toc"]
161
155
 
@@ -168,38 +162,25 @@ EOT
168
162
  s
169
163
  end
170
164
 
171
- def opf_guide
172
- s = ""
173
- s << %Q[ <guide>\n]
174
- s << %Q[ <reference type="cover" title="#{@producer.res.v("covertitle")}" href="#{@producer.params["cover"]}"/>\n]
175
- s << %Q[ <reference type="title-page" title="#{@producer.res.v("titlepagetitle")}" href="titlepage.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["titlepage"].nil?
176
- s << %Q[ <reference type="toc" title="#{@producer.res.v("toctitle")}" href="#{@producer.params["bookname"]}-toc.#{@producer.params["htmlext"]}"/>\n]
177
- s << %Q[ <reference type="colophon" title="#{@producer.res.v("colophontitle")}" href="colophon.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["colophon"].nil?
178
- s << %Q[ </guide>\n]
179
- s
180
- end
181
-
182
165
  def ncx(indentarray)
183
- s = common_header
184
- s << <<EOT
185
- <title>#{@producer.res.v("toctitle")}</title>
186
- </head>
187
- <body>
188
- <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
189
- <h1 class="toc-title">#{@producer.res.v("toctitle")}</h1>
190
- EOT
191
-
192
166
  if @producer.params["epubmaker"]["flattoc"].nil?
193
- s << hierarchy_ncx("ol")
167
+ ncx_main = hierarchy_ncx("ol")
194
168
  else
195
- s << flat_ncx("ol", @producer.params["epubmaker"]["flattocindent"])
169
+ ncx_main = flat_ncx("ol", @producer.params["epubmaker"]["flattocindent"])
196
170
  end
197
- s << <<EOT
198
- </nav>
199
- </body>
200
- </html>
171
+
172
+ @body = <<EOT
173
+ <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
174
+ <h1 class="toc-title">#{@producer.res.v("toctitle")}</h1>
175
+ #{ncx_main} </nav>
201
176
  EOT
202
- s
177
+
178
+ @title = @producer.res.v("toctitle")
179
+ @language = @producer.params['language']
180
+ @stylesheets = @producer.params["stylesheet"]
181
+ tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
182
+ tmpl = ReVIEW::Template.load(tmplfile)
183
+ return tmpl.result(binding)
203
184
  end
204
185
 
205
186
  # Produce EPUB file +epubfile+.
@@ -237,20 +218,5 @@ EOT
237
218
  s
238
219
  end
239
220
 
240
- def common_header
241
- s =<<EOT
242
- <?xml version="1.0" encoding="UTF-8"?>
243
- <!DOCTYPE html>
244
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{@producer.params["language"]}">
245
- <head>
246
- <meta charset="UTF-8" />
247
- <meta name="generator" content="Re:VIEW" />
248
- EOT
249
-
250
- @producer.params["stylesheet"].each do |file|
251
- s << %Q[ <link rel="stylesheet" type="text/css" href="#{file}"/>\n]
252
- end
253
- s
254
- end
255
221
  end
256
222
  end