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,7 +1,5 @@
1
- #
2
- # $Id: unfold.rb 3878 2008-02-09 13:12:15Z aamine $
3
- #
4
- # Copyright (c) 2002-2007 Minero Aoki
1
+ # Copyright (c) 2007-2017 Kenshi Muto
2
+ # 2002-2007 Minero Aoki
5
3
  #
6
4
  # This program is free software.
7
5
  # You can distribute or modify this program under the terms of
@@ -13,18 +11,16 @@ require 'review/preprocessor'
13
11
  require 'stringio'
14
12
 
15
13
  module ReVIEW
16
-
17
14
  class WrongInput < Error; end
18
15
 
19
16
  class Unfold
20
-
21
17
  # unfold paragraphs and strip preprocessor tags.
22
- def Unfold.unfold_author_source(s)
18
+ def self.unfold_author_source(s)
23
19
  unfold(Preprocessor::Strip.new(StringIO.new(s)))
24
20
  end
25
21
 
26
- def Unfold.unfold(f)
27
- new().unfold(f)
22
+ def self.unfold(f)
23
+ new.unfold(f)
28
24
  end
29
25
 
30
26
  def initialize(indent_paragraph = false)
@@ -47,14 +43,14 @@ module ReVIEW
47
43
 
48
44
  private
49
45
 
50
- ZSPACE = "\241\241" # EUC-JP zen-kaku space
46
+ ZSPACE = "\241\241".freeze # EUC-JP zen-kaku space
51
47
 
52
48
  def do_unfold(input)
53
49
  @blank_needed = false
54
50
  first = true
55
51
  indent = @indent_paragraph ? ZSPACE : ''
56
52
  f = LineInput.new(input)
57
- while line = f.gets
53
+ f.each_line do |line|
58
54
  case line
59
55
  when /\A\#@/
60
56
  raise "must not happen: input includes preproc directive: #{line.inspect}"
@@ -81,27 +77,25 @@ module ReVIEW
81
77
  println line
82
78
  skip_block f, /\A:|\A\s+\S/
83
79
  blank
84
- when %r<\A//\w.*\{\s*\z>
80
+ when %r{\A//\w.*\{\s*\z}
85
81
  blank
86
82
  println line
87
- f.until_terminator(%r<\A//\}>) do |s|
83
+ f.until_terminator(%r{\A//\}}) do |s|
88
84
  println s
89
85
  end
90
86
  println '//}'
91
87
  blank
92
- when %r<\A//\w>
88
+ when %r{\A//\w}
93
89
  blank
94
90
  println line
95
91
  blank
96
92
  when /\A\S/
97
- if %r<\A//\[> =~ line
93
+ if %r{\A//\[} =~ line
98
94
  $stderr.puts "warning: #{f.path}:#{f.lineno}: paragraph begin with `//['; missing ReVIEW directive name?"
99
95
  end
100
96
  flush_blank
101
97
  @output.print indent + line.rstrip
102
- f.until_match(%r<\A\s*\z|\A//\w>) do |s|
103
- @output.print s.rstrip
104
- end
98
+ f.until_match(%r{\A\s*\z|\A//\w}) { |s| @output.print s.rstrip }
105
99
  @output.puts
106
100
  else
107
101
  unless line.strip.empty?
@@ -127,12 +121,9 @@ module ReVIEW
127
121
  end
128
122
 
129
123
  def flush_blank
130
- if @blank_needed
131
- @output.puts
132
- @blank_needed = false
133
- end
124
+ return unless @blank_needed
125
+ @output.puts
126
+ @blank_needed = false
134
127
  end
135
-
136
128
  end
137
-
138
129
  end # module ReVIEW
@@ -1,3 +1,3 @@
1
1
  module ReVIEW
2
- VERSION = "2.3.0"
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # This program is free software.
4
2
  # You can distribute or modify this program under the terms of
5
3
  # the GNU LGPL, Lesser General Public License version 2.1.
@@ -28,6 +26,7 @@ module ReVIEW
28
26
 
29
27
  def initialize
30
28
  @basedir = nil
29
+ @logger = ReVIEW.logger
31
30
  end
32
31
 
33
32
  def self.execute(*args)
@@ -38,15 +37,13 @@ module ReVIEW
38
37
  cmd_config = {}
39
38
  opts = OptionParser.new
40
39
 
41
- opts.banner = "Usage: review-webmaker configfile"
40
+ opts.banner = 'Usage: review-webmaker configfile'
42
41
  opts.version = ReVIEW::VERSION
43
42
  opts.on('--help', 'Prints this message and quit.') do
44
43
  puts opts.help
45
44
  exit 0
46
45
  end
47
- opts.on('--ignore-errors', 'Ignore review-compile errors.') do
48
- cmd_config["ignore-errors"] = true
49
- end
46
+ opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true }
50
47
 
51
48
  opts.parse!(args)
52
49
  if args.size != 1
@@ -54,33 +51,35 @@ module ReVIEW
54
51
  exit 0
55
52
  end
56
53
 
57
- return cmd_config, args[0]
54
+ [cmd_config, args[0]]
58
55
  end
59
56
 
60
57
  def build_path
61
- @config["docroot"] || "webroot"
58
+ @config['docroot'] || 'webroot'
62
59
  end
63
60
 
64
61
  def remove_old_files(path)
62
+ math_dir = "./#{@config['imagedir']}/_review_math"
63
+ FileUtils.rm_rf(math_dir) if @config['imgmath'] && Dir.exist?(math_dir)
65
64
  FileUtils.rm_rf(path)
66
65
  end
67
66
 
68
67
  def execute(*args)
69
68
  @config = ReVIEW::Configure.values
70
- @config.maker = "webmaker"
69
+ @config.maker = 'webmaker'
71
70
  cmd_config, yamlfile = parse_opts(args)
72
71
 
73
72
  @config.merge!(YAML.load_file(yamlfile))
74
73
  # YAML configs will be overridden by command line options.
75
74
  @config.merge!(cmd_config)
76
- @config["htmlext"] = "html"
77
- I18n.setup(@config["language"])
75
+ @config['htmlext'] = 'html'
76
+ I18n.setup(@config['language'])
78
77
  generate_html_files(yamlfile)
79
78
  end
80
79
 
81
80
  def generate_html_files(yamlfile)
82
81
  @basedir = File.dirname(yamlfile)
83
- @path = build_path()
82
+ @path = build_path
84
83
  remove_old_files(@path)
85
84
  Dir.mkdir(@path)
86
85
 
@@ -92,56 +91,50 @@ module ReVIEW
92
91
  build_body(@path, yamlfile)
93
92
  copy_backmatter(@path)
94
93
 
95
- copy_images(@config["imagedir"], "#{@path}/#{@config["imagedir"]}")
94
+ copy_images(@config['imagedir'], "#{@path}/#{@config['imagedir']}")
96
95
 
97
- copy_resources("covers", "#{@path}/#{@config["imagedir"]}")
98
- copy_resources("adv", "#{@path}/#{@config["imagedir"]}")
99
- copy_resources(@config["fontdir"], "#{@path}/fonts", @config["font_ext"])
96
+ copy_resources('covers', "#{@path}/#{@config['imagedir']}")
97
+ copy_resources('adv', "#{@path}/#{@config['imagedir']}")
98
+ copy_resources(@config['fontdir'], "#{@path}/fonts", @config['font_ext'])
100
99
  end
101
100
 
102
- def build_body(basetmpdir, yamlfile)
101
+ def build_body(basetmpdir, _yamlfile)
103
102
  base_path = Pathname.new(@basedir)
104
103
  builder = ReVIEW::HTMLBuilder.new
105
104
  @converter = ReVIEW::Converter.new(@book, builder)
106
105
  @book.parts.each do |part|
107
- htmlfile = nil
108
106
  if part.name.present?
109
107
  if part.file?
110
108
  build_chap(part, base_path, basetmpdir, true)
111
109
  else
112
- htmlfile = "part_#{part.number}.#{@config["htmlext"]}"
110
+ htmlfile = "part_#{part.number}.#{@config['htmlext']}"
113
111
  build_part(part, basetmpdir, htmlfile)
114
- title = ReVIEW::I18n.t("part", part.number)
115
- title += ReVIEW::I18n.t("chapter_postfix") + part.name.strip if part.name.strip.present?
112
+ # title = ReVIEW::I18n.t('part', part.number)
113
+ # title += ReVIEW::I18n.t('chapter_postfix') + part.name.strip unless part.name.strip.empty?
116
114
  end
117
115
  end
118
116
 
119
- part.chapters.each do |chap|
120
- build_chap(chap, base_path, basetmpdir, false)
121
- end
117
+ part.chapters.each { |chap| build_chap(chap, base_path, basetmpdir, false) }
122
118
  end
123
119
  end
124
120
 
125
121
  def build_part(part, basetmpdir, htmlfile)
126
- File.open("#{basetmpdir}/#{htmlfile}", "w") do |f|
127
- @body = ""
128
- @body << "<div class=\"part\">\n"
129
- @body << "<h1 class=\"part-number\">#{ReVIEW::I18n.t("part", part.number)}</h1>\n"
130
- if part.name.strip.present?
131
- @body << "<h2 class=\"part-title\">#{part.name.strip}</h2>\n"
132
- end
122
+ File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
123
+ @body = ''
124
+ @body << %Q(<div class="part">\n)
125
+ @body << %Q(<h1 class="part-number">#{ReVIEW::I18n.t('part', part.number)}</h1>\n)
126
+ @body << %Q(<h2 class="part-title">#{part.name.strip}</h2>\n) if part.name.strip.present?
133
127
  @body << "</div>\n"
134
128
 
135
129
  @language = @config['language']
136
- @stylesheets = @config["stylesheet"]
130
+ @stylesheets = @config['stylesheet']
137
131
  tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
138
- tmpl = ReVIEW::Template.load(tmplfile)
139
- f.write tmpl.result(binding)
132
+ f.write ReVIEW::Template.load(tmplfile).result(binding)
140
133
  end
141
134
  end
142
135
 
143
136
  def template_name
144
- if @config["htmlversion"].to_i == 5
137
+ if @config['htmlversion'].to_i == 5
145
138
  'web/html/layout-html5.html.erb'
146
139
  else
147
140
  'web/html/layout-xhtml1.html.erb'
@@ -149,41 +142,39 @@ module ReVIEW
149
142
  end
150
143
 
151
144
  def build_chap(chap, base_path, basetmpdir, ispart)
152
- filename = ""
145
+ filename = ''
153
146
 
154
147
  if ispart.present?
155
148
  filename = chap.path
156
149
  else
157
150
  filename = Pathname.new(chap.path).relative_path_from(base_path).to_s
158
151
  end
159
- id = filename.sub(/\.re\Z/, "")
152
+ id = filename.sub(/\.re\Z/, '')
160
153
 
161
- htmlfile = "#{id}.#{@config["htmlext"]}"
154
+ htmlfile = "#{id}.#{@config['htmlext']}"
162
155
 
163
- if @config["params"].present?
164
- warn "'params:' in config.yml is obsoleted."
156
+ if @config['params'].present?
157
+ @logger.warn %Q('params:' in config.yml is obsoleted.)
165
158
  end
166
159
 
167
160
  begin
168
161
  @converter.convert(filename, File.join(basetmpdir, htmlfile))
169
162
  rescue => e
170
- warn "compile error in #{filename} (#{e.class})"
171
- warn e.message
163
+ @logger.warn "compile error in #{filename} (#{e.class})"
164
+ @logger.warn e.message
172
165
  end
173
166
  end
174
167
 
175
168
  def copy_images(resdir, destdir)
176
169
  return nil unless File.exist?(resdir)
177
- allow_exts = @config["image_ext"]
170
+ allow_exts = @config['image_ext']
178
171
  FileUtils.mkdir_p(destdir)
179
172
  recursive_copy_files(resdir, destdir, allow_exts)
180
173
  end
181
174
 
182
- def copy_resources(resdir, destdir, allow_exts=nil)
183
- if !resdir || !File.exist?(resdir)
184
- return nil
185
- end
186
- allow_exts = @config["image_ext"] if allow_exts.nil?
175
+ def copy_resources(resdir, destdir, allow_exts = nil)
176
+ return nil if !resdir || !File.exist?(resdir)
177
+ allow_exts = @config['image_ext'] if allow_exts.nil?
187
178
  FileUtils.mkdir_p(destdir)
188
179
  recursive_copy_files(resdir, destdir, allow_exts)
189
180
  end
@@ -194,107 +185,92 @@ module ReVIEW
194
185
  next if fname.start_with?('.')
195
186
  if FileTest.directory?("#{resdir}/#{fname}")
196
187
  recursive_copy_files("#{resdir}/#{fname}", "#{destdir}/#{fname}", allow_exts)
197
- else
198
- if fname =~ /\.(#{allow_exts.join("|")})\Z/i
199
- FileUtils.mkdir_p(destdir)
200
- FileUtils.cp("#{resdir}/#{fname}", destdir)
201
- end
188
+ elsif fname =~ /\.(#{allow_exts.join('|')})\Z/i
189
+ FileUtils.mkdir_p(destdir)
190
+ FileUtils.cp("#{resdir}/#{fname}", destdir)
202
191
  end
203
192
  end
204
193
  end
205
194
  end
206
195
 
207
196
  def copy_stylesheet(basetmpdir)
208
- if @config["stylesheet"].size > 0
209
- @config["stylesheet"].each do |sfile|
210
- FileUtils.cp(sfile, basetmpdir)
211
- end
212
- end
197
+ @config['stylesheet'].each { |sfile| FileUtils.cp(sfile, basetmpdir) } if @config['stylesheet'].size > 0
213
198
  end
214
199
 
215
200
  def copy_frontmatter(basetmpdir)
216
201
  build_indexpage(basetmpdir)
217
202
 
218
- if @config["titlepage"]
219
- if @config["titlefile"]
220
- FileUtils.cp(@config["titlefile"], "#{basetmpdir}/titlepage.#{@config["htmlext"]}")
203
+ if @config['titlepage']
204
+ if @config['titlefile']
205
+ FileUtils.cp(@config['titlefile'], "#{basetmpdir}/titlepage.#{@config['htmlext']}")
221
206
  else
222
- build_titlepage(basetmpdir, "titlepage.#{@config["htmlext"]}")
207
+ build_titlepage(basetmpdir, "titlepage.#{@config['htmlext']}")
223
208
  end
224
209
  end
225
210
 
226
- copy_file_with_param("creditfile")
227
- copy_file_with_param("originaltitlefile")
211
+ copy_file_with_param('creditfile')
212
+ copy_file_with_param('originaltitlefile')
228
213
  end
229
214
 
230
215
  def build_indexpage(basetmpdir)
231
- File.open("#{basetmpdir}/index.html", "w") do |f|
232
- if @config["coverimage"]
233
- file = File.join(@config["imagedir"], @config["coverimage"])
216
+ File.open("#{basetmpdir}/index.html", 'w') do |f|
217
+ if @config['coverimage']
218
+ file = File.join(@config['imagedir'], @config['coverimage'])
234
219
  @body = <<-EOT
235
220
  <div id="cover-image" class="cover-image">
236
221
  <img src="#{file}" class="max"/>
237
222
  </div>
238
223
  EOT
239
224
  else
240
- @body = ""
225
+ @body = ''
241
226
  end
242
227
  @language = @config['language']
243
- @stylesheets = @config["stylesheet"]
228
+ @stylesheets = @config['stylesheet']
244
229
  @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
245
230
  @next = @book.chapters[0]
246
- @next_title = @next ? @next.title : ""
231
+ @next_title = @next ? @next.title : ''
247
232
  tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
248
- tmpl = ReVIEW::Template.load(tmplfile)
249
- f.write tmpl.result(binding)
233
+ f.write ReVIEW::Template.load(tmplfile).result(binding)
250
234
  end
251
235
  end
252
236
 
253
237
  def build_titlepage(basetmpdir, htmlfile)
254
- File.open("#{basetmpdir}/#{htmlfile}", "w") do |f|
255
- @body = ""
256
- @body << "<div class=\"titlepage\">"
257
- @body << "<h1 class=\"tp-title\">#{CGI.escapeHTML(@config["booktitle"])}</h1>"
258
- if @config["aut"]
259
- @body << "<h2 class=\"tp-author\">#{join_with_separator(@config["aut"], ReVIEW::I18n.t("names_splitter"))}</h2>"
260
- end
261
- if @config["prt"]
262
- @body << "<h3 class=\"tp-publisher\">#{join_with_separator(@config["prt"], ReVIEW::I18n.t("names_splitter"))}</h3>"
263
- end
264
- @body << "</div>"
238
+ File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
239
+ @body = ''
240
+ @body << %Q(<div class="titlepage">)
241
+ @body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>)
242
+ @body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>) if @config['aut']
243
+ @body << %Q(<h3 class="tp-publisher">#{join_with_separator(@config.names_of('prt'), ReVIEW::I18n.t('names_splitter'))}</h3>) if @config['prt']
244
+ @body << '</div>'
265
245
 
266
246
  @language = @config['language']
267
- @stylesheets = @config["stylesheet"]
247
+ @stylesheets = @config['stylesheet']
268
248
  tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
269
- tmpl = ReVIEW::Template.load(tmplfile)
270
- f.write tmpl.result(binding)
249
+ f.write ReVIEW::Template.load(tmplfile).result(binding)
271
250
  end
272
251
  end
273
252
 
274
- def copy_backmatter(basetmpdir)
275
- copy_file_with_param("profile")
276
- copy_file_with_param("advfile")
277
- if @config["colophon"] && @config["colophon"].kind_of?(String)
278
- copy_file_with_param("colophon", "colophon.#{@config["htmlext"]}")
253
+ def copy_backmatter(_basetmpdir)
254
+ copy_file_with_param('profile')
255
+ copy_file_with_param('advfile')
256
+ if @config['colophon'] && @config['colophon'].is_a?(String)
257
+ copy_file_with_param('colophon', "colophon.#{@config['htmlext']}")
279
258
  end
280
- copy_file_with_param("backcover")
259
+ copy_file_with_param('backcover')
281
260
  end
282
261
 
283
262
  def copy_file_with_param(name, target_file = nil)
284
- if @config[name] && File.exist?(@config[name])
285
- target_file ||= File.basename(@config[name])
286
- FileUtils.cp(@config[name], File.join(basetmpdir, target_file))
287
- end
263
+ return if @config[name].nil? || !File.exist?(@config[name])
264
+ target_file ||= File.basename(@config[name])
265
+ FileUtils.cp(@config[name], File.join(basetmpdir, target_file))
288
266
  end
289
267
 
290
268
  def join_with_separator(value, sep)
291
- if value.kind_of? Array
269
+ if value.is_a?(Array)
292
270
  value.join(sep)
293
271
  else
294
272
  value
295
273
  end
296
274
  end
297
-
298
275
  end
299
276
  end
300
-
@@ -14,7 +14,7 @@ module ReVIEW
14
14
 
15
15
  def print_book(book)
16
16
  @out.puts '<ul class="book-toc">'
17
- @out.puts "<li><a href=\"index.html\">TOP</a></li>\n"
17
+ @out.puts %Q(<li><a href="index.html">TOP</a></li>\n)
18
18
  book.each_part do |part|
19
19
  print_part(part)
20
20
  end
@@ -24,32 +24,27 @@ module ReVIEW
24
24
  def print_part(part)
25
25
  if part.number
26
26
  if part.file?
27
- ext = part.book.config["htmlext"] || "html"
28
- path = part.path.sub(/\.re/, "."+ext)
29
- @out.puts "<li><a href=\"#{path}\">#{h(I18n.t("part_short", part.number) + " " + part.title)}</a>\n<ul>\n"
27
+ ext = part.book.config['htmlext'] || 'html'
28
+ path = part.path.sub(/\.re/, '.' + ext)
29
+ @out.puts %Q(<li><a href="#{path}">#{h(I18n.t('part_short', part.number) + ' ' + part.title)}</a>\n<ul>\n)
30
30
  else
31
- @out.puts "<li>#{h(I18n.t("part_short", part.number) + " " + part.title)}\n<ul>\n"
31
+ @out.puts %Q(<li>#{h(I18n.t('part_short', part.number) + ' ' + part.title)}\n<ul>\n)
32
32
  end
33
33
  end
34
- part.each_chapter do |chap|
35
- print_chapter(chap)
36
- end
37
- if part.number
38
- @out.puts "</ul>\n</li>\n"
39
- end
34
+ part.each_chapter { |chap| print_chapter(chap) }
35
+ @out.puts "</ul>\n</li>\n" if part.number
40
36
  end
41
37
 
42
38
  def print_chapter(chap)
43
39
  chap_node = TOCParser.chapter_node(chap)
44
- ext = chap.book.config["htmlext"] || "html"
45
- path = chap.path.sub(/\.re/, "."+ext)
46
- if chap_node.number && chap.on_CHAPS?
47
- label = "#{I18n.t("chapter_short", chap.number)} #{chap.title}"
48
- else
49
- label = chap.title
50
- end
51
- @out.puts "<li><a href=\"#{path}\">#{h(label)}</a></li>\n"
40
+ ext = chap.book.config['htmlext'] || 'html'
41
+ path = chap.path.sub(/\.re/, '.' + ext)
42
+ label = if chap_node.number && chap.on_chaps?
43
+ "#{I18n.t('chapter_short', chap.number)} #{chap.title}"
44
+ else
45
+ chap.title
46
+ end
47
+ @out.puts %Q(<li><a href="#{path}">#{h(label)}</a></li>\n)
52
48
  end
53
-
54
49
  end
55
50
  end