review 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +43 -1
  3. data/.rubocop_todo.yml +605 -0
  4. data/.travis.yml +9 -0
  5. data/ChangeLog +4 -0
  6. data/Dockerfile +22 -0
  7. data/README.rdoc +1 -1
  8. data/Rakefile +1 -1
  9. data/bin/review-check +8 -21
  10. data/bin/review-compile +9 -15
  11. data/bin/review-epubmaker-legacy +6 -6
  12. data/bin/review-index +2 -13
  13. data/bin/review-preproc +1 -14
  14. data/bin/review-validate +1 -1
  15. data/bin/review-vol +1 -13
  16. data/doc/NEWS.ja.md +22 -0
  17. data/doc/NEWS.md +22 -0
  18. data/doc/quickstart.ja.md +1 -1
  19. data/doc/quickstart.md +1 -1
  20. data/lib/epubmaker/content.rb +3 -3
  21. data/lib/epubmaker/epubcommon.rb +91 -108
  22. data/lib/epubmaker/epubv2.rb +14 -67
  23. data/lib/epubmaker/epubv3.rb +25 -59
  24. data/lib/epubmaker/producer.rb +12 -0
  25. data/lib/review/book/base.rb +12 -4
  26. data/lib/review/book/compilable.rb +1 -3
  27. data/lib/review/book/index.rb +4 -4
  28. data/lib/review/builder.rb +6 -11
  29. data/lib/review/compiler.rb +7 -7
  30. data/lib/review/configure.rb +20 -8
  31. data/lib/review/epubbuilder.rb +1 -1
  32. data/lib/review/epubmaker.rb +52 -122
  33. data/lib/review/ewbbuilder.rb +4 -4
  34. data/lib/review/exception.rb +1 -1
  35. data/lib/review/htmlbuilder.rb +49 -54
  36. data/lib/review/htmltoc.rb +45 -0
  37. data/lib/review/htmlutils.rb +3 -3
  38. data/lib/review/i18n.rb +6 -2
  39. data/lib/review/i18n.yml +1 -1
  40. data/lib/review/idgxmlbuilder.rb +4 -5
  41. data/lib/review/inaobuilder.rb +1 -1
  42. data/lib/review/latexbuilder.rb +2 -2
  43. data/lib/review/latexutils.rb +6 -6
  44. data/lib/review/markdownbuilder.rb +4 -3
  45. data/lib/review/pdfmaker.rb +92 -92
  46. data/lib/review/preprocessor.rb +14 -51
  47. data/lib/review/template.rb +21 -0
  48. data/lib/review/textbuilder.rb +1 -1
  49. data/lib/review/textutils.rb +0 -28
  50. data/lib/review/tocparser.rb +3 -3
  51. data/lib/review/tocprinter.rb +8 -31
  52. data/lib/review/topbuilder.rb +2 -3
  53. data/lib/review/unfold.rb +2 -2
  54. data/lib/review/version.rb +1 -1
  55. data/review.gemspec +2 -1
  56. data/templates/html/layout-html5.html.erb +17 -0
  57. data/templates/html/layout-xhtml1.html.erb +20 -0
  58. data/templates/ncx/epubv2.ncx.erb +11 -0
  59. data/templates/opf/epubv2.opf.erb +21 -0
  60. data/templates/opf/epubv3.opf.erb +18 -0
  61. data/templates/xml/container.xml.erb +6 -0
  62. data/test/assets/test.xml.erb +3 -0
  63. data/test/test.re +1 -1
  64. data/test/test_book.rb +4 -4
  65. data/test/test_book_chapter.rb +0 -76
  66. data/test/test_book_part.rb +1 -1
  67. data/test/test_builder.rb +0 -49
  68. data/test/test_configure.rb +50 -0
  69. data/test/test_htmlbuilder.rb +54 -4
  70. data/test/test_htmltoc.rb +32 -0
  71. data/test/test_i18n.rb +3 -5
  72. data/test/test_idgxmlbuilder.rb +0 -2
  73. data/test/test_inaobuilder.rb +2 -4
  74. data/test/test_latexbuilder.rb +2 -4
  75. data/test/test_lineinput.rb +0 -18
  76. data/test/test_markdownbuilder.rb +5 -4
  77. data/test/test_pdfmaker.rb +11 -10
  78. data/test/test_template.rb +26 -0
  79. data/test/test_topbuilder.rb +0 -2
  80. metadata +35 -4
  81. data/rubocop-todo.yml +0 -456
@@ -62,7 +62,7 @@ module ReVIEW
62
62
  lines.each do |line|
63
63
  if noescape
64
64
  puts detab(line)
65
- elsif /\AC:.*?>(.+)/ =~ line # DOS prompt hack
65
+ elsif /\AC:.*?>(.+)/ =~ line # DOS prompt hack
66
66
  prompt, cmd = *line.split('>', 2)
67
67
  puts "#{escape(prompt)}>//command{#{escape(cmd)}}//}"
68
68
  else
@@ -198,7 +198,7 @@ module ReVIEW
198
198
  # FIXME
199
199
  end
200
200
 
201
- Z_SPACE = "\241\241" # zen-kaku space in EUC-JP
201
+ Z_SPACE = "\241\241" # zen-kaku space in EUC-JP
202
202
 
203
203
  def paragraph(lines)
204
204
  if @noindent
@@ -263,10 +263,10 @@ module ReVIEW
263
263
  if abbr
264
264
  add_index(word) + "//g{#{word}//}" +
265
265
  add_index(abbr) + "(#{abbr}, " +
266
- add_index(eng) + "#{eng})"
266
+ add_index(eng) + "#{eng})"
267
267
  elsif eng
268
268
  add_index(word) + "//g{#{word}//}" +
269
- add_index(eng) + "(#{eng})"
269
+ add_index(eng) + "(#{eng})"
270
270
  else
271
271
  add_index(word) + "//g{#{word}//}"
272
272
  end
@@ -17,5 +17,5 @@ module ReVIEW
17
17
  class CompileError < ApplicationError; end
18
18
  class SyntaxError < CompileError; end
19
19
  class FileNotFound < ApplicationError; end
20
- class KeyError < CompileError; end
20
+ class KeyError < CompileError; end
21
21
  end
@@ -70,7 +70,7 @@ module ReVIEW
70
70
  if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
71
71
  warn "user's layout is prohibited in safe mode. ignored."
72
72
  else
73
- title = convert_outencoding(strip_html(compile_inline(@chapter.title)), @book.config["outencoding"])
73
+ title = strip_html(compile_inline(@chapter.title))
74
74
 
75
75
  toc = ""
76
76
  toc_level = 0
@@ -101,44 +101,21 @@ module ReVIEW
101
101
  end
102
102
 
103
103
  # default XHTML header/footer
104
- header = <<EOT
105
- <?xml version="1.0" encoding="#{@book.config["outencoding"] || "UTF-8"}"?>
106
- EOT
107
- if @book.config["htmlversion"].to_i == 5
108
- header += <<EOT
109
- <!DOCTYPE html>
110
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:#{xmlns_ops_prefix}="http://www.idpf.org/2007/ops" xml:lang="#{@book.config["language"]}">
111
- <head>
112
- <meta charset="#{@book.config["outencoding"] || "UTF-8"}" />
113
- EOT
104
+ @error_messages = error_messages
105
+ @warning_messages = warning_messages
106
+ @title = strip_html(compile_inline(@chapter.title))
107
+ @body = @output.string
108
+ @language = @book.config['language']
109
+ @stylesheets = @book.config["stylesheet"]
110
+
111
+ if @book.htmlversion == 5
112
+ htmlfilename = "layout-html5.html.erb"
114
113
  else
115
- header += <<EOT
116
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
117
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{@book.config["language"]}">
118
- <head>
119
- <meta http-equiv="Content-Type" content="text/html;charset=#{@book.config["outencoding"] || "UTF-8"}" />
120
- <meta http-equiv="Content-Style-Type" content="text/css" />
121
- EOT
122
- end
123
-
124
- unless @book.config["stylesheet"].nil?
125
- @book.config["stylesheet"].each do |style|
126
- header += <<EOT
127
- <link rel="stylesheet" type="text/css" href="#{style}" />
128
- EOT
129
- end
114
+ htmlfilename = "layout-xhtml1.html.erb"
130
115
  end
131
- header += <<EOT
132
- <meta name="generator" content="Re:VIEW" />
133
- <title>#{convert_outencoding(strip_html(compile_inline(@chapter.title)), @book.config["outencoding"])}</title>
134
- </head>
135
- <body>
136
- EOT
137
- footer = <<EOT
138
- </body>
139
- </html>
140
- EOT
141
- header + messages() + convert_outencoding(@output.string, @book.config["outencoding"]) + footer
116
+ tmplfile = File.expand_path('./html/'+htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
117
+ tmpl = ReVIEW::Template.load(tmplfile)
118
+ tmpl.result(binding)
142
119
  end
143
120
 
144
121
  def xmlns_ops_prefix
@@ -177,7 +154,7 @@ EOT
177
154
  "<ul>\n" +
178
155
  @errors.map {|file, line, msg|
179
156
  "<li>#{escape_html(file)}:#{line}: #{escape_html(msg.to_s)}</li>\n"
180
- }.join('') +
157
+ }.join('') +
181
158
  "</ul>\n"
182
159
  end
183
160
 
@@ -373,7 +350,7 @@ EOT
373
350
 
374
351
  def ol_begin
375
352
  if @ol_num
376
- puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
353
+ puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
377
354
  @ol_num = nil
378
355
  else
379
356
  puts '<ol>'
@@ -490,10 +467,18 @@ EOT
490
467
  end
491
468
 
492
469
  def listnum_body(lines, lang)
493
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
494
- lexer = lang
495
- puts highlight(:body => body, :lexer => lexer, :format => 'html',
496
- :options => {:linenos => 'inline', :nowrap => false})
470
+ if highlight?
471
+ body = lines.inject(''){|i, j| i + detab(j) + "\n"}
472
+ lexer = lang
473
+ puts highlight(:body => body, :lexer => lexer, :format => 'html',
474
+ :options => {:linenos => 'inline', :nowrap => false})
475
+ else
476
+ print '<pre class="list">'
477
+ lines.each_with_index do |line, i|
478
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
479
+ end
480
+ puts '</pre>'
481
+ end
497
482
  end
498
483
 
499
484
  def emlist(lines, caption = nil, lang = nil)
@@ -514,10 +499,20 @@ EOT
514
499
  if caption.present?
515
500
  puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
516
501
  end
517
- body = lines.inject(''){|i, j| i + detab(j) + "\n"}
518
- lexer = lang
519
- puts highlight(:body => body, :lexer => lexer, :format => 'html',
520
- :options => {:linenos => 'inline', :nowrap => false})
502
+
503
+ if highlight?
504
+ body = lines.inject(''){|i, j| i + detab(j) + "\n"}
505
+ lexer = lang
506
+ puts highlight(:body => body, :lexer => lexer, :format => 'html',
507
+ :options => {:linenos => 'inline', :nowrap => false})
508
+ else
509
+ print '<pre class="emlist">'
510
+ lines.each_with_index do |line, i|
511
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
512
+ end
513
+ puts '</pre>'
514
+ end
515
+
521
516
  puts '</div>'
522
517
  end
523
518
 
@@ -830,7 +825,7 @@ QUOTE
830
825
  end
831
826
 
832
827
  def compile_ruby(base, ruby)
833
- if @book.config["htmlversion"].to_i == 5
828
+ if @book.htmlversion == 5
834
829
  %Q[<ruby>#{escape_html(base)}<rp>#{I18n.t("ruby_prefix")}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
835
830
  else
836
831
  %Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
@@ -863,7 +858,7 @@ QUOTE
863
858
  end
864
859
 
865
860
  def inline_tti(str)
866
- if @book.config["htmlversion"].to_i == 5
861
+ if @book.htmlversion == 5
867
862
  %Q(<code class="tt"><i>#{escape_html(str)}</i></code>)
868
863
  else
869
864
  %Q(<tt><i>#{escape_html(str)}</i></tt>)
@@ -871,7 +866,7 @@ QUOTE
871
866
  end
872
867
 
873
868
  def inline_ttb(str)
874
- if @book.config["htmlversion"].to_i == 5
869
+ if @book.htmlversion == 5
875
870
  %Q(<code class="tt"><b>#{escape_html(str)}</b></code>)
876
871
  else
877
872
  %Q(<tt><b>#{escape_html(str)}</b></tt>)
@@ -883,7 +878,7 @@ QUOTE
883
878
  end
884
879
 
885
880
  def inline_code(str)
886
- if @book.config["htmlversion"].to_i == 5
881
+ if @book.htmlversion == 5
887
882
  %Q(<code class="inline-code tt">#{escape_html(str)}</code>)
888
883
  else
889
884
  %Q(<tt class="inline-code">#{escape_html(str)}</tt>)
@@ -939,7 +934,7 @@ QUOTE
939
934
  end
940
935
 
941
936
  def inline_bib(id)
942
- %Q(<a href="#{@book.bib_file.gsub(/re\Z/, "html")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>)
937
+ %Q(<a href="#{@book.bib_file.gsub(/\.re\Z/, ".#{@book.config['htmlext']}")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>)
943
938
  end
944
939
 
945
940
  def inline_hd_chap(chap, id)
@@ -1079,7 +1074,7 @@ QUOTE
1079
1074
  end
1080
1075
 
1081
1076
  def inline_tt(str)
1082
- if @book.config["htmlversion"].to_i == 5
1077
+ if @book.htmlversion == 5
1083
1078
  %Q(<code class="tt">#{escape_html(str)}</code>)
1084
1079
  else
1085
1080
  %Q(<tt>#{escape_html(str)}</tt>)
@@ -1159,4 +1154,4 @@ QUOTE
1159
1154
  end
1160
1155
  end
1161
1156
 
1162
- end # module ReVIEW
1157
+ end # module ReVIEW
@@ -0,0 +1,45 @@
1
+ require 'review'
2
+ module ReVIEW
3
+ class HTMLToc
4
+ def initialize(basedir)
5
+ @tochtmltxt = "toc-html.txt"
6
+ @basedir = basedir
7
+ end
8
+
9
+ def add_item(level, filename, title, args)
10
+ args_str = encode_args(args)
11
+ line = [level, filename, title, args_str].join("\t")
12
+ File.open(tocfilename, "a") do |f|
13
+ f.write "#{line}\n"
14
+ end
15
+ end
16
+
17
+ def each_item
18
+ File.open(tocfilename) do |f|
19
+ f.each_line do |line|
20
+ level, file, title, args_str = line.chomp.split("\t")
21
+ args = decode_args(args_str)
22
+ yield level, file, title, args
23
+ end
24
+ end
25
+ end
26
+
27
+ def tocfilename
28
+ File.join(@basedir, @tochtmltxt)
29
+ end
30
+
31
+ def decode_args(args_str)
32
+ args = Hash.new
33
+ args_str.split(/,\s*/).each do |pair|
34
+ key, val = pair.split("=")
35
+ args[key.to_sym] = val
36
+ end
37
+ args
38
+ end
39
+
40
+ def encode_args(args)
41
+ args.map{|k,v| "#{k}=#{v}"}.join(",")
42
+ end
43
+ end
44
+ end
45
+
@@ -40,7 +40,7 @@ module ReVIEW
40
40
  str.gsub('-', '&#45;')
41
41
  end
42
42
 
43
- def highlight_pygments?
43
+ def highlight?
44
44
  @book.config["pygments"].present? ||
45
45
  @book.config["highlight"] && @book.config["highlight"]["html"] == "pygments"
46
46
  end
@@ -58,7 +58,7 @@ module ReVIEW
58
58
  if ops[:options] && ops[:options].kind_of?(Hash)
59
59
  options.merge!(ops[:options])
60
60
  end
61
- return body if !highlight_pygments?
61
+ return body if !highlight?
62
62
 
63
63
  begin
64
64
  require 'pygments'
@@ -87,4 +87,4 @@ module ReVIEW
87
87
  end
88
88
  end
89
89
 
90
- end # module ReVIEW
90
+ end # module ReVIEW
data/lib/review/i18n.rb CHANGED
@@ -38,7 +38,7 @@ module ReVIEW
38
38
  end
39
39
 
40
40
  class << self
41
- alias v t ## for EPUBMaker backward compatibility
41
+ alias_method :v, :t ## for EPUBMaker backward compatibility
42
42
  end
43
43
 
44
44
  def self.update(user_i18n, locale = nil)
@@ -65,7 +65,11 @@ module ReVIEW
65
65
  locale = user_i18n["locale"]
66
66
  if locale
67
67
  user_i18n.delete("locale")
68
- @store[locale].merge!(user_i18n)
68
+ if @store[locale]
69
+ @store[locale].merge!(user_i18n)
70
+ else
71
+ @store[locale] = user_i18n
72
+ end
69
73
  else
70
74
  user_i18n.each do |key, values|
71
75
  raise KeyError, "Invalid locale file: #{path}" unless values.kind_of? Hash
data/lib/review/i18n.yml CHANGED
@@ -116,7 +116,7 @@ en:
116
116
  profiletitle: "Profile"
117
117
  backcovertitle: "Back Cover"
118
118
 
119
- zh_TW:
119
+ zh-TW:
120
120
  image: 圖
121
121
  table: 表
122
122
  list: List
@@ -541,7 +541,7 @@ module ReVIEW
541
541
  totallength = 0
542
542
  cellwidth.size.times do |n|
543
543
  cellwidth[n] = cellwidth[n].to_f / 0.351 # mm -> pt
544
- totallength = totallength + cellwidth[n]
544
+ totallength += cellwidth[n]
545
545
  warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
546
546
  end
547
547
  if cellwidth.size < col
@@ -1084,7 +1084,7 @@ module ReVIEW
1084
1084
  lines.each do |l|
1085
1085
  print l.gsub("&lt;", "<").gsub("&gt;", ">").gsub("&quot;", "\"").gsub("&amp;", "&")
1086
1086
  print "\n" unless lines.length == no
1087
- no = no + 1
1087
+ no += 1
1088
1088
  end
1089
1089
  end
1090
1090
 
@@ -1095,8 +1095,7 @@ module ReVIEW
1095
1095
  def inline_chapref(id)
1096
1096
  chs = ["", "「", "」"]
1097
1097
  unless @book.config["chapref"].nil?
1098
- _chs = convert_inencoding(@book.config["chapref"],
1099
- @book.config["inencoding"]).split(",")
1098
+ _chs = @book.config["chapref"].split(",")
1100
1099
  if _chs.size != 3
1101
1100
  error "--chapsplitter must have exactly 3 parameters with comma."
1102
1101
  else
@@ -1195,4 +1194,4 @@ module ReVIEW
1195
1194
 
1196
1195
  end
1197
1196
 
1198
- end # module ReVIEW
1197
+ end # module ReVIEW
@@ -352,4 +352,4 @@ module ReVIEW
352
352
  end
353
353
  end
354
354
 
355
- end # module ReVIEW
355
+ end # module ReVIEW
@@ -505,7 +505,7 @@ module ReVIEW
505
505
 
506
506
  def th(s)
507
507
  ## use shortstack for @<br>
508
- if /\\\\/i =~ s
508
+ if /\\\\/i =~ s
509
509
  macro('reviewth', macro('shortstack[l]', s))
510
510
  else
511
511
  macro('reviewth', s)
@@ -514,7 +514,7 @@ module ReVIEW
514
514
 
515
515
  def td(s)
516
516
  ## use shortstack for @<br>
517
- if /\\\\/ =~ s
517
+ if /\\\\/ =~ s
518
518
  macro('shortstack[l]', s)
519
519
  else
520
520
  s
@@ -17,18 +17,18 @@ module ReVIEW
17
17
  module LaTeXUtils
18
18
 
19
19
  METACHARS = {
20
- '#' => '\#',
21
- "$" => '\textdollar{}',
20
+ '#' => '\#',
21
+ "$" => '\textdollar{}',
22
22
  '%' => '\%',
23
23
  '&' => '\&',
24
24
  '{' => '\{',
25
25
  '}' => '\}',
26
- '_' => '\textunderscore{}',
26
+ '_' => '\textunderscore{}',
27
27
  '^' => '\textasciicircum{}',
28
28
  '~' => '\textasciitilde{}',
29
29
  '|' => '\textbar{}',
30
- '<' => '\textless{}',
31
- '>' => '\textgreater{}',
30
+ '<' => '\textless{}',
31
+ '>' => '\textgreater{}',
32
32
  "\\" => '\reviewbackslash{}',
33
33
  "-" => '{-}',
34
34
 
@@ -70,7 +70,7 @@ module ReVIEW
70
70
  alias_method :escape, :escape_latex
71
71
 
72
72
  def unescape_latex(str)
73
- metachars_invert_re = Regexp.new(METACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
73
+ metachars_invert_re = Regexp.new(METACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
74
74
  str.gsub(metachars_invert_re) {|s|
75
75
  METACHARS_INVERT[s] or raise "unknown trans char: #{s}"
76
76
  }
@@ -51,9 +51,9 @@ module ReVIEW
51
51
 
52
52
  def list_header(id, caption, lang)
53
53
  if get_chap.nil?
54
- puts %Q[リスト#{@chapter.list(id).number} #{compile_inline(caption)}]
54
+ print %Q[リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n]
55
55
  else
56
- puts %Q[リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}]
56
+ print %Q[リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n]
57
57
  end
58
58
  lang ||= ""
59
59
  puts "```#{lang}"
@@ -103,6 +103,7 @@ module ReVIEW
103
103
  blank
104
104
  if caption
105
105
  puts caption
106
+ print "\n"
106
107
  end
107
108
  lang ||= ""
108
109
  puts "```#{lang}"
@@ -274,4 +275,4 @@ module ReVIEW
274
275
  end
275
276
  end
276
277
 
277
- end # module ReVIEW
278
+ end # module ReVIEW