review 2.0.0.beta1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -1
  3. data/.rubocop_todo.yml +617 -0
  4. data/.travis.yml +16 -1
  5. data/ChangeLog +48 -0
  6. data/Dockerfile +22 -0
  7. data/Gemfile +0 -1
  8. data/README.md +97 -0
  9. data/Rakefile +10 -11
  10. data/appveyor.yml +9 -0
  11. data/bin/review +46 -0
  12. data/bin/review-check +8 -21
  13. data/bin/review-compile +26 -43
  14. data/bin/review-index +9 -22
  15. data/bin/review-init +21 -25
  16. data/bin/review-preproc +9 -13
  17. data/bin/review-validate +1 -1
  18. data/bin/review-vol +3 -17
  19. data/bin/review-webmaker +15 -0
  20. data/doc/NEWS.ja.md +534 -0
  21. data/doc/NEWS.md +538 -0
  22. data/doc/catalog.ja.md +10 -18
  23. data/doc/catalog.md +5 -9
  24. data/doc/config.yml.sample +319 -0
  25. data/doc/customize_epub.ja.md +42 -0
  26. data/doc/format.ja.md +320 -288
  27. data/doc/format.md +277 -170
  28. data/doc/format_idg.ja.md +82 -175
  29. data/doc/pdfmaker.ja.md +61 -0
  30. data/doc/pdfmaker.md +65 -0
  31. data/doc/quickstart.ja.md +88 -98
  32. data/doc/quickstart.md +72 -110
  33. data/doc/sample.css +41 -0
  34. data/doc/writing_vertical.ja.md +55 -0
  35. data/doc/writing_vertical.md +5 -0
  36. data/lib/epubmaker/content.rb +3 -3
  37. data/lib/epubmaker/epubcommon.rb +173 -145
  38. data/lib/epubmaker/epubv2.rb +24 -77
  39. data/lib/epubmaker/epubv3.rb +72 -73
  40. data/lib/epubmaker/producer.rb +54 -30
  41. data/lib/lineinput.rb +48 -0
  42. data/lib/review/book.rb +0 -1
  43. data/lib/review/book/base.rb +47 -27
  44. data/lib/review/book/chapter.rb +48 -19
  45. data/lib/review/book/compilable.rb +10 -14
  46. data/lib/review/book/index.rb +10 -19
  47. data/lib/review/book/page_metric.rb +0 -10
  48. data/lib/review/book/part.rb +17 -3
  49. data/lib/review/builder.rb +84 -68
  50. data/lib/review/catalog.rb +5 -1
  51. data/lib/review/compiler.rb +327 -4657
  52. data/lib/review/configure.rb +84 -10
  53. data/lib/review/converter.rb +28 -0
  54. data/lib/review/epubbuilder.rb +1 -1
  55. data/lib/review/epubmaker.rb +142 -158
  56. data/lib/review/ewbbuilder.rb +5 -5
  57. data/lib/review/exception.rb +1 -1
  58. data/lib/review/extentions.rb +1 -1
  59. data/lib/review/extentions/hash.rb +15 -0
  60. data/lib/review/extentions/string.rb +2 -1
  61. data/lib/review/htmlbuilder.rb +364 -348
  62. data/lib/review/htmltoc.rb +44 -0
  63. data/lib/review/htmlutils.rb +12 -6
  64. data/lib/review/i18n.rb +78 -6
  65. data/lib/review/i18n.yml +7 -4
  66. data/lib/review/idgxmlbuilder.rb +226 -267
  67. data/lib/review/latexbuilder.rb +281 -274
  68. data/lib/review/latexutils.rb +56 -49
  69. data/lib/review/makerhelper.rb +8 -4
  70. data/lib/review/markdownbuilder.rb +80 -124
  71. data/lib/review/pdfmaker.rb +197 -138
  72. data/lib/review/preprocessor.rb +16 -67
  73. data/lib/review/template.rb +24 -0
  74. data/lib/review/textbuilder.rb +1 -1
  75. data/lib/review/textutils.rb +18 -24
  76. data/lib/review/tocparser.rb +51 -106
  77. data/lib/review/tocprinter.rb +61 -117
  78. data/lib/review/topbuilder.rb +119 -126
  79. data/lib/review/unfold.rb +2 -2
  80. data/lib/review/version.rb +1 -1
  81. data/lib/review/webmaker.rb +302 -0
  82. data/lib/review/webtocprinter.rb +48 -0
  83. data/lib/review/yamlloader.rb +47 -0
  84. data/review.gemspec +3 -3
  85. data/templates/html/layout-html5.html.erb +17 -0
  86. data/templates/html/layout-xhtml1.html.erb +20 -0
  87. data/{lib/review → templates/latex}/layout.tex.erb +107 -115
  88. data/templates/ncx/epubv2.ncx.erb +11 -0
  89. data/templates/opf/epubv2.opf.erb +21 -0
  90. data/templates/opf/epubv3.opf.erb +18 -0
  91. data/templates/web/html/layout-html5.html.erb +56 -0
  92. data/templates/web/html/layout-xhtml1.html.erb +20 -0
  93. data/templates/xml/container.xml.erb +6 -0
  94. data/test/assets/test.xml.erb +3 -0
  95. data/test/assets/test_template.tex +28 -71
  96. data/test/assets/test_template_backmatter.tex +1 -9
  97. data/test/sample-book/src/Rakefile +12 -3
  98. data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
  99. data/test/sample-book/src/config.yml +40 -154
  100. data/test/sample-book/src/style-web.css +45 -0
  101. data/test/sample-book/src/style.css +23 -1
  102. data/test/test.re +1 -1
  103. data/test/test_book.rb +15 -17
  104. data/test/test_book_chapter.rb +2 -80
  105. data/test/test_book_part.rb +1 -1
  106. data/test/test_builder.rb +28 -6
  107. data/test/test_catalog.rb +17 -0
  108. data/test/test_compiler.rb +14 -59
  109. data/test/test_configure.rb +94 -0
  110. data/test/test_converter.rb +21 -0
  111. data/test/test_epub3maker.rb +155 -3
  112. data/test/test_epubmaker.rb +245 -30
  113. data/test/test_epubmaker_cmd.rb +2 -2
  114. data/test/test_extentions_hash.rb +60 -0
  115. data/test/test_helper.rb +4 -47
  116. data/test/test_htmlbuilder.rb +282 -175
  117. data/test/test_htmltoc.rb +33 -0
  118. data/test/test_i18n.rb +134 -70
  119. data/test/test_idgxmlbuilder.rb +58 -39
  120. data/test/test_latexbuilder.rb +132 -14
  121. data/test/test_lineinput.rb +5 -26
  122. data/test/test_makerhelper.rb +6 -4
  123. data/test/test_markdownbuilder.rb +23 -5
  124. data/test/test_pdfmaker.rb +86 -20
  125. data/test/test_pdfmaker_cmd.rb +1 -3
  126. data/test/test_review_ext.rb +1 -1
  127. data/test/test_template.rb +27 -0
  128. data/test/test_textutils.rb +36 -0
  129. data/test/test_tocparser.rb +25 -0
  130. data/test/test_topbuilder.rb +34 -2
  131. data/test/test_yamlloader.rb +188 -0
  132. metadata +71 -29
  133. data/README.rdoc +0 -81
  134. data/bin/review-epubmaker-legacy +0 -1024
  135. data/doc/ruby-uuid/README +0 -11
  136. data/doc/ruby-uuid/README.ja +0 -34
  137. data/lib/review/compiler/literals_1_8.kpeg +0 -19
  138. data/lib/review/compiler/literals_1_8.rb +0 -432
  139. data/lib/review/compiler/literals_1_9.kpeg +0 -22
  140. data/lib/review/compiler/literals_1_9.rb +0 -435
  141. data/lib/review/extentions/array.rb +0 -25
  142. data/lib/review/htmllayout.rb +0 -41
  143. data/lib/review/inaobuilder.rb +0 -357
  144. data/lib/review/location.rb +0 -24
  145. data/lib/review/node.rb +0 -267
  146. data/lib/review/review.kpeg +0 -724
  147. data/lib/uuid.rb +0 -312
  148. data/rubocop-todo.yml +0 -456
  149. data/test/test_inaobuilder.rb +0 -247
  150. data/test/test_uuid.rb +0 -157
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # Copyright (c) 2010-2015 Kenshi Muto and Masayoshi Takahashi
3
+ # Copyright (c) 2010-2016 Kenshi Muto and Masayoshi Takahashi
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
@@ -11,9 +11,17 @@ require 'optparse'
11
11
  require 'yaml'
12
12
  require 'fileutils'
13
13
  require 'erb'
14
+ require 'tmpdir'
14
15
 
15
- require 'review'
16
16
  require 'review/i18n'
17
+ require 'review/book'
18
+ require 'review/configure'
19
+ require 'review/converter'
20
+ require 'review/latexbuilder'
21
+ require 'review/yamlloader'
22
+ require 'review/version'
23
+ require 'review/makerhelper'
24
+ require 'review/template'
17
25
 
18
26
 
19
27
  module ReVIEW
@@ -22,8 +30,11 @@ module ReVIEW
22
30
  include FileUtils
23
31
  include ReVIEW::LaTeXUtils
24
32
 
33
+ attr_accessor :config, :basedir
34
+
25
35
  def initialize
26
- @basedir = Dir.pwd
36
+ @basedir = nil
37
+ @input_files = Hash.new{|h, key| h[key] = ""}
27
38
  end
28
39
 
29
40
  def system_or_raise(*args)
@@ -39,13 +50,25 @@ module ReVIEW
39
50
  $stderr.puts "#{File.basename($0, '.*')}: warning: #{msg}"
40
51
  end
41
52
 
42
- def check_book(config)
43
- pdf_file = config["bookname"]+".pdf"
44
- File.unlink(pdf_file) if File.exist?(pdf_file)
53
+ def pdf_filepath
54
+ File.join(@basedir, @config["bookname"]+".pdf")
55
+ end
56
+
57
+ def remove_old_file
58
+ FileUtils.rm_f(pdf_filepath)
45
59
  end
46
60
 
47
- def build_path(config)
48
- "./#{config["bookname"]}-pdf"
61
+ def build_path
62
+ if @config["debug"]
63
+ path = "#{@config["bookname"]}-pdf"
64
+ if File.exist?(path)
65
+ FileUtils.rm_rf(path, :secure => true)
66
+ end
67
+ Dir.mkdir(path)
68
+ return path
69
+ else
70
+ return Dir.mktmpdir("#{@config["bookname"]}-pdf-")
71
+ end
49
72
  end
50
73
 
51
74
  def check_compile_status(ignore_errors)
@@ -89,120 +112,114 @@ module ReVIEW
89
112
  end
90
113
 
91
114
  def execute(*args)
92
- config = ReVIEW::Configure.values
115
+ @config = ReVIEW::Configure.values
116
+ @config.maker = "pdfmaker"
93
117
  cmd_config, yamlfile = parse_opts(args)
94
-
95
- config.merge!(YAML.load_file(yamlfile))
118
+ loader = ReVIEW::YAMLLoader.new
119
+ @config.deep_merge!(loader.load_file(yamlfile))
96
120
  # YAML configs will be overridden by command line options.
97
- config.merge!(cmd_config)
98
- I18n.setup(config["language"])
99
- generate_pdf(config, yamlfile)
121
+ @config.merge!(cmd_config)
122
+ I18n.setup(@config["language"])
123
+ @basedir = File.dirname(yamlfile)
124
+
125
+ begin
126
+ @config.check_version(ReVIEW::VERSION)
127
+ rescue ReVIEW::ConfigError => e
128
+ warn e.message
129
+ end
130
+ generate_pdf(yamlfile)
100
131
  end
101
132
 
102
- def generate_pdf(config, yamlfile)
103
- check_book(config)
104
- @path = build_path(config)
105
- bookname = config["bookname"]
106
- Dir.mkdir(@path)
107
-
108
- @chaps_fnames = Hash.new{|h, key| h[key] = ""}
109
- @compile_errors = nil
110
-
111
- book = ReVIEW::Book.load(@basedir)
112
- book.config = config
113
- book.parts.each do |part|
114
- if part.name.present?
115
- if part.file?
116
- output_chaps(part.name, config, yamlfile)
117
- @chaps_fnames["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
118
- else
119
- @chaps_fnames["CHAPS"] << %Q|\\part{#{part.name}}\n|
133
+ def generate_pdf(yamlfile)
134
+ remove_old_file
135
+ @path = build_path()
136
+ begin
137
+ @compile_errors = nil
138
+
139
+ book = ReVIEW::Book.load(@basedir)
140
+ book.config = @config
141
+ @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
142
+ book.parts.each do |part|
143
+ if part.name.present?
144
+ if part.file?
145
+ output_chaps(part.name, yamlfile)
146
+ @input_files["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
147
+ else
148
+ @input_files["CHAPS"] << %Q|\\part{#{part.name}}\n|
149
+ end
120
150
  end
121
- end
122
151
 
123
- part.chapters.each do |chap|
124
- filename = File.basename(chap.path, ".*")
125
- output_chaps(filename, config, yamlfile)
126
- @chaps_fnames["PREDEF"] << "\\input{#{filename}.tex}\n" if chap.on_PREDEF?
127
- @chaps_fnames["CHAPS"] << "\\input{#{filename}.tex}\n" if chap.on_CHAPS?
128
- @chaps_fnames["APPENDIX"] << "\\input{#{filename}.tex}\n" if chap.on_APPENDIX?
129
- @chaps_fnames["POSTDEF"] << "\\input{#{filename}.tex}\n" if chap.on_POSTDEF?
152
+ part.chapters.each do |chap|
153
+ filename = File.basename(chap.path, ".*")
154
+ output_chaps(filename, yamlfile)
155
+ @input_files["PREDEF"] << "\\input{#{filename}.tex}\n" if chap.on_PREDEF?
156
+ @input_files["CHAPS"] << "\\input{#{filename}.tex}\n" if chap.on_CHAPS?
157
+ @input_files["APPENDIX"] << "\\input{#{filename}.tex}\n" if chap.on_APPENDIX?
158
+ @input_files["POSTDEF"] << "\\input{#{filename}.tex}\n" if chap.on_POSTDEF?
159
+ end
130
160
  end
131
- end
132
-
133
- check_compile_status(config["ignore-errors"])
134
161
 
135
- config["pre_str"] = @chaps_fnames["PREDEF"]
136
- config["chap_str"] = @chaps_fnames["CHAPS"]
137
- config["appendix_str"] = @chaps_fnames["APPENDIX"]
138
- config["post_str"] = @chaps_fnames["POSTDEF"]
162
+ check_compile_status(@config["ignore-errors"])
139
163
 
140
- config["usepackage"] = ""
141
- if config["texstyle"]
142
- config["usepackage"] = "\\usepackage{#{config['texstyle']}}"
143
- end
164
+ @config["usepackage"] = ""
165
+ if @config["texstyle"]
166
+ @config["usepackage"] = "\\usepackage{#{@config['texstyle']}}"
167
+ end
144
168
 
145
- copy_images("./images", "#{@path}/images")
146
- copyStyToDir(Dir.pwd + "/sty", @path)
147
- copyStyToDir(Dir.pwd + "/sty", @path, "fd")
148
- copyStyToDir(Dir.pwd + "/sty", @path, "cls")
149
- copyStyToDir(Dir.pwd, @path, "tex")
169
+ copy_images("./images", File.join(@path, "images"))
170
+ copyStyToDir(File.join(Dir.pwd, "sty"), @path)
171
+ copyStyToDir(File.join(Dir.pwd, "sty"), @path, "fd")
172
+ copyStyToDir(File.join(Dir.pwd, "sty"), @path, "cls")
173
+ copyStyToDir(Dir.pwd, @path, "tex")
150
174
 
151
- Dir.chdir(@path) {
152
- template = get_template(config)
153
- File.open("./book.tex", "wb"){|f| f.write(template)}
175
+ template = get_template
176
+ Dir.chdir(@path) do
177
+ File.open("./book.tex", "wb"){|f| f.write(template)}
154
178
 
155
- call_hook("hook_beforetexcompile", config)
179
+ call_hook("hook_beforetexcompile")
156
180
 
157
- ## do compile
158
- enc = config["params"].to_s.split(/\s+/).find{|i| i =~ /\A--outencoding=/ }
159
- kanji = 'utf8'
160
- texcommand = "platex"
161
- texoptions = "-kanji=#{kanji}"
162
- dvicommand = "dvipdfmx"
163
- dvioptions = "-d 5"
181
+ ## do compile
182
+ if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
183
+ warn "command configuration is prohibited in safe mode. ignored."
184
+ else
185
+ texcommand = @config["texcommand"] if @config["texcommand"]
186
+ dvicommand = @config["dvicommand"] if @config["dvicommand"]
187
+ dvioptions = @config["dvioptions"] if @config["dvioptions"]
188
+ texoptions = @config["texoptions"] if @config["texoptions"]
189
+ end
190
+ 3.times do
191
+ system_or_raise("#{texcommand} #{texoptions} book.tex")
192
+ end
193
+ call_hook("hook_aftertexcompile")
164
194
 
165
- if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
166
- warn "command configuration is prohibited in safe mode. ignored."
167
- else
168
- texcommand = config["texcommand"] if config["texcommand"]
169
- dvicommand = config["dvicommand"] if config["dvicommand"]
170
- dvioptions = config["dvioptions"] if config["dvioptions"]
171
- if enc
172
- kanji = enc.split(/\=/).last.gsub(/-/, '').downcase
173
- texoptions = "-kanji=#{kanji}"
195
+ if File.exist?("book.dvi")
196
+ system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
174
197
  end
175
- texoptions = config["texoptions"] if config["texoptions"]
176
198
  end
177
- 3.times do
178
- system_or_raise("#{texcommand} #{texoptions} book.tex")
179
- end
180
- call_hook("hook_aftertexcompile", config)
199
+ call_hook("hook_afterdvipdf")
181
200
 
182
- if File.exist?("book.dvi")
183
- system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
184
- end
185
- }
186
- call_hook("hook_afterdvipdf", config)
187
-
188
- FileUtils.cp("#{@path}/book.pdf", "#{@basedir}/#{bookname}.pdf")
201
+ FileUtils.cp(File.join(@path, "book.pdf"), pdf_filepath)
189
202
 
190
- unless config["debug"]
191
- remove_entry_secure @path
203
+ ensure
204
+ unless @config["debug"]
205
+ remove_entry_secure @path
206
+ end
192
207
  end
193
208
  end
194
209
 
195
- def output_chaps(filename, config, yamlfile)
210
+ def output_chaps(filename, yamlfile)
196
211
  $stderr.puts "compiling #{filename}.tex"
197
- cmd = "#{ReVIEW::MakerHelper.bindir}/review-compile --yaml=#{yamlfile} --target=latex --level=#{config["secnolevel"]} --toclevel=#{config["toclevel"]} #{config["params"]} #{filename}.re > #{@path}/#{filename}.tex"
198
- if system cmd
199
- # OK
200
- else
212
+ begin
213
+ @converter.convert(filename+".re", File.join(@path, filename+".tex"))
214
+ rescue => e
201
215
  @compile_errors = true
202
- warn cmd
216
+ warn "compile error in #{filename}.tex (#{e.class})"
217
+ warn e.message
203
218
  end
204
219
  end
205
220
 
221
+ # PDFMaker#copy_images should copy image files _AND_ execute extractbb (or ebb).
222
+ #
206
223
  def copy_images(from, to)
207
224
  if File.exist?(from)
208
225
  Dir.mkdir(to)
@@ -237,89 +254,131 @@ module ReVIEW
237
254
  end
238
255
  end
239
256
 
240
- def make_colophon_role(role, config)
241
- if config[role].present?
242
- return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(config[role], ReVIEW::I18n.t("names_splitter")))} \\\\\n"
257
+ def make_colophon_role(role)
258
+ if @config[role].present?
259
+ initialize_metachars(@config["texcommand"])
260
+ return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config.names_of(role), ReVIEW::I18n.t("names_splitter")))} \\\\\n"
243
261
  else
244
262
  ""
245
263
  end
246
264
  end
247
265
 
248
- def make_colophon(config)
266
+ def make_colophon
249
267
  colophon = ""
250
- config["colophon_order"].each do |role|
251
- colophon += make_colophon_role(role, config)
268
+ @config["colophon_order"].each do |role|
269
+ colophon += make_colophon_role(role)
252
270
  end
253
271
  colophon
254
272
  end
255
273
 
256
- def make_authors(config)
274
+ def make_authors
257
275
  authors = ""
258
- if config["aut"].present?
259
- author_names = join_with_separator(config["aut"], ReVIEW::I18n.t("names_splitter"))
276
+ if @config["aut"].present?
277
+ author_names = join_with_separator(@config.names_of("aut"), ReVIEW::I18n.t("names_splitter"))
260
278
  authors = ReVIEW::I18n.t("author_with_label", author_names)
261
279
  end
262
- if config["csl"].present?
263
- csl_names = join_with_separator(config["csl"], ReVIEW::I18n.t("names_splitter"))
280
+ if @config["csl"].present?
281
+ csl_names = join_with_separator(@config.names_of("csl"), ReVIEW::I18n.t("names_splitter"))
264
282
  authors += " \\\\\n"+ ReVIEW::I18n.t("supervisor_with_label", csl_names)
265
283
  end
266
- if config["trl"].present?
267
- trl_names = join_with_separator(config["trl"], ReVIEW::I18n.t("names_splitter"))
284
+ if @config["trl"].present?
285
+ trl_names = join_with_separator(@config.names_of("trl"), ReVIEW::I18n.t("names_splitter"))
268
286
  authors += " \\\\\n"+ ReVIEW::I18n.t("translator_with_label", trl_names)
269
287
  end
270
288
  authors
271
289
  end
272
290
 
273
- def get_template(config)
274
- dclass = config["texdocumentclass"] || []
275
- documentclass = dclass[0] || "jsbook"
276
- documentclassoption = dclass[1] || "oneside"
291
+ def make_history_list
292
+ buf = []
293
+ if @config["history"]
294
+ @config["history"].each_with_index do |items, edit|
295
+ items.each_with_index do |item, rev|
296
+ editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
297
+ revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
298
+ if item =~ /\A\d+\-\d+\-\d+\Z/
299
+ buf << ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])
300
+ else
301
+ # custom date with string
302
+ item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
303
+ buf << ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])
304
+ end
305
+ end
306
+ end
307
+ end
308
+ elsif @config["date"]
309
+ buf << ReVIEW::I18n.t("published_by2",
310
+ date_to_s(@config["date"]))
311
+ end
312
+ buf
313
+ end
314
+
315
+ def date_to_s(date)
316
+ require 'date'
317
+ d = Date.parse(date)
318
+ d.strftime(ReVIEW::I18n.t("date_format"))
319
+ end
277
320
 
278
- okuduke = make_colophon(config)
279
- authors = make_authors(config)
321
+ def get_template
322
+ dclass = @config["texdocumentclass"] || []
323
+ @documentclass = dclass[0] || "jsbook"
324
+ @documentclassoption = dclass[1] || "uplatex,oneside"
280
325
 
281
- custom_titlepage = make_custom_page(config["coverfile"])
282
- custom_originaltitlepage = make_custom_page(config["originaltitlefile"])
283
- custom_creditpage = make_custom_page(config["creditfile"])
326
+ @okuduke = make_colophon
327
+ @authors = make_authors
284
328
 
285
- custom_profilepage = make_custom_page(config["profile"])
286
- custom_advfilepage = make_custom_page(config["advfile"])
287
- if config["colophon"] && config["colophon"].kind_of?(String)
288
- custom_colophonpage = make_custom_page(config["colophon"])
329
+ @custom_titlepage = make_custom_page(@config["cover"]) || make_custom_page(@config["coverfile"])
330
+ @custom_originaltitlepage = make_custom_page(@config["originaltitlefile"])
331
+ @custom_creditpage = make_custom_page(@config["creditfile"])
332
+
333
+ @custom_profilepage = make_custom_page(@config["profile"])
334
+ @custom_advfilepage = make_custom_page(@config["advfile"])
335
+ if @config["colophon"] && @config["colophon"].kind_of?(String)
336
+ @custom_colophonpage = make_custom_page(@config["colophon"])
289
337
  end
290
- custom_backcoverpage = make_custom_page(config["backcover"])
338
+ @custom_backcoverpage = make_custom_page(@config["backcover"])
291
339
 
292
- template = File.expand_path('layout.tex.erb', File.dirname(__FILE__))
340
+ if @config["pubhistory"]
341
+ warn "pubhistory is oboleted. use history."
342
+ else
343
+ @config["pubhistory"] = make_history_list.join("\n")
344
+ end
345
+ if @documentclass == "ubook" || @documentclass == "utbook"
346
+ @coverimageoption = "width=\\textheight,height=\\textwidth,keepaspectratio,angle=90"
347
+ else
348
+ @coverimageoption = "width=\\textwidth,height=\\textheight,keepaspectratio"
349
+ end
350
+
351
+ template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
293
352
  layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
294
353
  if File.exist?(layout_file)
295
354
  template = layout_file
296
355
  end
297
356
 
298
- erb = ERB.new(File.open(template).read)
299
- values = config # must be 'values' for legacy files
357
+ @texcompiler = File.basename(@config["texcommand"], ".*")
358
+
359
+ erb = ReVIEW::Template.load(template, '-')
300
360
  erb.result(binding)
301
361
  end
302
362
 
303
363
  def copyStyToDir(dirname, copybase, extname = "sty")
304
364
  unless File.directory?(dirname)
305
- $stderr.puts "No such directory - #{dirname}"
365
+ warn "No such directory - #{dirname}"
306
366
  return
307
367
  end
308
368
 
309
- Dir.open(dirname) {|dir|
310
- dir.each {|fname|
311
- next if fname =~ /^\./
312
- if fname =~ /\.(#{extname})$/i
313
- Dir.mkdir(copybase) unless File.exist?(copybase)
314
- FileUtils.cp "#{dirname}/#{fname}", copybase
369
+ Dir.open(dirname) do |dir|
370
+ dir.each do |fname|
371
+ if File.extname(fname).downcase == "."+extname
372
+ FileUtils.mkdir_p(copybase)
373
+ FileUtils.cp File.join(dirname, fname), copybase
315
374
  end
316
- }
317
- }
375
+ end
376
+ end
318
377
  end
319
378
 
320
- def call_hook(hookname, config)
321
- if config["pdfmaker"].instance_of?(Hash) && config["pdfmaker"][hookname]
322
- hook = File.absolute_path(config["pdfmaker"][hookname], @basedir)
379
+ def call_hook(hookname)
380
+ if @config["pdfmaker"].instance_of?(Hash) && @config["pdfmaker"][hookname]
381
+ hook = File.absolute_path(@config["pdfmaker"][hookname], @basedir)
323
382
  if ENV["REVIEW_SAFE_MODE"].to_i & 1 > 0
324
383
  warn "hook configuration is prohibited in safe mode. ignored."
325
384
  else
@@ -24,24 +24,10 @@ module ReVIEW
24
24
  end
25
25
 
26
26
  def warn(msg)
27
- if @config["outencoding"] =~ /^EUC$/
28
- msg = NKF.nkf("-W -e", msg)
29
- elsif @config["outencoding"] =~ /^SJIS$/
30
- msg = NKF.nkf("-W -s", msg)
31
- elsif @config["outencoding"] =~ /^JIS$/
32
- msg = NKF.nkf("-W -j", msg)
33
- end
34
27
  $stderr.puts "#{location()}: warning: #{msg}"
35
28
  end
36
29
 
37
30
  def error(msg)
38
- if @config["outencoding"] =~ /^EUC$/
39
- msg = NKF.nkf("-W -e", msg)
40
- elsif @config["outencoding"] =~ /^SJIS$/
41
- msg = NKF.nkf("-W -s", msg)
42
- elsif @config["outencoding"] =~ /^JIS$/
43
- msg = NKF.nkf("-W -j", msg)
44
- end
45
31
  @errutils_err = true
46
32
  raise ApplicationError, "#{location()}: #{msg}"
47
33
  end
@@ -148,7 +134,7 @@ module ReVIEW
148
134
  path = expand(direc.arg)
149
135
  ent = @repository.fetch_file(path)
150
136
  ent = evaluate(path, ent) if direc['eval']
151
- replace_block f, line, ent, false # FIXME: turn off lineno: tmp
137
+ replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
152
138
 
153
139
  when /\A\#@map(?:range)?/
154
140
  direc = parse_directive(line, 2, 'unindent')
@@ -156,7 +142,7 @@ module ReVIEW
156
142
  ent = @repository.fetch_range(path, direc.args[1]) or
157
143
  error "unknown range: #{path}: #{direc.args[1]}"
158
144
  ent = (direc['unindent'] ? unindent(ent, direc['unindent']) : ent)
159
- replace_block f, line, ent, false # FIXME: turn off lineno: tmp
145
+ replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
160
146
 
161
147
  when /\A\#@end/
162
148
  error 'unbaranced #@end'
@@ -167,7 +153,7 @@ module ReVIEW
167
153
  warn "unkown directive: #{line.strip}" unless known_directive?(op)
168
154
  @f.print line
169
155
 
170
- when /\A\s*\z/ # empty line
156
+ when /\A\s*\z/ # empty line
171
157
  @f.puts
172
158
  else
173
159
  @f.print line
@@ -175,42 +161,17 @@ module ReVIEW
175
161
  end
176
162
  end
177
163
 
178
- private
179
-
180
164
  KNOWN_DIRECTIVES = %w( require provide warn ok )
181
165
 
182
166
  def known_directive?(op)
183
167
  KNOWN_DIRECTIVES.index(op)
184
168
  end
185
169
 
186
- def convert_outencoding(*s)
187
- ine = ""
188
- if @config["inencoding"] =~ /^EUC$/i
189
- ine = "-E,"
190
- elsif @config["inencoding"] =~ /^SJIS$/i
191
- ine = "-S,"
192
- elsif @config["inencoding"] =~ /^JIS$/i
193
- ine = "-J,"
194
- elsif @config["inencoding"] =~ /^UTF\-8$/i
195
- ine = "-W,"
196
- end
197
-
198
- if @config["outencoding"] =~ /^EUC$/i
199
- NKF.nkf("#{ine} -m0x -e", *s)
200
- elsif @config["outencoding"] =~ /^SJIS$/i
201
- NKF.nkf("#{ine} -m0x -s", *s)
202
- elsif @config["outencoding"] =~ /^JIS$/i
203
- NKF.nkf("#{ine} -m0x -j", *s)
204
- else
205
- NKF.nkf("#{ine} -m0x -w", *s)
206
- end
207
- end
208
-
209
170
  def replace_block(f, directive_line, newlines, with_lineno)
210
171
  @f.print directive_line
211
172
  newlines.each do |line|
212
173
  print_number line.number if with_lineno
213
- @f.print convert_outencoding(line.string)
174
+ @f.print line.string
214
175
  end
215
176
  skip_list f
216
177
  end
@@ -243,8 +204,8 @@ module ReVIEW
243
204
  class Directive
244
205
  def initialize(op, args, opts)
245
206
  @op = op
246
- @args = args
247
- @opts = opts
207
+ @args = args
208
+ @opts = opts
248
209
  end
249
210
 
250
211
  attr_reader :op
@@ -297,12 +258,12 @@ module ReVIEW
297
258
 
298
259
  def optarg_value(spec)
299
260
  case spec
300
- when 'true' then true # [name=true]
301
- when 'false' then false # [name=false]
302
- when 'nil' then nil # [name=nil]
303
- when nil then true # [name]
304
- when /^\d+$/ then $&.to_i # [name=8]
305
- else # [name=val]
261
+ when 'true' then true # [name=true]
262
+ when 'false' then false # [name=false]
263
+ when 'nil' then nil # [name=nil]
264
+ when nil then true # [name]
265
+ when /^\d+$/ then $&.to_i # [name=8]
266
+ else # [name=val]
306
267
  spec
307
268
  end
308
269
  end
@@ -335,18 +296,6 @@ module ReVIEW
335
296
  n == INF_INDENT ? 0 : n
336
297
  end
337
298
 
338
- def check_ruby_syntax(rbfile)
339
- status = spawn {
340
- exec("ruby -c #{rbfile} 2>&1 > /dev/null")
341
- }
342
- error "syntax check failed: #{rbfile}" unless status.exitstatus == 0
343
- end
344
-
345
- def spawn
346
- pid, status = *Process.waitpid2(fork { yield })
347
- status
348
- end
349
-
350
299
  def evaluate(path, chunk)
351
300
  outputs = get_output("ruby #{path}", false).split(/\n/).map {|s| s.strip }
352
301
  chunk.map {|line|
@@ -443,7 +392,7 @@ module ReVIEW
443
392
  end
444
393
 
445
394
  def git?(fname)
446
- fname =~ /\Agit\|/
395
+ fname.start_with?('git|')
447
396
  end
448
397
 
449
398
  def parse_git_blob(g_obj)
@@ -454,7 +403,7 @@ module ReVIEW
454
403
  end
455
404
 
456
405
  def parse_file(fname)
457
- File.open(fname) {|f|
406
+ File.open(fname, 'r:BOM|utf-8') {|f|
458
407
  init_ErrorUtils f
459
408
  return _parse_file(f)
460
409
  }
@@ -465,7 +414,7 @@ module ReVIEW
465
414
  repo = {'file' => whole}
466
415
  curr = {'WHOLE' => whole}
467
416
  lineno = 1
468
- yacchack = false # remove ';'-only lines.
417
+ yacchack = false # remove ';'-only lines.
469
418
  opened = [['(not opened)', '(not opened)']] * 3
470
419
 
471
420
  f.each do |line|
@@ -510,7 +459,7 @@ module ReVIEW
510
459
  when /(?:\A\#@|\#@@)yacchack/
511
460
  yacchack = true
512
461
 
513
- when /\A\#@-/ # does not increment line number.
462
+ when /\A\#@-/ # does not increment line number.
514
463
  line = canonical($')
515
464
  curr.each_value do |list|
516
465
  list.push Line.new(nil, line)