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.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +90 -66
  3. data/.travis.yml +1 -1
  4. data/Gemfile +0 -1
  5. data/NEWS.ja.md +82 -0
  6. data/NEWS.md +83 -0
  7. data/README.md +5 -3
  8. data/Rakefile +8 -8
  9. data/bin/review +1 -5
  10. data/bin/review-catalog-converter +22 -27
  11. data/bin/review-check +36 -43
  12. data/bin/review-checkdep +10 -15
  13. data/bin/review-compile +37 -55
  14. data/bin/review-epubmaker +4 -5
  15. data/bin/review-index +21 -29
  16. data/bin/review-init +26 -37
  17. data/bin/review-pdfmaker +0 -2
  18. data/bin/review-preproc +25 -45
  19. data/bin/review-validate +19 -18
  20. data/bin/review-vol +15 -27
  21. data/doc/config.yml.sample +5 -2
  22. data/doc/format.ja.md +20 -1
  23. data/doc/format.md +21 -5
  24. data/doc/images/review-generate.png +0 -0
  25. data/lib/epubmaker.rb +1 -3
  26. data/lib/epubmaker/content.rb +24 -27
  27. data/lib/epubmaker/epubcommon.rb +135 -148
  28. data/lib/epubmaker/epubv2.rb +39 -46
  29. data/lib/epubmaker/epubv3.rb +93 -103
  30. data/lib/epubmaker/producer.rb +138 -151
  31. data/lib/epubmaker/zip_exporter.rb +21 -26
  32. data/lib/review/book.rb +3 -6
  33. data/lib/review/book/base.rb +78 -103
  34. data/lib/review/book/chapter.rb +36 -40
  35. data/lib/review/book/compilable.rb +28 -31
  36. data/lib/review/book/image_finder.rb +6 -13
  37. data/lib/review/book/index.rb +100 -121
  38. data/lib/review/book/page_metric.rb +2 -7
  39. data/lib/review/book/part.rb +18 -20
  40. data/lib/review/book/volume.rb +9 -13
  41. data/lib/review/builder.rb +81 -116
  42. data/lib/review/catalog.rb +15 -19
  43. data/lib/review/compiler.rb +64 -83
  44. data/lib/review/configure.rb +87 -97
  45. data/lib/review/converter.rb +2 -7
  46. data/lib/review/epubbuilder.rb +1 -3
  47. data/lib/review/epubmaker.rb +213 -205
  48. data/lib/review/exception.rb +2 -4
  49. data/lib/review/extentions.rb +0 -1
  50. data/lib/review/extentions/hash.rb +2 -2
  51. data/lib/review/extentions/string.rb +5 -30
  52. data/lib/review/htmlbuilder.rb +320 -375
  53. data/lib/review/htmltoc.rb +4 -7
  54. data/lib/review/htmlutils.rb +29 -32
  55. data/lib/review/i18n.rb +33 -44
  56. data/lib/review/i18n.yml +3 -3
  57. data/lib/review/idgxmlbuilder.rb +309 -345
  58. data/lib/review/latexbuilder.rb +175 -212
  59. data/lib/review/latexindex.rb +2 -8
  60. data/lib/review/latexutils.rb +33 -43
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/logger.rb +21 -0
  63. data/lib/review/makerhelper.rb +1 -4
  64. data/lib/review/markdownbuilder.rb +44 -53
  65. data/lib/review/md2inaobuilder.rb +6 -12
  66. data/lib/review/pdfmaker.rb +143 -173
  67. data/lib/review/preprocessor.rb +64 -101
  68. data/lib/review/rstbuilder.rb +126 -158
  69. data/lib/review/sec_counter.rb +18 -34
  70. data/lib/review/template.rb +4 -5
  71. data/lib/review/textbuilder.rb +2 -3
  72. data/lib/review/textutils.rb +7 -13
  73. data/lib/review/tocparser.rb +31 -56
  74. data/lib/review/tocprinter.rb +26 -52
  75. data/lib/review/topbuilder.rb +219 -247
  76. data/lib/review/unfold.rb +15 -24
  77. data/lib/review/version.rb +1 -1
  78. data/lib/review/webmaker.rb +75 -99
  79. data/lib/review/webtocprinter.rb +15 -20
  80. data/lib/review/yamlloader.rb +13 -15
  81. data/review.gemspec +20 -22
  82. data/templates/latex/layout.tex.erb +2 -2
  83. data/templates/opf/epubv2.opf.erb +7 -7
  84. data/templates/opf/epubv3.opf.erb +7 -7
  85. data/templates/web/html/layout-html5.html.erb +2 -2
  86. data/test/assets/black.eps +280 -0
  87. data/test/assets/fit.png +0 -0
  88. data/test/assets/large.gif +0 -0
  89. data/test/assets/large.jpg +0 -0
  90. data/test/assets/large.png +0 -0
  91. data/test/assets/large.svg +65 -0
  92. data/test/assets/test_template.tex +1 -1
  93. data/test/book_test_helper.rb +2 -2
  94. data/test/run_test.rb +4 -4
  95. data/test/sample-book/src/Rakefile +21 -22
  96. data/test/syntax-book/Gemfile +4 -0
  97. data/test/syntax-book/Rakefile +72 -0
  98. data/test/syntax-book/appA.re +22 -0
  99. data/test/syntax-book/bib.re +6 -0
  100. data/test/syntax-book/catalog.yml +15 -0
  101. data/test/syntax-book/ch01.re +136 -0
  102. data/test/syntax-book/ch02.re +351 -0
  103. data/test/syntax-book/ch03.re +82 -0
  104. data/test/syntax-book/config.yml +35 -0
  105. data/test/syntax-book/images/ball.png +0 -0
  106. data/test/syntax-book/images/cover.jpg +0 -0
  107. data/test/syntax-book/images/fractal.png +0 -0
  108. data/test/syntax-book/images/img3-1.png +0 -0
  109. data/test/syntax-book/images/inlineicon.jpg +0 -0
  110. data/test/syntax-book/images/logic.png +0 -0
  111. data/test/syntax-book/images/logic2.png +0 -0
  112. data/test/syntax-book/images/puzzle.jpg +0 -0
  113. data/test/syntax-book/images/table.jpg +0 -0
  114. data/test/syntax-book/part2.re +6 -0
  115. data/test/syntax-book/pre01.re +26 -0
  116. data/test/syntax-book/review-ext.rb +14 -0
  117. data/test/syntax-book/sty/jumoline.sty +310 -0
  118. data/test/syntax-book/sty/reviewmacro.sty +39 -0
  119. data/test/syntax-book/style.css +494 -0
  120. data/test/syntax-book/syntax.dic +2 -0
  121. data/test/test_book.rb +106 -111
  122. data/test/test_book_chapter.rb +21 -22
  123. data/test/test_book_part.rb +3 -5
  124. data/test/test_builder.rb +11 -22
  125. data/test/test_catalog.rb +17 -18
  126. data/test/test_catalog_converter_cmd.rb +5 -5
  127. data/test/test_compiler.rb +18 -16
  128. data/test/test_configure.rb +35 -38
  129. data/test/test_converter.rb +3 -4
  130. data/test/test_epub3maker.rb +136 -117
  131. data/test/test_epubmaker.rb +107 -114
  132. data/test/test_epubmaker_cmd.rb +2 -4
  133. data/test/test_extentions_hash.rb +32 -33
  134. data/test/test_helper.rb +9 -11
  135. data/test/test_htmlbuilder.rb +454 -420
  136. data/test/test_htmltoc.rb +8 -12
  137. data/test/test_htmlutils.rb +0 -2
  138. data/test/test_i18n.rb +159 -150
  139. data/test/test_idgxmlbuilder.rb +190 -197
  140. data/test/test_image_finder.rb +21 -22
  141. data/test/test_index.rb +24 -29
  142. data/test/test_latexbuilder.rb +274 -264
  143. data/test/test_lineinput.rb +7 -10
  144. data/test/test_location.rb +7 -7
  145. data/test/test_makerhelper.rb +13 -25
  146. data/test/test_markdownbuilder.rb +23 -26
  147. data/test/test_md2inaobuilder.rb +8 -11
  148. data/test/test_pdfmaker.rb +114 -123
  149. data/test/test_pdfmaker_cmd.rb +1 -3
  150. data/test/test_review_ext.rb +3 -5
  151. data/test/test_rstbuilder.rb +92 -97
  152. data/test/test_template.rb +3 -7
  153. data/test/test_textutils.rb +27 -27
  154. data/test/test_tocparser.rb +2 -2
  155. data/test/test_topbuilder.rb +98 -103
  156. data/test/test_webtocprinter.rb +5 -6
  157. data/test/test_yamlloader.rb +42 -42
  158. data/test/test_zip_exporter.rb +12 -18
  159. metadata +86 -9
  160. data/lib/review/ewbbuilder.rb +0 -382
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # = epubcommon.rb -- super class for EPUBv2 and EPUBv3
4
2
  #
5
3
  # Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
@@ -15,10 +13,9 @@ require 'review/template'
15
13
  require 'cgi'
16
14
 
17
15
  module EPUBMaker
18
-
19
16
  # EPUBCommon is the common class for EPUB producer.
20
17
  class EPUBCommon
21
- # Construct object with parameter hash +params+ and message resource hash +res+.
18
+ # Construct object with parameter hash +config+ and message resource hash +res+.
22
19
  def initialize(producer)
23
20
  @body_ext = ''
24
21
  @producer = producer
@@ -27,41 +24,41 @@ module EPUBMaker
27
24
 
28
25
  # Return mimetype content.
29
26
  def mimetype
30
- "application/epub+zip"
27
+ 'application/epub+zip'
31
28
  end
32
29
 
33
30
  def opf_path
34
- "OEBPS/#{@producer.params["bookname"]}.opf"
31
+ "OEBPS/#{@producer.config['bookname']}.opf"
35
32
  end
36
33
 
37
34
  def opf_coverimage
38
- s = ""
39
- if @producer.params["coverimage"]
35
+ s = ''
36
+ if @producer.config['coverimage']
40
37
  file = nil
41
38
  @producer.contents.each do |item|
42
- if item.media.start_with?('image') && item.file =~ /#{@producer.params["coverimage"]}\Z/
43
- s << %Q[ <meta name="cover" content="#{item.id}"/>\n]
44
- file = item.file
45
- break
46
- end
39
+ next if !item.media.start_with?('image') || item.file !~ /#{@producer.config["coverimage"]}\Z/
40
+
41
+ s << %Q( <meta name="cover" content="#{item.id}"/>\n)
42
+ file = item.file
43
+ break
47
44
  end
48
- raise "coverimage #{@producer.params["coverimage"]} not found. Abort." if file.nil?
45
+ raise "coverimage #{@producer.config['coverimage']} not found. Abort." if file.nil?
49
46
  end
50
47
  s
51
48
  end
52
49
 
53
50
  def ncx_isbn
54
- uid = @producer.params["isbn"] || @producer.params["urnid"]
55
- %Q[ <meta name="dtb:uid" content="#{uid}"/>\n]
51
+ uid = @producer.config['isbn'] || @producer.config['urnid']
52
+ %Q( <meta name="dtb:uid" content="#{uid}"/>\n)
56
53
  end
57
54
 
58
55
  def ncx_doctitle
59
56
  <<EOT
60
57
  <docTitle>
61
- <text>#{CGI.escapeHTML(@producer.params["title"])}</text>
58
+ <text>#{CGI.escapeHTML(@producer.config['title'])}</text>
62
59
  </docTitle>
63
60
  <docAuthor>
64
- <text>#{@producer.params["aut"].nil? ? "" : CGI.escapeHTML(join_with_separator(@producer.params["aut"], ReVIEW::I18n.t("names_splitter")))}</text>
61
+ <text>#{@producer.config['aut'].nil? ? '' : CGI.escapeHTML(join_with_separator(@producer.config['aut'], ReVIEW::I18n.t('names_splitter')))}</text>
65
62
  </docAuthor>
66
63
  EOT
67
64
  end
@@ -71,21 +68,21 @@ EOT
71
68
  <navMap>
72
69
  <navPoint id="top" playOrder="1">
73
70
  <navLabel>
74
- <text>#{CGI.escapeHTML(@producer.params["title"])}</text>
71
+ <text>#{CGI.escapeHTML(@producer.config['title'])}</text>
75
72
  </navLabel>
76
- <content src="#{@producer.params["cover"]}"/>
73
+ <content src="#{@producer.config['cover']}"/>
77
74
  </navPoint>
78
75
  EOT
79
76
 
80
77
  nav_count = 2
81
78
 
82
- unless @producer.params["mytoc"].nil?
79
+ unless @producer.config['mytoc'].nil?
83
80
  s << <<EOT
84
81
  <navPoint id="toc" playOrder="#{nav_count}">
85
82
  <navLabel>
86
- <text>#{CGI.escapeHTML(@producer.res.v("toctitle"))}</text>
83
+ <text>#{CGI.escapeHTML(@producer.res.v('toctitle'))}</text>
87
84
  </navLabel>
88
- <content src="#{@producer.params["bookname"]}-toc.#{@producer.params["htmlext"]}"/>
85
+ <content src="#{@producer.config['bookname']}-toc.#{@producer.config['htmlext']}"/>
89
86
  </navPoint>
90
87
  EOT
91
88
  nav_count += 1
@@ -93,7 +90,7 @@ EOT
93
90
 
94
91
  @producer.contents.each do |item|
95
92
  next if item.title.nil?
96
- indent = indentarray.nil? ? [""] : indentarray
93
+ indent = indentarray.nil? ? [''] : indentarray
97
94
  level = item.level.nil? ? 0 : (item.level - 1)
98
95
  level = indent.size - 1 if level >= indent.size
99
96
  s << <<EOT
@@ -122,38 +119,36 @@ EOT
122
119
  end
123
120
 
124
121
  # Return cover content.
125
- def cover(type=nil)
126
- @body_ext = type.nil? ? "" : " epub:type=\"#{type}\""
122
+ def cover(type = nil)
123
+ @body_ext = type.nil? ? '' : %Q( epub:type="#{type}")
127
124
 
128
- if @producer.params["coverimage"]
125
+ if @producer.config['coverimage']
129
126
  file = @producer.coverimage
130
- if !file
131
- raise "coverimage #{@producer.params["coverimage"]} not found. Abort."
132
- end
127
+ raise "coverimage #{@producer.config['coverimage']} not found. Abort." unless file
133
128
  @body = <<-EOT
134
129
  <div id="cover-image" class="cover-image">
135
- <img src="#{file}" alt="#{CGI.escapeHTML(@producer.params.name_of("title"))}" class="max"/>
130
+ <img src="#{file}" alt="#{CGI.escapeHTML(@producer.config.name_of('title'))}" class="max"/>
136
131
  </div>
137
132
  EOT
138
133
  else
139
134
  @body = <<-EOT
140
- <h1 class="cover-title">#{CGI.escapeHTML(@producer.params.name_of("title"))}</h1>
135
+ <h1 class="cover-title">#{CGI.escapeHTML(@producer.config.name_of('title'))}</h1>
141
136
  EOT
142
- if @producer.params["subtitle"]
137
+ if @producer.config['subtitle']
143
138
  @body << <<-EOT
144
- <h2 class="cover-subtitle">#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}</h2>
139
+ <h2 class="cover-subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</h2>
145
140
  EOT
146
141
  end
147
142
  end
148
143
 
149
- @title = CGI.escapeHTML(@producer.params.name_of("title"))
150
- @language = @producer.params['language']
151
- @stylesheets = @producer.params["stylesheet"]
152
- if @producer.params["htmlversion"].to_i == 5
153
- tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
154
- else
155
- tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
156
- end
144
+ @title = CGI.escapeHTML(@producer.config.name_of('title'))
145
+ @language = @producer.config['language']
146
+ @stylesheets = @producer.config['stylesheet']
147
+ tmplfile = if @producer.config['htmlversion'].to_i == 5
148
+ File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
149
+ else
150
+ File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
151
+ end
157
152
  tmpl = ReVIEW::Template.load(tmplfile)
158
153
  tmpl.result(binding)
159
154
  end
@@ -162,29 +157,29 @@ EOT
162
157
  # NOTE: this method is not used yet.
163
158
  # see lib/review/epubmaker.rb#build_titlepage
164
159
  def titlepage
165
- @title = CGI.escapeHTML(@producer.params.name_of("title"))
160
+ @title = CGI.escapeHTML(@producer.config.name_of('title'))
166
161
 
167
162
  @body = <<EOT
168
163
  <h1 class="tp-title">#{@title}</h1>
169
164
  EOT
170
165
 
171
- if @producer.params["subtitle"]
166
+ if @producer.config['subtitle']
172
167
  @body << <<EOT
173
- <h2 class="tp-subtitle">#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}</h2>
168
+ <h2 class="tp-subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</h2>
174
169
  EOT
175
170
  end
176
171
 
177
- if @producer.params["aut"]
172
+ if @producer.config['aut']
178
173
  @body << <<EOT
179
174
  <p>
180
175
  <br />
181
176
  <br />
182
177
  </p>
183
- <h2 class="tp-author">#{CGI.escapeHTML(join_with_separator(@producer.params.names_of("aut"), ReVIEW::I18n.t("names_splitter")))}</h2>
178
+ <h2 class="tp-author">#{CGI.escapeHTML(join_with_separator(@producer.config.names_of('aut'), ReVIEW::I18n.t('names_splitter')))}</h2>
184
179
  EOT
185
180
  end
186
181
 
187
- publisher = @producer.params.names_of("pbl")
182
+ publisher = @producer.config.names_of('pbl')
188
183
  if publisher
189
184
  @body << <<EOT
190
185
  <p>
@@ -193,123 +188,117 @@ EOT
193
188
  <br />
194
189
  <br />
195
190
  </p>
196
- <h3 class="tp-publisher">#{CGI.escapeHTML(join_with_separator(publisher, ReVIEW::I18n.t("names_splitter")))}</h3>
191
+ <h3 class="tp-publisher">#{CGI.escapeHTML(join_with_separator(publisher, ReVIEW::I18n.t('names_splitter')))}</h3>
197
192
  EOT
198
193
  end
199
194
 
200
- @language = @producer.params['language']
201
- @stylesheets = @producer.params["stylesheet"]
202
- if @producer.params["htmlversion"].to_i == 5
203
- tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
204
- else
205
- tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
206
- end
195
+ @language = @producer.config['language']
196
+ @stylesheets = @producer.config['stylesheet']
197
+ tmplfile = if @producer.config['htmlversion'].to_i == 5
198
+ File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
199
+ else
200
+ File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
201
+ end
207
202
  tmpl = ReVIEW::Template.load(tmplfile)
208
203
  tmpl.result(binding)
209
204
  end
210
205
 
211
206
  # Return colophon content.
212
207
  def colophon
213
- @title = CGI.escapeHTML(@producer.res.v("colophontitle"))
208
+ @title = CGI.escapeHTML(@producer.res.v('colophontitle'))
214
209
  @body = <<EOT
215
210
  <div class="colophon">
216
211
  EOT
217
212
 
218
- if @producer.params["subtitle"].nil?
213
+ if @producer.config['subtitle'].nil?
219
214
  @body << <<EOT
220
- <p class="title">#{CGI.escapeHTML(@producer.params.name_of("title"))}</p>
215
+ <p class="title">#{CGI.escapeHTML(@producer.config.name_of('title'))}</p>
221
216
  EOT
222
217
  else
223
218
  @body << <<EOT
224
- <p class="title">#{CGI.escapeHTML(@producer.params.name_of("title"))}<br /><span class="subtitle">#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}</span></p>
219
+ <p class="title">#{CGI.escapeHTML(@producer.config.name_of('title'))}<br /><span class="subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</span></p>
225
220
  EOT
226
221
  end
227
222
 
228
- if @producer.params["date"] || @producer.params["history"]
229
- @body << colophon_history
230
- end
223
+ @body << colophon_history if @producer.config['date'] || @producer.config['history']
231
224
 
232
- @body << %Q[ <table class="colophon">\n]
233
- @body << @producer.params["colophon_order"].map{ |role|
234
- if @producer.params[role]
235
- %Q[ <tr><th>#{CGI.escapeHTML(@producer.res.v(role))}</th><td>#{CGI.escapeHTML(join_with_separator(@producer.params.names_of(role), ReVIEW::I18n.t("names_splitter")))}</td></tr>\n]
225
+ @body << %Q( <table class="colophon">\n)
226
+ @body << @producer.config['colophon_order'].map do |role|
227
+ if @producer.config[role]
228
+ %Q( <tr><th>#{CGI.escapeHTML(@producer.res.v(role))}</th><td>#{CGI.escapeHTML(join_with_separator(@producer.config.names_of(role), ReVIEW::I18n.t('names_splitter')))}</td></tr>\n)
236
229
  else
237
- ""
230
+ ''
238
231
  end
239
- }.join("")
240
-
241
- if @producer.isbn_hyphen
242
- @body << %Q[ <tr><th>ISBN</th><td>#{@producer.isbn_hyphen}</td></tr>\n]
243
- end
244
- @body << %Q[ </table>\n]
245
- if !@producer.params["rights"].nil? && @producer.params["rights"].size > 0
246
- @body << %Q[ <p class="copyright">#{join_with_separator(@producer.params.names_of("rights").map {|m| CGI.escapeHTML(m)}, "<br />")}</p>\n]
247
- end
248
- @body << %Q[ </div>\n]
249
-
250
- @language = @producer.params['language']
251
- @stylesheets = @producer.params["stylesheet"]
252
- if @producer.params["htmlversion"].to_i == 5
253
- tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
254
- else
255
- tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
256
- end
232
+ end.join
233
+
234
+ @body << %Q( <tr><th>ISBN</th><td>#{@producer.isbn_hyphen}</td></tr>\n) if @producer.isbn_hyphen
235
+ @body << %Q( </table>\n)
236
+ @body << %Q( <p class="copyright">#{join_with_separator(@producer.config.names_of('rights').map { |m| CGI.escapeHTML(m) }, '<br />')}</p>\n) if @producer.config['rights'] && !@producer.config['rights'].empty?
237
+ @body << %Q( </div>\n)
238
+
239
+ @language = @producer.config['language']
240
+ @stylesheets = @producer.config['stylesheet']
241
+ tmplfile = if @producer.config['htmlversion'].to_i == 5
242
+ File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
243
+ else
244
+ File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
245
+ end
257
246
  tmpl = ReVIEW::Template.load(tmplfile)
258
247
  tmpl.result(binding)
259
248
  end
260
249
 
261
250
  def colophon_history
262
- buf = ""
263
- buf << %Q[ <div class="pubhistory">\n]
264
- if @producer.params["history"]
265
- @producer.params["history"].each_with_index do |items, edit|
251
+ buf = ''
252
+ buf << %Q( <div class="pubhistory">\n)
253
+ if @producer.config['history']
254
+ @producer.config['history'].each_with_index do |items, edit|
266
255
  items.each_with_index do |item, rev|
267
- editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
268
- revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
256
+ editstr = edit == 0 ? ReVIEW::I18n.t('first_edition') : ReVIEW::I18n.t('nth_edition', (edit + 1).to_s)
257
+ revstr = ReVIEW::I18n.t('nth_impression', (rev + 1).to_s)
269
258
  if item =~ /\A\d+\-\d+\-\d+\Z/
270
- buf << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
259
+ buf << %Q( <p>#{ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])}</p>\n)
271
260
  elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/
272
261
  # custom date with string
273
262
  item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
274
- buf << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
263
+ buf << %Q( <p>#{ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]])}</p>\n)
275
264
  end
276
265
  else
277
266
  # free format
278
- buf << %Q[ <p>#{item}</p>\n]
267
+ buf << %Q( <p>#{item}</p>\n)
279
268
  end
280
269
  end
281
270
  end
282
271
  else
283
- buf << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
272
+ buf << %Q( <p>#{ReVIEW::I18n.t('published_by2', date_to_s(@producer.config['date']))}</p>\n)
284
273
  end
285
- buf << %Q[ </div>\n]
274
+ buf << %Q( </div>\n)
286
275
  buf
287
276
  end
288
277
 
289
278
  def date_to_s(date)
290
279
  require 'date'
291
280
  d = Date.parse(date)
292
- d.strftime(ReVIEW::I18n.t("date_format"))
281
+ d.strftime(ReVIEW::I18n.t('date_format'))
293
282
  end
294
283
 
295
284
  # Return own toc content.
296
285
  def mytoc
297
- @title = CGI.escapeHTML(@producer.res.v("toctitle"))
286
+ @title = CGI.escapeHTML(@producer.res.v('toctitle'))
298
287
 
299
- @body = %Q[ <h1 class="toc-title">#{CGI.escapeHTML(@producer.res.v("toctitle"))}</h1>\n]
300
- if @producer.params["epubmaker"]["flattoc"].nil?
301
- @body << hierarchy_ncx("ul")
288
+ @body = %Q( <h1 class="toc-title">#{CGI.escapeHTML(@producer.res.v('toctitle'))}</h1>\n)
289
+ if @producer.config['epubmaker']['flattoc'].nil?
290
+ @body << hierarchy_ncx('ul')
302
291
  else
303
- @body << flat_ncx("ul", @producer.params["epubmaker"]["flattocindent"])
292
+ @body << flat_ncx('ul', @producer.config['epubmaker']['flattocindent'])
304
293
  end
305
294
 
306
- @language = @producer.params['language']
307
- @stylesheets = @producer.params["stylesheet"]
308
- if @producer.params["htmlversion"].to_i == 5
309
- tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
310
- else
311
- tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
312
- end
295
+ @language = @producer.config['language']
296
+ @stylesheets = @producer.config['stylesheet']
297
+ tmplfile = if @producer.config['htmlversion'].to_i == 5
298
+ File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
299
+ else
300
+ File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
301
+ end
313
302
  tmpl = ReVIEW::Template.load(tmplfile)
314
303
  tmpl.result(binding)
315
304
  end
@@ -319,25 +308,25 @@ EOT
319
308
  level = 1
320
309
  find_jump = nil
321
310
  has_part = nil
322
- toclevel = @producer.params["toclevel"].to_i
311
+ toclevel = @producer.config['toclevel'].to_i
323
312
 
324
313
  # check part existance
325
314
  @producer.contents.each do |item|
326
- if item.notoc.nil? && item.chaptype == "part"
327
- has_part = true
328
- break
329
- end
315
+ next if item.notoc || item.chaptype != 'part'
316
+
317
+ has_part = true
318
+ break
330
319
  end
331
320
 
332
- if !has_part.nil?
321
+ if has_part
333
322
  @producer.contents.each do |item|
334
- item.level += 1 if item.chaptype == "part" || item.chaptype == "body"
335
- item.notoc = true if (item.chaptype == "pre" || item.chaptype == "post") && !item.level.nil? && (item.level + 1 == toclevel) # FIXME: 部があるときに前後の処理が困難
323
+ item.level += 1 if item.chaptype == 'part' || item.chaptype == 'body'
324
+ item.notoc = true if (item.chaptype == 'pre' || item.chaptype == 'post') && !item.level.nil? && (item.level + 1 == toclevel) # FIXME: part processing
336
325
  end
337
326
  toclevel += 1
338
327
  end
339
328
 
340
- doc = REXML::Document.new(%Q[<#{type} class="toc-h#{level}"><li /></#{type}>])
329
+ doc = REXML::Document.new(%Q(<#{type} class="toc-h#{level}"><li /></#{type}>))
341
330
  doc.context[:attribute_quote] = :quote
342
331
 
343
332
  e = doc.root.elements[1] # first <li/>
@@ -345,7 +334,7 @@ EOT
345
334
  next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > toclevel
346
335
 
347
336
  if item.level == level
348
- e2 = e.parent.add_element("li")
337
+ e2 = e.parent.add_element('li')
349
338
  e = e2
350
339
  elsif item.level > level
351
340
  find_jump = true if (item.level - level) > 1
@@ -353,59 +342,57 @@ EOT
353
342
  (level + 1).upto(item.level) do |n|
354
343
  if e.size == 0
355
344
  # empty span for epubcheck
356
- e.attributes["style"] = "list-style-type: none;"
357
- es = e.add_element("span", {"style"=>"display:none;"})
358
- es.add_text(REXML::Text.new("&#xa0;", false, nil, true))
345
+ e.attributes['style'] = 'list-style-type: none;'
346
+ es = e.add_element('span', 'style' => 'display:none;')
347
+ es.add_text(REXML::Text.new('&#xa0;', false, nil, true))
359
348
  end
360
349
 
361
- e2 = e.add_element(type, {"class" => "toc-h#{n}"})
362
- e3 = e2.add_element("li")
350
+ e2 = e.add_element(type, 'class' => "toc-h#{n}")
351
+ e3 = e2.add_element('li')
363
352
  e = e3
364
353
  end
365
354
  level = item.level
366
355
  elsif item.level < level
367
356
  # shallower
368
- (level - 1).downto(item.level) do |n|
369
- e = e.parent.parent
370
- end
371
- e2 = e.parent.add_element("li")
357
+ (level - 1).downto(item.level) { e = e.parent.parent }
358
+ e2 = e.parent.add_element('li')
372
359
  e = e2
373
360
  level = item.level
374
361
  end
375
- e2 = e.add_element("a", {"href" => item.file})
362
+ e2 = e.add_element('a', 'href' => item.file)
376
363
  e2.add_text(REXML::Text.new(item.title, true))
377
364
  end
378
365
 
379
- warn "found level jumping in table of contents. consider to use 'epubmaker:flattoc: true' for strict ePUB validator." unless find_jump.nil?
366
+ warn %Q(found level jumping in table of contents. consider to use 'epubmaker:flattoc: true' for strict ePUB validator.) unless find_jump.nil?
380
367
 
381
- doc.to_s.gsub("<li/>", "").gsub("</li>", "</li>\n").gsub("<#{type} ", "\n" + '\&') # ugly
368
+ doc.to_s.gsub('<li/>', '').gsub('</li>', "</li>\n").gsub("<#{type} ", "\n" + '\&') # ugly
382
369
  end
383
370
 
384
- def flat_ncx(type, indent=nil)
385
- s = %Q[<#{type} class="toc-h1">\n]
371
+ def flat_ncx(type, indent = nil)
372
+ s = %Q(<#{type} class="toc-h1">\n)
386
373
  @producer.contents.each do |item|
387
- next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > @producer.params["toclevel"].to_i
388
- is = indent == true ? " " * item.level : ""
389
- s << %Q[<li><a href="#{item.file}">#{is}#{CGI.escapeHTML(item.title)}</a></li>\n]
374
+ next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > @producer.config['toclevel'].to_i
375
+ is = indent == true ? ' ' * item.level : ''
376
+ s << %Q(<li><a href="#{item.file}">#{is}#{CGI.escapeHTML(item.title)}</a></li>\n)
390
377
  end
391
- s << %Q[</#{type}>\n]
378
+ s << %Q(</#{type}>\n)
392
379
 
393
380
  s
394
381
  end
395
382
 
396
383
  def produce_write_common(basedir, tmpdir)
397
- File.open("#{tmpdir}/mimetype", "w") {|f| @producer.mimetype(f) }
384
+ File.open("#{tmpdir}/mimetype", 'w') { |f| @producer.mimetype(f) }
398
385
 
399
386
  FileUtils.mkdir_p("#{tmpdir}/META-INF")
400
- File.open("#{tmpdir}/META-INF/container.xml", "w") {|f| @producer.container(f) }
387
+ File.open("#{tmpdir}/META-INF/container.xml", 'w') { |f| @producer.container(f) }
401
388
 
402
389
  FileUtils.mkdir_p("#{tmpdir}/OEBPS")
403
- File.open(File.join(tmpdir, opf_path), "w") {|f| @producer.opf(f) }
390
+ File.open(File.join(tmpdir, opf_path), 'w') { |f| @producer.opf(f) }
404
391
 
405
- if File.exist?("#{basedir}/#{@producer.params["cover"]}")
406
- FileUtils.cp("#{basedir}/#{@producer.params["cover"]}", "#{tmpdir}/OEBPS")
392
+ if File.exist?("#{basedir}/#{@producer.config['cover']}")
393
+ FileUtils.cp("#{basedir}/#{@producer.config['cover']}", "#{tmpdir}/OEBPS")
407
394
  else
408
- File.open("#{tmpdir}/OEBPS/#{@producer.params["cover"]}", "w") {|f| @producer.cover(f) }
395
+ File.open("#{tmpdir}/OEBPS/#{@producer.config['cover']}", 'w') { |f| @producer.cover(f) }
409
396
  end
410
397
 
411
398
  @producer.contents.each do |item|
@@ -418,21 +405,21 @@ EOT
418
405
  end
419
406
 
420
407
  def legacy_cover_and_title_file(loadfile, writefile)
421
- @title = @producer.params["booktitle"]
422
- s = ""
408
+ @title = @producer.config['booktitle']
409
+ s = ''
423
410
  File.open(loadfile) do |f|
424
411
  f.each_line do |l|
425
412
  s << l
426
413
  end
427
414
  end
428
415
 
429
- File.open(writefile, "w") do |f|
416
+ File.open(writefile, 'w') do |f|
430
417
  f.puts s
431
418
  end
432
419
  end
433
420
 
434
421
  def join_with_separator(value, sep)
435
- if value.kind_of? Array
422
+ if value.is_a?(Array)
436
423
  value.join(sep)
437
424
  else
438
425
  value