review 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # This program is free software.
3
2
  # You can distribute or modify this program under the terms of
4
3
  # the GNU LGPL, Lesser General Public License version 2.1.
@@ -6,26 +5,23 @@
6
5
  require 'review/markdownbuilder'
7
6
 
8
7
  module ReVIEW
9
-
10
8
  class MD2INAOBuilder < MARKDOWNBuilder
11
9
  def paragraph(lines)
12
- puts " " + lines.join
10
+ puts ' ' + lines.join
13
11
  puts "\n"
14
12
  end
15
13
 
16
14
  def list_header(id, caption, lang)
17
- lang ||= ""
15
+ lang ||= ''
18
16
  puts "```#{lang}"
19
- print %Q[●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n]
17
+ print %Q(●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n)
20
18
  end
21
19
 
22
20
  def cmd(lines)
23
21
  # WEB+DB では使っていないらしいけど
24
- puts "!!! cmd"
25
- lines.each do |line|
26
- puts detab(line)
27
- end
28
- puts ""
22
+ puts '!!! cmd'
23
+ lines.each { |line| puts detab(line) }
24
+ puts ''
29
25
  end
30
26
 
31
27
  def dl_begin
@@ -51,7 +47,5 @@ module ReVIEW
51
47
  %Q[<span class='groupruby'>#{escape_html(base)}(#{escape_html(ruby)})</span>]
52
48
  end
53
49
  end
54
-
55
50
  end
56
-
57
51
  end # module ReVIEW
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
4
2
  #
5
3
  # This program is free software.
@@ -23,10 +21,8 @@ require 'review/version'
23
21
  require 'review/makerhelper'
24
22
  require 'review/template'
25
23
 
26
-
27
24
  module ReVIEW
28
25
  class PDFMaker
29
-
30
26
  include FileUtils
31
27
  include ReVIEW::LaTeXUtils
32
28
 
@@ -35,7 +31,8 @@ module ReVIEW
35
31
  def initialize
36
32
  @basedir = nil
37
33
  @basehookdir = nil
38
- @input_files = Hash.new{|h, key| h[key] = ""}
34
+ @logger = ReVIEW.logger
35
+ @input_files = Hash.new { |h, key| h[key] = '' }
39
36
  end
40
37
 
41
38
  def system_or_raise(*args)
@@ -43,16 +40,16 @@ module ReVIEW
43
40
  end
44
41
 
45
42
  def error(msg)
46
- $stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
43
+ @logger.error "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
47
44
  exit 1
48
45
  end
49
46
 
50
47
  def warn(msg)
51
- $stderr.puts "#{File.basename($0, '.*')}: warning: #{msg}"
48
+ @logger.warn "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
52
49
  end
53
50
 
54
51
  def pdf_filepath
55
- File.join(@basedir, @config["bookname"]+".pdf")
52
+ File.join(@basedir, @config['bookname'] + '.pdf')
56
53
  end
57
54
 
58
55
  def remove_old_file
@@ -60,15 +57,13 @@ module ReVIEW
60
57
  end
61
58
 
62
59
  def build_path
63
- if @config["debug"]
64
- path = "#{@config["bookname"]}-pdf"
65
- if File.exist?(path)
66
- FileUtils.rm_rf(path, :secure => true)
67
- end
60
+ if @config['debug']
61
+ path = "#{@config['bookname']}-pdf"
62
+ FileUtils.rm_rf(path, secure: true) if File.exist?(path)
68
63
  Dir.mkdir(path)
69
- return path
64
+ path
70
65
  else
71
- return Dir.mktmpdir("#{@config["bookname"]}-pdf-")
66
+ Dir.mktmpdir("#{@config['bookname']}-pdf-")
72
67
  end
73
68
  end
74
69
 
@@ -76,9 +71,9 @@ module ReVIEW
76
71
  return unless @compile_errors
77
72
 
78
73
  if ignore_errors
79
- $stderr.puts "compile error, but try to generate PDF file"
74
+ $stderr.puts 'compile error, but try to generate PDF file'
80
75
  else
81
- error "compile error, No PDF file output."
76
+ error 'compile error, No PDF file output.'
82
77
  end
83
78
  end
84
79
 
@@ -90,18 +85,14 @@ module ReVIEW
90
85
  cmd_config = {}
91
86
  opts = OptionParser.new
92
87
 
93
- opts.banner = "Usage: review-pdfmaker configfile"
88
+ opts.banner = 'Usage: review-pdfmaker configfile'
94
89
  opts.version = ReVIEW::VERSION
95
90
  opts.on('--help', 'Prints this message and quit.') do
96
91
  puts opts.help
97
92
  exit 0
98
93
  end
99
- opts.on('--[no-]debug', 'Keep temporary files.') do |debug|
100
- cmd_config["debug"] = debug
101
- end
102
- opts.on('--ignore-errors', 'Ignore review-compile errors.') do
103
- cmd_config["ignore-errors"] = true
104
- end
94
+ opts.on('--[no-]debug', 'Keep temporary files.') { |debug| cmd_config['debug'] = debug }
95
+ opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true }
105
96
 
106
97
  opts.parse!(args)
107
98
  if args.size != 1
@@ -109,18 +100,18 @@ module ReVIEW
109
100
  exit 0
110
101
  end
111
102
 
112
- return cmd_config, args[0]
103
+ [cmd_config, args[0]]
113
104
  end
114
105
 
115
106
  def execute(*args)
116
107
  @config = ReVIEW::Configure.values
117
- @config.maker = "pdfmaker"
108
+ @config.maker = 'pdfmaker'
118
109
  cmd_config, yamlfile = parse_opts(args)
119
110
  loader = ReVIEW::YAMLLoader.new
120
111
  @config.deep_merge!(loader.load_file(yamlfile))
121
112
  # YAML configs will be overridden by command line options.
122
113
  @config.merge!(cmd_config)
123
- I18n.setup(@config["language"])
114
+ I18n.setup(@config['language'])
124
115
  @basedir = File.dirname(yamlfile)
125
116
  @basehookdir = File.absolute_path(File.dirname(yamlfile))
126
117
 
@@ -133,24 +124,24 @@ module ReVIEW
133
124
  end
134
125
 
135
126
  def make_input_files(book, yamlfile)
136
- input_files = Hash.new{|h, key| h[key] = ""}
127
+ input_files = Hash.new { |h, key| h[key] = '' }
137
128
  book.parts.each do |part|
138
129
  if part.name.present?
139
130
  if part.file?
140
131
  output_chaps(part.name, yamlfile)
141
- input_files["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
132
+ input_files['CHAPS'] << %Q(\\input{#{part.name}.tex}\n)
142
133
  else
143
- input_files["CHAPS"] << %Q|\\part{#{part.name}}\n|
134
+ input_files['CHAPS'] << %Q(\\part{#{part.name}}\n)
144
135
  end
145
136
  end
146
137
 
147
138
  part.chapters.each do |chap|
148
- filename = File.basename(chap.path, ".*")
139
+ filename = File.basename(chap.path, '.*')
149
140
  output_chaps(filename, yamlfile)
150
- input_files["PREDEF"] << "\\input{#{filename}.tex}\n" if chap.on_PREDEF?
151
- input_files["CHAPS"] << "\\input{#{filename}.tex}\n" if chap.on_CHAPS?
152
- input_files["APPENDIX"] << "\\input{#{filename}.tex}\n" if chap.on_APPENDIX?
153
- input_files["POSTDEF"] << "\\input{#{filename}.tex}\n" if chap.on_POSTDEF?
141
+ input_files['PREDEF'] << "\\input{#{filename}.tex}\n" if chap.on_predef?
142
+ input_files['CHAPS'] << "\\input{#{filename}.tex}\n" if chap.on_chaps?
143
+ input_files['APPENDIX'] << "\\input{#{filename}.tex}\n" if chap.on_appendix?
144
+ input_files['POSTDEF'] << "\\input{#{filename}.tex}\n" if chap.on_postdef?
154
145
  end
155
146
  end
156
147
 
@@ -158,32 +149,32 @@ module ReVIEW
158
149
  end
159
150
 
160
151
  def build_pdf
161
- template = get_template
152
+ template = template_content
162
153
  Dir.chdir(@path) do
163
- File.open("./book.tex", "wb"){|f| f.write(template)}
154
+ File.open('./book.tex', 'wb') { |f| f.write(template) }
164
155
 
165
- call_hook("hook_beforetexcompile")
156
+ call_hook('hook_beforetexcompile')
166
157
 
167
158
  ## do compile
168
- if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
169
- warn "command configuration is prohibited in safe mode. ignored."
170
- texcommand = ReVIEW::Configure.values["texcommand"]
171
- dvicommand = ReVIEW::Configure.values["dvicommand"]
172
- dvioptions = ReVIEW::Configure.values["dvioptions"]
173
- texoptions = ReVIEW::Configure.values["texoptions"]
174
- makeindex_command = ReVIEW::Configure.values["pdfmaker"]["makeindex_command"]
175
- makeindex_options = ReVIEW::Configure.values["pdfmaker"]["makeindex_options"]
176
- makeindex_sty = ReVIEW::Configure.values["pdfmaker"]["makeindex_sty"]
177
- makeindex_dic = ReVIEW::Configure.values["pdfmaker"]["makeindex_dic"]
159
+ if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
160
+ warn 'command configuration is prohibited in safe mode. ignored.'
161
+ texcommand = ReVIEW::Configure.values['texcommand']
162
+ dvicommand = ReVIEW::Configure.values['dvicommand']
163
+ dvioptions = ReVIEW::Configure.values['dvioptions']
164
+ texoptions = ReVIEW::Configure.values['texoptions']
165
+ makeindex_command = ReVIEW::Configure.values['pdfmaker']['makeindex_command']
166
+ makeindex_options = ReVIEW::Configure.values['pdfmaker']['makeindex_options']
167
+ makeindex_sty = ReVIEW::Configure.values['pdfmaker']['makeindex_sty']
168
+ makeindex_dic = ReVIEW::Configure.values['pdfmaker']['makeindex_dic']
178
169
  else
179
- texcommand = @config["texcommand"] if @config["texcommand"]
180
- dvicommand = @config["dvicommand"] if @config["dvicommand"]
181
- dvioptions = @config["dvioptions"] if @config["dvioptions"]
182
- texoptions = @config["texoptions"] if @config["texoptions"]
183
- makeindex_command = @config["pdfmaker"]["makeindex_command"]
184
- makeindex_options = @config["pdfmaker"]["makeindex_options"]
185
- makeindex_sty = @config["pdfmaker"]["makeindex_sty"]
186
- makeindex_dic = @config["pdfmaker"]["makeindex_dic"]
170
+ texcommand = @config['texcommand'] if @config['texcommand']
171
+ dvicommand = @config['dvicommand'] if @config['dvicommand']
172
+ dvioptions = @config['dvioptions'] if @config['dvioptions']
173
+ texoptions = @config['texoptions'] if @config['texoptions']
174
+ makeindex_command = @config['pdfmaker']['makeindex_command']
175
+ makeindex_options = @config['pdfmaker']['makeindex_options']
176
+ makeindex_sty = @config['pdfmaker']['makeindex_sty']
177
+ makeindex_dic = @config['pdfmaker']['makeindex_dic']
187
178
  end
188
179
 
189
180
  if makeindex_sty.present?
@@ -199,23 +190,23 @@ module ReVIEW
199
190
  system_or_raise("#{texcommand} #{texoptions} book.tex")
200
191
  end
201
192
 
202
- call_hook("hook_beforemakeindex")
203
- system_or_raise("#{makeindex_command} #{makeindex_options} book") if @config["pdfmaker"]["makeindex"] && File.exist?("book.idx")
204
- call_hook("hook_aftermakeindex")
193
+ call_hook('hook_beforemakeindex')
194
+ system_or_raise("#{makeindex_command} #{makeindex_options} book") if @config['pdfmaker']['makeindex'] && File.exist?('book.idx')
195
+ call_hook('hook_aftermakeindex')
205
196
 
206
197
  system_or_raise("#{texcommand} #{texoptions} book.tex")
207
- call_hook("hook_aftertexcompile")
198
+ call_hook('hook_aftertexcompile')
208
199
 
209
- if File.exist?("book.dvi")
200
+ if File.exist?('book.dvi')
210
201
  system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
211
- call_hook("hook_afterdvipdf")
202
+ call_hook('hook_afterdvipdf')
212
203
  end
213
204
  end
214
205
  end
215
206
 
216
207
  def generate_pdf(yamlfile)
217
208
  remove_old_file
218
- @path = build_path()
209
+ @path = build_path
219
210
  begin
220
211
  @compile_errors = nil
221
212
 
@@ -225,33 +216,29 @@ module ReVIEW
225
216
 
226
217
  @input_files = make_input_files(book, yamlfile)
227
218
 
228
- check_compile_status(@config["ignore-errors"])
219
+ check_compile_status(@config['ignore-errors'])
229
220
 
230
- @config["usepackage"] = ""
231
- if @config["texstyle"]
232
- @config["usepackage"] = "\\usepackage{#{@config['texstyle']}}"
233
- end
221
+ @config['usepackage'] = ''
222
+ @config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
234
223
 
235
- copy_images(@config["imagedir"], File.join(@path, @config["imagedir"]))
236
- copyStyToDir(File.join(Dir.pwd, "sty"), @path)
237
- copyStyToDir(File.join(Dir.pwd, "sty"), @path, "fd")
238
- copyStyToDir(File.join(Dir.pwd, "sty"), @path, "cls")
239
- copyStyToDir(Dir.pwd, @path, "tex")
224
+ copy_images(@config['imagedir'], File.join(@path, @config['imagedir']))
225
+ copy_sty(File.join(Dir.pwd, 'sty'), @path)
226
+ copy_sty(File.join(Dir.pwd, 'sty'), @path, 'fd')
227
+ copy_sty(File.join(Dir.pwd, 'sty'), @path, 'cls')
228
+ copy_sty(Dir.pwd, @path, 'tex')
240
229
 
241
230
  build_pdf
242
231
 
243
- FileUtils.cp(File.join(@path, "book.pdf"), pdf_filepath)
232
+ FileUtils.cp(File.join(@path, 'book.pdf'), pdf_filepath)
244
233
  ensure
245
- unless @config["debug"]
246
- remove_entry_secure @path
247
- end
234
+ remove_entry_secure @path unless @config['debug']
248
235
  end
249
236
  end
250
237
 
251
- def output_chaps(filename, yamlfile)
238
+ def output_chaps(filename, _yamlfile)
252
239
  $stderr.puts "compiling #{filename}.tex"
253
240
  begin
254
- @converter.convert(filename+".re", File.join(@path, filename+".tex"))
241
+ @converter.convert(filename + '.re', File.join(@path, filename + '.tex'))
255
242
  rescue => e
256
243
  @compile_errors = true
257
244
  warn "compile error in #{filename}.tex (#{e.class})"
@@ -262,33 +249,25 @@ module ReVIEW
262
249
  # PDFMaker#copy_images should copy image files _AND_ execute extractbb (or ebb).
263
250
  #
264
251
  def copy_images(from, to)
265
- if File.exist?(from)
266
- Dir.mkdir(to)
267
- ReVIEW::MakerHelper.copy_images_to_dir(from, to)
268
- Dir.chdir(to) do
269
- images = Dir.glob("**/*").find_all{|f|
270
- File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf|ai|eps|tif)\z/
271
- }
272
- break if images.empty?
273
- system("extractbb", *images)
274
- unless system("extractbb", "-m", *images)
275
- system_or_raise("ebb", *images)
276
- end
277
- end
252
+ return unless File.exist?(from)
253
+ Dir.mkdir(to)
254
+ ReVIEW::MakerHelper.copy_images_to_dir(from, to)
255
+ Dir.chdir(to) do
256
+ images = Dir.glob('**/*').find_all { |f| File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf|ai|eps|tif)\z/ }
257
+ break if images.empty?
258
+ system('extractbb', *images)
259
+ system_or_raise('ebb', *images) unless system('extractbb', '-m', *images)
278
260
  end
279
261
  end
280
262
 
281
263
  def make_custom_page(file)
282
- file_sty = file.to_s.sub(/\.[^.]+$/, ".tex")
283
- if File.exist?(file_sty)
284
- File.read(file_sty)
285
- else
286
- nil
287
- end
264
+ file_sty = file.to_s.sub(/\.[^.]+\Z/, '.tex')
265
+ return File.read(file_sty) if File.exist?(file_sty)
266
+ nil
288
267
  end
289
268
 
290
269
  def join_with_separator(value, sep)
291
- if value.kind_of? Array
270
+ if value.is_a?(Array)
292
271
  value.join(sep)
293
272
  else
294
273
  value
@@ -297,61 +276,56 @@ module ReVIEW
297
276
 
298
277
  def make_colophon_role(role)
299
278
  if @config[role].present?
300
- initialize_metachars(@config["texcommand"])
301
- return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config.names_of(role), ReVIEW::I18n.t("names_splitter")))} \\\\\n"
279
+ initialize_metachars(@config['texcommand'])
280
+ "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config.names_of(role), ReVIEW::I18n.t('names_splitter')))} \\\\\n"
302
281
  else
303
- ""
282
+ ''
304
283
  end
305
284
  end
306
285
 
307
286
  def make_colophon
308
- colophon = ""
309
- @config["colophon_order"].each do |role|
310
- colophon += make_colophon_role(role)
311
- end
287
+ colophon = ''
288
+ @config['colophon_order'].each { |role| colophon += make_colophon_role(role) }
312
289
  colophon
313
290
  end
314
291
 
315
292
  def make_authors
316
- authors = ""
317
- if @config["aut"].present?
318
- author_names = join_with_separator(@config.names_of("aut").map{|s| escape_latex(s)}, ReVIEW::I18n.t("names_splitter"))
319
- authors = ReVIEW::I18n.t("author_with_label", author_names)
293
+ authors = ''
294
+ if @config['aut'].present?
295
+ author_names = join_with_separator(@config.names_of('aut').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
296
+ authors = ReVIEW::I18n.t('author_with_label', author_names)
320
297
  end
321
- if @config["csl"].present?
322
- csl_names = join_with_separator(@config.names_of("csl").map{|s| escape_latex(s)}, ReVIEW::I18n.t("names_splitter"))
323
- authors += " \\\\\n"+ ReVIEW::I18n.t("supervisor_with_label", csl_names)
298
+ if @config['csl'].present?
299
+ csl_names = join_with_separator(@config.names_of('csl').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
300
+ authors += " \\\\\n" + ReVIEW::I18n.t('supervisor_with_label', csl_names)
324
301
  end
325
- if @config["trl"].present?
326
- trl_names = join_with_separator(@config.names_of("trl").map{|s| escape_latex(s)}, ReVIEW::I18n.t("names_splitter"))
327
- authors += " \\\\\n"+ ReVIEW::I18n.t("translator_with_label", trl_names)
302
+ if @config['trl'].present?
303
+ trl_names = join_with_separator(@config.names_of('trl').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
304
+ authors += " \\\\\n" + ReVIEW::I18n.t('translator_with_label', trl_names)
328
305
  end
329
306
  authors
330
307
  end
331
308
 
332
309
  def make_history_list
333
310
  buf = []
334
- if @config["history"]
335
- @config["history"].each_with_index do |items, edit|
311
+ if @config['history']
312
+ @config['history'].each_with_index do |items, edit|
336
313
  items.each_with_index do |item, rev|
337
- editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
338
- revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
314
+ editstr = edit == 0 ? ReVIEW::I18n.t('first_edition') : ReVIEW::I18n.t('nth_edition', (edit + 1).to_s)
315
+ revstr = ReVIEW::I18n.t('nth_impression', (rev + 1).to_s)
339
316
  if item =~ /\A\d+\-\d+\-\d+\Z/
340
- buf << ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])
317
+ buf << ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])
341
318
  elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/
342
319
  # custom date with string
343
- item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
344
- buf << ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])
345
- end
320
+ item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) { |m| buf << ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]]) }
346
321
  else
347
322
  # free format
348
323
  buf << item
349
324
  end
350
325
  end
351
326
  end
352
- elsif @config["date"]
353
- buf << ReVIEW::I18n.t("published_by2",
354
- date_to_s(@config["date"]))
327
+ elsif @config['date']
328
+ buf << ReVIEW::I18n.t('published_by2', date_to_s(@config['date']))
355
329
  end
356
330
  buf
357
331
  end
@@ -359,63 +333,61 @@ module ReVIEW
359
333
  def date_to_s(date)
360
334
  require 'date'
361
335
  d = Date.parse(date)
362
- d.strftime(ReVIEW::I18n.t("date_format"))
336
+ d.strftime(ReVIEW::I18n.t('date_format'))
363
337
  end
364
338
 
365
- def get_template
366
- dclass = @config["texdocumentclass"] || []
367
- @documentclass = dclass[0] || "jsbook"
368
- @documentclassoption = dclass[1] || "uplatex,oneside"
339
+ def template_content
340
+ dclass = @config['texdocumentclass'] || []
341
+ @documentclass = dclass[0] || 'jsbook'
342
+ @documentclassoption = dclass[1] || 'uplatex,oneside'
369
343
 
370
344
  @okuduke = make_colophon
371
345
  @authors = make_authors
372
346
 
373
- @custom_titlepage = make_custom_page(@config["cover"]) || make_custom_page(@config["coverfile"])
374
- @custom_originaltitlepage = make_custom_page(@config["originaltitlefile"])
375
- @custom_creditpage = make_custom_page(@config["creditfile"])
347
+ @custom_titlepage = make_custom_page(@config['cover']) || make_custom_page(@config['coverfile'])
348
+ @custom_originaltitlepage = make_custom_page(@config['originaltitlefile'])
349
+ @custom_creditpage = make_custom_page(@config['creditfile'])
376
350
 
377
- @custom_profilepage = make_custom_page(@config["profile"])
378
- @custom_advfilepage = make_custom_page(@config["advfile"])
379
- if @config["colophon"] && @config["colophon"].kind_of?(String)
380
- @custom_colophonpage = make_custom_page(@config["colophon"])
381
- end
382
- @custom_backcoverpage = make_custom_page(@config["backcover"])
351
+ @custom_profilepage = make_custom_page(@config['profile'])
352
+ @custom_advfilepage = make_custom_page(@config['advfile'])
353
+ @custom_colophonpage = make_custom_page(@config['colophon']) if @config['colophon'] && @config['colophon'].is_a?(String)
354
+ @custom_backcoverpage = make_custom_page(@config['backcover'])
383
355
 
384
- if @config["pubhistory"]
385
- warn "pubhistory is oboleted. use history."
386
- else
387
- @config["pubhistory"] = make_history_list.join("\n")
388
- end
389
- if @documentclass == "ubook" || @documentclass == "utbook"
390
- @coverimageoption = "width=\\textheight,height=\\textwidth,keepaspectratio,angle=90"
356
+ if @config['pubhistory']
357
+ warn 'pubhistory is oboleted. use history.'
391
358
  else
392
- @coverimageoption = "width=\\textwidth,height=\\textheight,keepaspectratio"
359
+ @config['pubhistory'] = make_history_list.join("\n")
393
360
  end
394
361
 
362
+ @coverimageoption =
363
+ if @documentclass == 'ubook' || @documentclass == 'utbook'
364
+ 'width=\\textheight,height=\\textwidth,keepaspectratio,angle=90'
365
+ else
366
+ 'width=\\textwidth,height=\\textheight,keepaspectratio'
367
+ end
368
+
395
369
  @locale_latex = {}
396
- part_tuple = I18n.get("part").split(/\%[A-Za-z]{1,3}/, 2)
397
- chapter_tuple = I18n.get("chapter").split(/\%[A-Za-z]{1,3}/, 2)
398
- appendix_tuple = I18n.get("appendix").split(/\%[A-Za-z]{1,3}/, 2)
399
- @locale_latex["prepartname"] = part_tuple[0]
400
- @locale_latex["postpartname"] = part_tuple[1]
401
- @locale_latex["prechaptername"] = chapter_tuple[0]
402
- @locale_latex["postchaptername"] = chapter_tuple[1]
403
- @locale_latex["preappendixname"] = appendix_tuple[0]
404
- @locale_latex["postappendixname"] = appendix_tuple[1]
370
+ part_tuple = I18n.get('part').split(/\%[A-Za-z]{1,3}/, 2)
371
+ chapter_tuple = I18n.get('chapter').split(/\%[A-Za-z]{1,3}/, 2)
372
+ appendix_tuple = I18n.get('appendix').split(/\%[A-Za-z]{1,3}/, 2)
373
+ @locale_latex['prepartname'] = part_tuple[0]
374
+ @locale_latex['postpartname'] = part_tuple[1]
375
+ @locale_latex['prechaptername'] = chapter_tuple[0]
376
+ @locale_latex['postchaptername'] = chapter_tuple[1]
377
+ @locale_latex['preappendixname'] = appendix_tuple[0]
378
+ @locale_latex['postappendixname'] = appendix_tuple[1]
405
379
 
406
380
  template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
407
- layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
408
- if File.exist?(layout_file)
409
- template = layout_file
410
- end
381
+ layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
382
+ template = layout_file if File.exist?(layout_file)
411
383
 
412
- @texcompiler = File.basename(@config["texcommand"], ".*")
384
+ @texcompiler = File.basename(@config['texcommand'], '.*')
413
385
 
414
386
  erb = ReVIEW::Template.load(template, '-')
415
387
  erb.result(binding)
416
388
  end
417
389
 
418
- def copyStyToDir(dirname, copybase, extname = "sty")
390
+ def copy_sty(dirname, copybase, extname = 'sty')
419
391
  unless File.directory?(dirname)
420
392
  warn "No such directory - #{dirname}"
421
393
  return
@@ -423,7 +395,7 @@ module ReVIEW
423
395
 
424
396
  Dir.open(dirname) do |dir|
425
397
  dir.each do |fname|
426
- if File.extname(fname).downcase == "."+extname
398
+ if File.extname(fname).downcase == '.' + extname
427
399
  FileUtils.mkdir_p(copybase)
428
400
  FileUtils.cp File.join(dirname, fname), copybase
429
401
  end
@@ -432,15 +404,13 @@ module ReVIEW
432
404
  end
433
405
 
434
406
  def call_hook(hookname)
435
- if @config["pdfmaker"].instance_of?(Hash) && @config["pdfmaker"][hookname]
436
- hook = File.absolute_path(@config["pdfmaker"][hookname], @basehookdir)
437
- if ENV["REVIEW_SAFE_MODE"].to_i & 1 > 0
438
- warn "hook configuration is prohibited in safe mode. ignored."
439
- else
440
- system_or_raise("#{hook} #{Dir.pwd} #{@basehookdir}")
441
- end
407
+ return if !@config['pdfmaker'].is_a?(Hash) || @config['pdfmaker'][hookname].nil?
408
+ hook = File.absolute_path(@config['pdfmaker'][hookname], @basehookdir)
409
+ if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
410
+ warn 'hook configuration is prohibited in safe mode. ignored.'
411
+ else
412
+ system_or_raise("#{hook} #{Dir.pwd} #{@basehookdir}")
442
413
  end
443
414
  end
444
415
  end
445
416
  end
446
-