review 1.7.2 → 2.0.0.beta1

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -43
  3. data/.travis.yml +0 -9
  4. data/ChangeLog +0 -16
  5. data/Gemfile +1 -0
  6. data/README.rdoc +1 -1
  7. data/Rakefile +12 -1
  8. data/bin/review-check +21 -8
  9. data/bin/review-compile +15 -9
  10. data/bin/review-epubmaker-legacy +6 -6
  11. data/bin/review-index +13 -2
  12. data/bin/review-init +18 -12
  13. data/bin/review-preproc +14 -1
  14. data/bin/review-validate +1 -1
  15. data/bin/review-vol +13 -1
  16. data/doc/quickstart.ja.md +1 -1
  17. data/doc/quickstart.md +1 -1
  18. data/lib/epubmaker/content.rb +3 -3
  19. data/lib/epubmaker/epubcommon.rb +108 -91
  20. data/lib/epubmaker/epubv2.rb +67 -14
  21. data/lib/epubmaker/epubv3.rb +59 -25
  22. data/lib/epubmaker/producer.rb +1 -13
  23. data/lib/lineinput.rb +0 -48
  24. data/lib/review/book/base.rb +4 -12
  25. data/lib/review/book/compilable.rb +3 -1
  26. data/lib/review/book/index.rb +4 -4
  27. data/lib/review/builder.rb +54 -47
  28. data/lib/review/compiler.rb +4662 -326
  29. data/lib/review/compiler/literals_1_8.kpeg +19 -0
  30. data/lib/review/compiler/literals_1_8.rb +432 -0
  31. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  32. data/lib/review/compiler/literals_1_9.rb +435 -0
  33. data/lib/review/configure.rb +8 -20
  34. data/lib/review/epubbuilder.rb +1 -1
  35. data/lib/review/epubmaker.rb +122 -52
  36. data/lib/review/ewbbuilder.rb +4 -4
  37. data/lib/review/exception.rb +1 -1
  38. data/lib/review/extentions.rb +1 -0
  39. data/lib/review/extentions/array.rb +25 -0
  40. data/lib/review/htmlbuilder.rb +286 -275
  41. data/lib/review/htmllayout.rb +0 -2
  42. data/lib/review/htmlutils.rb +4 -4
  43. data/lib/review/i18n.rb +2 -6
  44. data/lib/review/i18n.yml +1 -1
  45. data/lib/review/idgxmlbuilder.rb +239 -204
  46. data/lib/review/inaobuilder.rb +75 -73
  47. data/lib/review/latexbuilder.rb +265 -219
  48. data/lib/review/latexutils.rb +6 -6
  49. data/lib/review/layout.tex.erb +1 -1
  50. data/lib/review/location.rb +24 -0
  51. data/lib/review/markdownbuilder.rb +124 -79
  52. data/lib/review/node.rb +267 -0
  53. data/lib/review/pdfmaker.rb +92 -92
  54. data/lib/review/preprocessor.rb +51 -14
  55. data/lib/review/review.kpeg +724 -0
  56. data/lib/review/textbuilder.rb +1 -1
  57. data/lib/review/textutils.rb +24 -18
  58. data/lib/review/tocparser.rb +3 -3
  59. data/lib/review/tocprinter.rb +31 -8
  60. data/lib/review/topbuilder.rb +119 -111
  61. data/lib/review/unfold.rb +2 -2
  62. data/lib/review/version.rb +1 -1
  63. data/review.gemspec +2 -2
  64. data/rubocop-todo.yml +456 -0
  65. data/test/assets/test_template.tex +1 -1
  66. data/test/sample-book/src/config.yml +0 -1
  67. data/test/test.re +1 -1
  68. data/test/test_book.rb +4 -4
  69. data/test/test_book_chapter.rb +70 -0
  70. data/test/test_book_part.rb +1 -1
  71. data/test/test_builder.rb +6 -28
  72. data/test/test_compiler.rb +59 -14
  73. data/test/test_helper.rb +47 -4
  74. data/test/test_htmlbuilder.rb +104 -73
  75. data/test/test_i18n.rb +5 -3
  76. data/test/test_idgxmlbuilder.rb +5 -2
  77. data/test/test_inaobuilder.rb +4 -2
  78. data/test/test_latexbuilder.rb +18 -37
  79. data/test/test_lineinput.rb +25 -4
  80. data/test/test_markdownbuilder.rb +4 -22
  81. data/test/test_pdfmaker.rb +12 -11
  82. data/test/test_textutils.rb +0 -36
  83. data/test/test_topbuilder.rb +2 -0
  84. metadata +14 -28
  85. data/.rubocop_todo.yml +0 -605
  86. data/Dockerfile +0 -22
  87. data/doc/NEWS.ja.md +0 -362
  88. data/doc/NEWS.md +0 -366
  89. data/lib/review/htmltoc.rb +0 -45
  90. data/lib/review/template.rb +0 -21
  91. data/templates/html/layout-html5.html.erb +0 -17
  92. data/templates/html/layout-xhtml1.html.erb +0 -20
  93. data/templates/ncx/epubv2.ncx.erb +0 -11
  94. data/templates/opf/epubv2.opf.erb +0 -21
  95. data/templates/opf/epubv3.opf.erb +0 -18
  96. data/templates/xml/container.xml.erb +0 -6
  97. data/test/assets/test.xml.erb +0 -3
  98. data/test/sample-book/src/config-epub2.yml +0 -186
  99. data/test/test_configure.rb +0 -50
  100. data/test/test_htmltoc.rb +0 -32
  101. data/test/test_template.rb +0 -26
data/bin/review-vol CHANGED
@@ -21,7 +21,13 @@ require 'optparse'
21
21
  include ReVIEW::TextUtils
22
22
 
23
23
  def main
24
+ $KCODE = 'UTF-8' unless defined?(Encoding)
25
+
24
26
  @config = ReVIEW::Configure.values
27
+ @config.merge!({
28
+ "inencoding" => "UTF-8",
29
+ "outencoding" => "UTF-8"
30
+ })
25
31
 
26
32
  part_sensitive = false
27
33
  basedir = nil
@@ -34,6 +40,12 @@ def main
34
40
  opts.on('-P', '--part-sensitive', 'Prints volume of each parts.') {
35
41
  part_sensitive = true
36
42
  }
43
+ opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc|
44
+ @config["inencoding"] = enc
45
+ }
46
+ opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc|
47
+ @config["outencoding"] = enc
48
+ }
37
49
  opts.on('--directory=DIR', 'Compile all chapters in DIR.') {|path|
38
50
  basedir = path
39
51
  }
@@ -83,7 +95,7 @@ end
83
95
 
84
96
  def print_chapter_volume(chap)
85
97
  vol = chap.volume
86
- title = chap.title
98
+ title = convert_outencoding(chap.title, @config["outencoding"])
87
99
  printf "%s %3dKB %6dC %5dL %3dP %s %-s\n",
88
100
  chapnumstr(chap.number), vol.kbytes, vol.chars, vol.lines, vol.page,
89
101
  "#{chap.name} ".ljust(25, '.'), title
data/doc/quickstart.ja.md CHANGED
@@ -161,7 +161,7 @@ sample.re を HTML に変換すると、次のようになります。
161
161
  </html>
162
162
  ```
163
163
 
164
- Re:VIEW フォーマットについての詳細は、 [format.ja.md](https://github.com/kmuto/review/blob/master/doc/format.ja.md) を参照してください。
164
+ Re:VIEW フォーマットについての詳細は、 [format.rdoc](https://github.com/kmuto/review/blob/master/doc/format.rdoc) を参照してください。
165
165
 
166
166
  review-compile を含め、ほとんどのコマンドは `--help` オプションを付けるとオプションについてのヘルプが表示されます。`review-compile` には多数のオプションがあるので確認してください。
167
167
 
data/doc/quickstart.md CHANGED
@@ -191,7 +191,7 @@ You can get HTML file as follows:
191
191
  </html>
192
192
  ```
193
193
 
194
- For more information about Re:VIEW format, see [format.md](https://github.com/kmuto/review/blob/master/doc/format.md).
194
+ For more information about Re:VIEW format, see [format.rdoc](https://github.com/kmuto/review/blob/master/doc/format.rdoc).
195
195
 
196
196
  review-compile and other commands in Re:VIEW has `--help` option to output help. `review-compile` has many options, so you may see them.
197
197
 
@@ -60,12 +60,12 @@ module EPUBMaker
60
60
  complement
61
61
  end
62
62
 
63
- def ==(other)
64
- if self.class != other.class
63
+ def ==(obj)
64
+ if self.class != obj.class
65
65
  return false
66
66
  end
67
67
  [self.id, self.file, self.media, self.title, self.level, self.notoc, self.chaptype, self.properties] ==
68
- [other.id, other.file, other.media, other.title, other.level, other.notoc, other.chaptype, other.properties]
68
+ [obj.id, obj.file, obj.media, obj.title, obj.level, obj.notoc, obj.chaptype, obj.properties]
69
69
  end
70
70
 
71
71
  private
@@ -28,10 +28,6 @@ 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
-
35
31
  def opf_coverimage
36
32
  s = ""
37
33
  if @producer.params["coverimage"]
@@ -116,53 +112,66 @@ EOT
116
112
 
117
113
  # Return container content.
118
114
  def container
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)
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
123
124
  end
124
125
 
125
126
  # Return cover content.
126
127
  def cover(type=nil)
127
- @body_ext = type.nil? ? "" : " epub:type=\"#{type}\""
128
+ bodyext = type.nil? ? "" : " epub:type=\"#{type}\""
128
129
 
129
- if @producer.params["coverimage"]
130
- file = @producer.coverimage
131
- if !file
132
- raise "coverimage #{@producer.params["coverimage"]} not found. Abort."
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
133
147
  end
134
- @body = <<-EOT
148
+ raise "coverimage #{@producer.params["coverimage"]} not found. Abort." if file.nil?
149
+ s << <<EOT
135
150
  <div id="cover-image" class="cover-image">
136
151
  <img src="#{file}" alt="#{CGI.escapeHTML(@producer.params["title"])}" class="max"/>
137
152
  </div>
138
- EOT
139
- else
140
- @body = <<-EOT
141
- <h1 class="cover-title">#{CGI.escapeHTML(@producer.params["title"])}</h1>
142
- EOT
153
+ EOT
143
154
  end
144
155
 
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)
156
+ s << <<EOT
157
+ </body>
158
+ </html>
159
+ EOT
160
+ s
155
161
  end
156
162
 
157
163
  # Return title (copying) content.
158
164
  def titlepage
159
- @title = @producer.params["title"]
160
-
161
- @body = <<EOT
162
- <h1 class="tp-title">#{CGI.escapeHTML(@title)}</h1>
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>
163
171
  EOT
172
+
164
173
  if @producer.params["aut"]
165
- @body << <<EOT
174
+ s << <<EOT
166
175
  <p>
167
176
  <br />
168
177
  <br />
@@ -173,7 +182,7 @@ EOT
173
182
 
174
183
  publisher = @producer.params["pbl"] || @producer.params["prt"] # XXX Backward Compatiblity
175
184
  if publisher
176
- @body << <<EOT
185
+ s << <<EOT
177
186
  <p>
178
187
  <br />
179
188
  <br />
@@ -184,66 +193,67 @@ EOT
184
193
  EOT
185
194
  end
186
195
 
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)
196
+ s << <<EOT
197
+ </body>
198
+ </html>
199
+ EOT
200
+
201
+ s
196
202
  end
197
203
 
198
204
  # Return colophon content.
199
205
  def colophon
200
- @title = @producer.res.v("colophontitle")
201
- @body = <<EOT
206
+ s = common_header
207
+ s << <<EOT
208
+ <title>#{@producer.res.v("colophontitle")}</title>
209
+ </head>
210
+ <body>
202
211
  <div class="colophon">
203
212
  EOT
204
213
 
205
214
  if @producer.params["subtitle"].nil?
206
- @body << <<EOT
215
+ s << <<EOT
207
216
  <p class="title">#{CGI.escapeHTML(@producer.params["title"])}</p>
208
217
  EOT
209
218
  else
210
- @body << <<EOT
219
+ s << <<EOT
211
220
  <p class="title">#{CGI.escapeHTML(@producer.params["title"])}<br /><span class="subtitle">#{CGI.escapeHTML(@producer.params["subtitle"])}</span></p>
212
221
  EOT
213
222
  end
214
223
 
215
224
  if @producer.params["date"] || @producer.params["history"]
216
- @body << %Q[ <div class="pubhistory">\n]
225
+ s << %Q[ <div class="pubhistory">\n]
217
226
  if @producer.params["history"]
218
227
  @producer.params["history"].each_with_index do |items, edit|
219
228
  items.each_with_index do |item, rev|
220
229
  editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
221
230
  revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
222
231
  if item =~ /\A\d+\-\d+\-\d+\Z/
223
- @body << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
232
+ s << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
224
233
  else
225
234
  # custom date with string
226
235
  item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
227
- @body << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
236
+ s << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
228
237
  end
229
238
  end
230
239
  end
231
240
  end
232
241
  else
233
- @body << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
242
+ s << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
234
243
  end
235
- @body << %Q[ </div>\n]
244
+ s << %Q[ </div>\n]
236
245
  end
237
246
 
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
-
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?
247
257
  if @producer.params["isbn"].to_s =~ /\A\d{10}\Z/ || @producer.params["isbn"].to_s =~ /\A\d{13}\Z/
248
258
  isbn = nil
249
259
  str = @producer.params["isbn"].to_s
@@ -252,23 +262,21 @@ EOT
252
262
  else
253
263
  isbn = "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}"
254
264
  end
255
- @body << %Q[ <tr><th>ISBN</th><td>#{isbn}</td></tr>\n]
265
+ s << %Q[ <tr><th>ISBN</th><td>#{isbn}</td></tr>\n]
256
266
  end
257
- @body << %Q[ </table>\n]
267
+ s << <<EOT
268
+ </table>
269
+ EOT
258
270
  if !@producer.params["rights"].nil? && @producer.params["rights"].size > 0
259
- @body << %Q[ <p class="copyright">#{@producer.params["rights"].join("<br />")}</p>]
271
+ s << %Q[ <p class="copyright">#{@producer.params["rights"].join("<br />")}</p>]
260
272
  end
261
- @body << %Q[ </div>\n]
262
273
 
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)
274
+ s << <<EOT
275
+ </div>
276
+ </body>
277
+ </html>
278
+ EOT
279
+ s
272
280
  end
273
281
 
274
282
  def date_to_s(date)
@@ -279,24 +287,25 @@ EOT
279
287
 
280
288
  # Return own toc content.
281
289
  def mytoc
282
- @title = @producer.res.v("toctitle")
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
283
297
 
284
- @body = %Q[ <h1 class="toc-title">#{@producer.res.v("toctitle")}</h1>\n]
285
298
  if @producer.params["epubmaker"]["flattoc"].nil?
286
- @body << hierarchy_ncx("ul")
299
+ s << hierarchy_ncx("ul")
287
300
  else
288
- @body << flat_ncx("ul", @producer.params["epubmaker"]["flattocindent"])
301
+ s << flat_ncx("ul", @producer.params["epubmaker"]["flattocindent"])
289
302
  end
290
303
 
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)
304
+ s << <<EOT
305
+ </body>
306
+ </html>
307
+ EOT
308
+ s
300
309
  end
301
310
 
302
311
  def hierarchy_ncx(type)
@@ -385,7 +394,7 @@ EOT
385
394
  File.open("#{tmpdir}/META-INF/container.xml", "w") {|f| @producer.container(f) }
386
395
 
387
396
  FileUtils.mkdir_p("#{tmpdir}/OEBPS")
388
- File.open(File.join(tmpdir, opf_path), "w") {|f| @producer.opf(f) }
397
+ File.open("#{tmpdir}/OEBPS/#{@producer.params["bookname"]}.opf", "w") {|f| @producer.opf(f) }
389
398
 
390
399
  if File.exist?("#{basedir}/#{@producer.params["cover"]}")
391
400
  FileUtils.cp("#{basedir}/#{@producer.params["cover"]}", "#{tmpdir}/OEBPS")
@@ -408,13 +417,21 @@ EOT
408
417
  end
409
418
 
410
419
  def legacy_cover_and_title_file(loadfile, writefile)
411
- @title = @producer.params["booktitle"]
412
- s = ""
420
+ s = common_header
421
+ s << <<EOT
422
+ <title>#{@producer.params["booktitle"]}</title>
423
+ </head>
424
+ <body>
425
+ EOT
413
426
  File.open(loadfile) do |f|
414
427
  f.each_line do |l|
415
428
  s << l
416
429
  end
417
430
  end
431
+ s << <<EOT
432
+ </body>
433
+ </html>
434
+ EOT
418
435
 
419
436
  File.open(writefile, "w") do |f|
420
437
  f.puts s
@@ -23,14 +23,24 @@ module EPUBMaker
23
23
 
24
24
  # Return opf file content.
25
25
  def opf
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)
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
34
44
  end
35
45
 
36
46
  def opf_metainfo
@@ -111,15 +121,39 @@ EOT
111
121
  s
112
122
  end
113
123
 
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
+
114
135
  # Return ncx content. +indentarray+ has prefix marks for each level.
115
136
  def ncx(indentarray)
116
- @ncx_isbn = ncx_isbn
117
- @ncx_doctitle = ncx_doctitle
118
- @ncx_navmap = ncx_navmap(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
119
146
 
120
- tmplfile = File.expand_path('./ncx/epubv2.ncx.erb', ReVIEW::Template::TEMPLATE_DIR)
121
- tmpl = ReVIEW::Template.load(tmplfile)
122
- return tmpl.result(binding)
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
123
157
  end
124
158
 
125
159
  # Produce EPUB file +epubfile+.
@@ -135,5 +169,24 @@ EOT
135
169
  export_zip(tmpdir, epubfile)
136
170
  end
137
171
 
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
138
191
  end
139
192
  end