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,16 +1,14 @@
1
1
  module ReVIEW
2
2
  class HTMLToc
3
3
  def initialize(basedir)
4
- @tochtmltxt = "toc-html.txt"
4
+ @tochtmltxt = 'toc-html.txt'
5
5
  @basedir = basedir
6
6
  end
7
7
 
8
8
  def add_item(level, filename, title, args)
9
9
  args_str = encode_args(args)
10
10
  line = [level, filename, title, args_str].join("\t")
11
- File.open(tocfilename, "a") do |f|
12
- f.write "#{line}\n"
13
- end
11
+ File.open(tocfilename, 'a') { |f| f.write "#{line}\n" }
14
12
  end
15
13
 
16
14
  def each_item
@@ -30,15 +28,14 @@ module ReVIEW
30
28
  def decode_args(args_str)
31
29
  args = {}
32
30
  args_str.split(/,\s*/).each do |pair|
33
- key, val = pair.split("=")
31
+ key, val = pair.split('=')
34
32
  args[key.to_sym] = val
35
33
  end
36
34
  args
37
35
  end
38
36
 
39
37
  def encode_args(args)
40
- args.delete_if {|k,v| v.nil? }.map{|k,v| "#{k}=#{v}"}.join(",")
38
+ args.delete_if { |_k, v| v.nil? }.map { |k, v| "#{k}=#{v}" }.join(',')
41
39
  end
42
40
  end
43
41
  end
44
-
@@ -1,7 +1,6 @@
1
1
  #
2
- # $Id: htmlutils.rb 2227 2006-05-13 00:09:08Z aamine $
3
- #
4
- # Copyright (c) 2002-2006 Minero Aoki
2
+ # Copyright (c) 2006-2017 Minero Aoki, Kenshi Muto
3
+ # 2002-2006 Minero Aoki
5
4
  #
6
5
  # This program is free software.
7
6
  # You can distribute or modify this program under the terms of
@@ -10,18 +9,17 @@
10
9
 
11
10
  require 'cgi/util'
12
11
  module ReVIEW
13
-
14
12
  module HTMLUtils
15
13
  ESC = {
16
14
  '&' => '&',
17
15
  '<' => '&lt;',
18
16
  '>' => '&gt;',
19
17
  '"' => '&quot;'
20
- }
18
+ } # .freeze
21
19
 
22
20
  def escape_html(str)
23
21
  t = ESC
24
- str.gsub(/[&"<>]/) {|c| t[c] }
22
+ str.gsub(/[&"<>]/) { |c| t[c] }
25
23
  end
26
24
 
27
25
  alias_method :escape, :escape_html
@@ -35,7 +33,7 @@ module ReVIEW
35
33
  alias_method :unescape, :unescape_html
36
34
 
37
35
  def strip_html(str)
38
- str.gsub(/<\/?[^>]*>/, "")
36
+ str.gsub(%r{</?[^>]*>}, '')
39
37
  end
40
38
 
41
39
  def escape_comment(str)
@@ -43,40 +41,40 @@ module ReVIEW
43
41
  end
44
42
 
45
43
  def highlight?
46
- @book.config["highlight"] &&
47
- @book.config["highlight"]["html"]
44
+ @book.config['highlight'] &&
45
+ @book.config['highlight']['html']
48
46
  end
49
47
 
50
48
  def highlight(ops)
51
- if @book.config["pygments"].present?
52
- raise ReVIEW::ConfigError, "'pygments:' in config.yml is obsoleted."
49
+ if @book.config['pygments'].present?
50
+ raise ReVIEW::ConfigError, %Q('pygments:' in config.yml is obsoleted.)
53
51
  end
54
- return ops[:body].to_s if !highlight?
52
+ return ops[:body].to_s unless highlight?
55
53
 
56
- if @book.config["highlight"]["html"] == "pygments"
54
+ if @book.config['highlight']['html'] == 'pygments'
57
55
  highlight_pygments(ops)
58
- elsif @book.config["highlight"]["html"] == "rouge"
56
+ elsif @book.config['highlight']['html'] == 'rouge'
59
57
  highlight_rouge(ops)
60
58
  else
61
- raise ReVIEW::ConfigError, "unknown highlight method #{@book.config["highlight"]["html"]} in config.yml."
59
+ raise ReVIEW::ConfigError, "unknown highlight method #{@book.config['highlight']['html']} in config.yml."
62
60
  end
63
61
  end
64
62
 
65
63
  def highlight_pygments(ops)
66
64
  body = ops[:body] || ''
67
- if @book.config["highlight"] && @book.config["highlight"]["lang"]
68
- lexer = @book.config["highlight"]["lang"] # default setting
65
+ if @book.config['highlight'] && @book.config['highlight']['lang']
66
+ lexer = @book.config['highlight']['lang'] # default setting
69
67
  else
70
68
  lexer = 'text'
71
69
  end
72
70
  lexer = ops[:lexer] if ops[:lexer].present?
73
71
  format = ops[:format] || ''
74
- options = {:nowrap => true, :noclasses => true}
72
+ options = { nowrap: true, noclasses: true }
75
73
  if ops[:linenum]
76
74
  options[:nowrap] = false
77
75
  options[:linenos] = 'inline'
78
76
  end
79
- if ops[:options] && ops[:options].kind_of?(Hash)
77
+ if ops[:options] && ops[:options].is_a?(Hash)
80
78
  options.merge!(ops[:options])
81
79
  end
82
80
 
@@ -84,9 +82,9 @@ module ReVIEW
84
82
  require 'pygments'
85
83
  begin
86
84
  Pygments.highlight(unescape_html(body),
87
- :options => options,
88
- :formatter => format,
89
- :lexer => lexer)
85
+ options: options,
86
+ formatter: format,
87
+ lexer: lexer)
90
88
  rescue MentosError
91
89
  body
92
90
  end
@@ -99,12 +97,12 @@ module ReVIEW
99
97
  body = ops[:body] || ''
100
98
  if ops[:lexer].present?
101
99
  lexer = ops[:lexer]
102
- elsif @book.config["highlight"] && @book.config["highlight"]["lang"]
103
- lexer = @book.config["highlight"]["lang"] # default setting
100
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
101
+ lexer = @book.config['highlight']['lang'] # default setting
104
102
  else
105
103
  lexer = 'text'
106
104
  end
107
- format = ops[:format] || ''
105
+ # format = ops[:format] || ''
108
106
 
109
107
  first_line_num = 1 ## default
110
108
  if ops[:options] && ops[:options][:linenostart]
@@ -115,11 +113,11 @@ module ReVIEW
115
113
  lexer = Rouge::Lexer.find(lexer)
116
114
  raise "unknown lexer #{lexer}" unless lexer
117
115
 
118
- formatter = Rouge::Formatters::HTML.new(:css_class => 'highlight')
116
+ formatter = Rouge::Formatters::HTML.new(css_class: 'highlight')
119
117
  if ops[:linenum]
120
118
  formatter = Rouge::Formatters::HTMLTable.new(formatter,
121
- :table_class => 'highlight rouge-table',
122
- :start_line => first_line_num)
119
+ table_class: 'highlight rouge-table',
120
+ start_line: first_line_num)
123
121
  end
124
122
  raise "unknown formatter #{formatter}" unless formatter
125
123
 
@@ -129,13 +127,12 @@ module ReVIEW
129
127
 
130
128
  def normalize_id(id)
131
129
  if id =~ /\A[a-z][a-z0-9_.-]*\Z/i
132
- return id
130
+ id
133
131
  elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
134
- return "id_#{id}" # dummy prefix
132
+ "id_#{id}" # dummy prefix
135
133
  else
136
- return "id_#{CGI.escape(id.gsub("_", "__")).gsub("%", "_").gsub("+", "-")}" # escape all
134
+ "id_#{CGI.escape(id.gsub('_', '__')).gsub('%', '_').gsub('+', '-')}" # escape all
137
135
  end
138
136
  end
139
137
  end
140
-
141
138
  end # module ReVIEW
@@ -1,20 +1,19 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'yaml'
3
2
 
4
3
  module ReVIEW
5
4
  class I18n
6
- ALPHA_U = %w[0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
7
- ALPHA_L = %w[0 a b c d e f g h i j k l m n o p q r s t u v w x y z]
8
- ROMAN_U = %w[0 I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII]
9
- ROMAN_L = %w[0 i ii iii iv v vi vii viii ix x xi xii xiii xiv xv xvi xvii xviii xix xx xxi xxii xxiii xxiv xxv xxvi xxvii]
10
- ALPHA_UW = %w[0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
11
- ALPHA_LW = %w[0 a b c d e f g h i j k l m n o p q r s t u v w x y z]
12
- ROMAN_UW = %w[0 Ⅰ Ⅱ Ⅲ Ⅳ V Ⅵ Ⅶ Ⅷ Ⅸ X Ⅺ Ⅻ]
13
- ARABIC_UW = %w[〇 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27]
14
- ARABIC_LW = %w[〇 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27]
15
- JAPAN = %w[〇 一 二 三 四 五 六 七 八 九 十 十一 十二 十三 十四 十五 十六 十七 十八 十九 二十 二十一 二十二 二十三 二十四 二十五 二十六 二十七]
16
-
17
- def self.setup(locale="ja", ymlfile = "locale.yml")
5
+ ALPHA_U = %w[0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z].freeze
6
+ ALPHA_L = %w[0 a b c d e f g h i j k l m n o p q r s t u v w x y z].freeze
7
+ ROMAN_U = %w[0 I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII].freeze
8
+ ROMAN_L = %w[0 i ii iii iv v vi vii viii ix x xi xii xiii xiv xv xvi xvii xviii xix xx xxi xxii xxiii xxiv xxv xxvi xxvii].freeze
9
+ ALPHA_UW = %w[0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z].freeze
10
+ ALPHA_LW = %w[0 a b c d e f g h i j k l m n o p q r s t u v w x y z].freeze
11
+ ROMAN_UW = %w[0 Ⅰ Ⅱ Ⅲ Ⅳ V Ⅵ Ⅶ Ⅷ Ⅸ X Ⅺ Ⅻ].freeze
12
+ ARABIC_UW = %w[〇 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27].freeze
13
+ ARABIC_LW = %w[〇 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27].freeze
14
+ JAPAN = %w[〇 一 二 三 四 五 六 七 八 九 十 十一 十二 十三 十四 十五 十六 十七 十八 十九 二十 二十一 二十二 二十三 二十四 二十五 二十六 二十七].freeze
15
+
16
+ def self.setup(locale = 'ja', ymlfile = 'locale.yml')
18
17
  @i18n = ReVIEW::I18n.new(locale)
19
18
 
20
19
  lfile = nil
@@ -22,18 +21,14 @@ module ReVIEW
22
21
  lfile = File.expand_path(ymlfile, Dir.pwd)
23
22
 
24
23
  # backward compatibility
25
- if !File.exist?(lfile) && (ymlfile == "locale.yml") && File.exist?(File.expand_path("locale.yaml", Dir.pwd))
26
- raise ReVIEW::ConfigError, "locale.yaml is obsoleted. Please use locale.yml."
27
- end
24
+ raise ReVIEW::ConfigError, 'locale.yaml is obsoleted. Please use locale.yml.' if !File.exist?(lfile) && (ymlfile == 'locale.yml') && File.exist?(File.expand_path('locale.yaml', Dir.pwd))
28
25
  end
29
26
 
30
- if lfile && File.file?(lfile)
31
- @i18n.update_localefile(lfile)
32
- end
27
+ @i18n.update_localefile(lfile) if lfile && File.file?(lfile)
33
28
  end
34
29
 
35
- def self.i18n(*args)
36
- raise NotImplementedError, "I18n.i18n is obsoleted. Please use I18n.setup(locale, [ymlfile])"
30
+ def self.i18n(*_args)
31
+ raise NotImplementedError, 'I18n.i18n is obsoleted. Please use I18n.setup(locale, [ymlfile])'
37
32
  end
38
33
 
39
34
  def self.t(str, args = nil)
@@ -68,7 +63,7 @@ module ReVIEW
68
63
  end
69
64
 
70
65
  def load_default
71
- load_file(File.expand_path("i18n.yml", File.dirname(__FILE__)))
66
+ load_file(File.expand_path('i18n.yml', File.dirname(__FILE__)))
72
67
  end
73
68
 
74
69
  def load_file(path)
@@ -77,9 +72,9 @@ module ReVIEW
77
72
 
78
73
  def update_localefile(path)
79
74
  user_i18n = YAML.load_file(path)
80
- locale = user_i18n["locale"]
75
+ locale = user_i18n['locale']
81
76
  if locale
82
- user_i18n.delete("locale")
77
+ user_i18n.delete('locale')
83
78
  if @store[locale]
84
79
  @store[locale].merge!(user_i18n)
85
80
  else
@@ -87,7 +82,7 @@ module ReVIEW
87
82
  end
88
83
  else
89
84
  user_i18n.each do |key, values|
90
- raise KeyError, "Invalid locale file: #{path}" unless values.kind_of? Hash
85
+ raise KeyError, "Invalid locale file: #{path}" unless values.is_a? Hash
91
86
  @store[key].merge!(values)
92
87
  end
93
88
  end
@@ -111,56 +106,50 @@ module ReVIEW
111
106
  frmt = @store[@locale][str].dup
112
107
  frmt.gsub!('%%', '##')
113
108
 
114
- if !args.is_a?(Array)
115
- if args.nil? && frmt !~ /\%/
116
- args = []
117
- else
118
- args = [args]
119
- end
109
+ unless args.is_a?(Array)
110
+ args = args.nil? && frmt !~ /\%/ ? [] : [args]
120
111
  end
121
112
 
122
113
  percents = frmt.scan(/%[A-Za-z]{1,3}/)
123
114
  remove_args = []
124
115
  percents.each_with_index do |i, idx|
125
116
  case i
126
- when "%pA"
117
+ when '%pA'
127
118
  frmt.sub!(i, ALPHA_U[args[idx]])
128
119
  remove_args << idx
129
- when "%pa"
120
+ when '%pa'
130
121
  frmt.sub!(i, ALPHA_L[args[idx]])
131
122
  remove_args << idx
132
- when "%pAW"
123
+ when '%pAW'
133
124
  frmt.sub!(i, ALPHA_UW[args[idx]])
134
125
  remove_args << idx
135
- when "%paW"
126
+ when '%paW'
136
127
  frmt.sub!(i, ALPHA_LW[args[idx]])
137
128
  remove_args << idx
138
- when "%pR"
129
+ when '%pR'
139
130
  frmt.sub!(i, ROMAN_U[args[idx]])
140
131
  remove_args << idx
141
- when "%pr"
132
+ when '%pr'
142
133
  frmt.sub!(i, ROMAN_L[args[idx]])
143
134
  remove_args << idx
144
- when "%pRW"
135
+ when '%pRW'
145
136
  frmt.sub!(i, ROMAN_UW[args[idx]])
146
137
  remove_args << idx
147
- when "%pJ"
138
+ when '%pJ'
148
139
  frmt.sub!(i, JAPAN[args[idx]])
149
140
  remove_args << idx
150
- when "%pdW"
141
+ when '%pdW'
151
142
  frmt.sub!(i, ARABIC_LW[args[idx]])
152
143
  remove_args << idx
153
- when "%pDW"
144
+ when '%pDW'
154
145
  frmt.sub!(i, ARABIC_UW[args[idx]])
155
146
  remove_args << idx
156
- else
157
- # do nothing
158
147
  end
159
148
  end
160
149
  remove_args.reverse_each do |idx|
161
150
  args.delete_at idx
162
151
  end
163
- args_matched = (frmt.count("%") <= args.size)
152
+ args_matched = (frmt.count('%') <= args.size)
164
153
  frmt.gsub!('##', '%%')
165
154
  args_matched ? (frmt % args) : frmt
166
155
  rescue
@@ -5,7 +5,7 @@ ja:
5
5
  column: "コラム「%s」"
6
6
  columnname: "コラム"
7
7
  column_head: "■コラム"
8
- part: 第%d
8
+ part: 第%pR
9
9
  part_short: "%pR"
10
10
  chapter: 第%d章
11
11
  chapter_short: "%d"
@@ -67,7 +67,7 @@ en:
67
67
  column: "Column %s"
68
68
  columnname: "Column"
69
69
  column_head: "Column"
70
- part: "Part %s"
70
+ part: "Part %pR"
71
71
  part_short: "%pR"
72
72
  chapter: Chapter %d
73
73
  chapter_short: "%d"
@@ -126,7 +126,7 @@ zh-TW:
126
126
  image: 圖
127
127
  table: 表
128
128
  list: List
129
- part: 第%d部份
129
+ part: 第%pR部份
130
130
  part_short: "%pR"
131
131
  chapter: 第%d章
132
132
  chapter_short: "%d"
@@ -1,7 +1,5 @@
1
- # encoding: utf-8
2
-
3
- # Copyright (c) 2002-2007 Minero Aoki
4
- # 2008-2017 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2008-2017 Minero Aoki, 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
@@ -14,13 +12,11 @@ require 'review/textutils'
14
12
  require 'nkf'
15
13
 
16
14
  module ReVIEW
17
-
18
15
  class IDGXMLBuilder < Builder
19
-
20
16
  include TextUtils
21
17
  include HTMLUtils
22
18
 
23
- [:ttbold, :hint, :maru, :keytop, :labelref, :ref, :pageref, :balloon].each {|e| Compiler.definline(e) }
19
+ %i[ttbold hint maru keytop labelref ref balloon].each { |e| Compiler.definline(e) }
24
20
  Compiler.defsingle(:dtp, 1)
25
21
 
26
22
  Compiler.defblock(:insn, 0..1)
@@ -65,19 +61,19 @@ module ReVIEW
65
61
  @noindent = nil
66
62
  @ol_num = nil
67
63
  @first_line_num = nil
68
- @rootelement = "doc"
64
+ @rootelement = 'doc'
69
65
  @secttags = nil
70
66
  @tsize = nil
71
67
  @texblockequation = 0
72
68
  @texinlineequation = 0
73
69
  print %Q(<?xml version="1.0" encoding="UTF-8"?>\n)
74
70
  print %Q(<#{@rootelement} xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">)
75
- @secttags = true unless @book.config["structuredxml"].nil?
71
+ @secttags = true unless @book.config['structuredxml'].nil?
76
72
  end
77
73
  private :builder_init_file
78
74
 
79
75
  def puts(arg)
80
- if @book.config["nolf"].present?
76
+ if @book.config['nolf'].present?
81
77
  print arg
82
78
  else
83
79
  super
@@ -85,43 +81,25 @@ module ReVIEW
85
81
  end
86
82
 
87
83
  def result
88
- s = ""
89
- unless @secttags.nil?
90
- s += "</sect4>" if @subsubsubsection > 0
91
- s += "</sect3>" if @subsubsection > 0
92
- s += "</sect2>" if @subsection > 0
93
- s += "</sect>" if @section > 0
94
- s += "</chapter>" if @chapter.number > 0
84
+ s = ''
85
+ if @secttags
86
+ s += '</sect4>' if @subsubsubsection > 0
87
+ s += '</sect3>' if @subsubsection > 0
88
+ s += '</sect2>' if @subsection > 0
89
+ s += '</sect>' if @section > 0
90
+ s += '</chapter>' if @chapter.number > 0
95
91
  end
96
92
  @output.string + s + "</#{@rootelement}>\n"
97
93
  end
98
94
 
99
- def warn(msg)
100
- if @no_error
101
- @warns.push [@location.filename, @location.lineno, msg]
102
- puts "----WARNING: #{escape_html(msg)}----"
103
- else
104
- $stderr.puts "#{@location}: warning: #{msg}"
105
- end
106
- end
107
-
108
- def error(msg)
109
- if @no_error
110
- @errors.push [@location.filename, @location.lineno, msg]
111
- puts "----ERROR: #{escape_html(msg)}----"
112
- else
113
- $stderr.puts "#{@location}: error: #{msg}"
114
- end
115
- end
116
-
117
95
  def headline(level, label, caption)
118
96
  case level
119
97
  when 1
120
- unless @secttags.nil?
121
- print "</sect4>" if @subsubsubsection > 0
122
- print "</sect3>" if @subsubsection > 0
123
- print "</sect2>" if @subsection > 0
124
- print "</sect>" if @section > 0
98
+ if @secttags
99
+ print '</sect4>' if @subsubsubsection > 0
100
+ print '</sect3>' if @subsubsection > 0
101
+ print '</sect2>' if @subsection > 0
102
+ print '</sect>' if @section > 0
125
103
  end
126
104
 
127
105
  print %Q(<chapter id="chap:#{@chapter.number}">) unless @secttags.nil?
@@ -131,11 +109,11 @@ module ReVIEW
131
109
  @subsubsection = 0
132
110
  @subsubsubsection = 0
133
111
  when 2
134
- unless @secttags.nil?
135
- print "</sect4>" if @subsubsubsection > 0
136
- print "</sect3>" if @subsubsection > 0
137
- print "</sect2>" if @subsection > 0
138
- print "</sect>" if @section > 0
112
+ if @secttags
113
+ print '</sect4>' if @subsubsubsection > 0
114
+ print '</sect3>' if @subsubsection > 0
115
+ print '</sect2>' if @subsection > 0
116
+ print '</sect>' if @section > 0
139
117
  end
140
118
  @section += 1
141
119
  print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) unless @secttags.nil?
@@ -144,10 +122,10 @@ module ReVIEW
144
122
  @subsubsection = 0
145
123
  @subsubsubsection = 0
146
124
  when 3
147
- unless @secttags.nil?
148
- print "</sect4>" if @subsubsubsection > 0
149
- print "</sect3>" if @subsubsection > 0
150
- print "</sect2>" if @subsection > 0
125
+ if @secttags
126
+ print '</sect4>' if @subsubsubsection > 0
127
+ print '</sect3>' if @subsubsection > 0
128
+ print '</sect2>' if @subsection > 0
151
129
  end
152
130
 
153
131
  @subsection += 1
@@ -156,35 +134,33 @@ module ReVIEW
156
134
  @subsubsection = 0
157
135
  @subsubsubsection = 0
158
136
  when 4
159
- unless @secttags.nil?
160
- print "</sect4>" if @subsubsubsection > 0
161
- print "</sect3>" if @subsubsection > 0
137
+ if @secttags
138
+ print '</sect4>' if @subsubsubsection > 0
139
+ print '</sect3>' if @subsubsection > 0
162
140
  end
163
141
 
164
142
  @subsubsection += 1
165
- print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) unless @secttags.nil?
143
+ print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) if @secttags
166
144
 
167
145
  @subsubsubsection = 0
168
146
  when 5
169
- unless @secttags.nil?
170
- print "</sect4>" if @subsubsubsection > 0
171
- end
147
+ print '</sect4>' if @secttags && @subsubsubsection > 0
172
148
 
173
149
  @subsubsubsection += 1
174
- print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) unless @secttags.nil?
150
+ print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
175
151
  else
176
152
  raise "caption level too deep or unsupported: #{level}"
177
153
  end
178
154
 
179
- prefix, anchor = headline_prefix(level)
155
+ prefix, _anchor = headline_prefix(level)
180
156
 
181
- label = label.nil? ? "" : " id=\"#{label}\""
157
+ label = label.nil? ? '' : %Q( id="#{label}")
182
158
  toccaption = escape_html(compile_inline(caption.gsub(/@<fn>\{.+?\}/, '')).gsub(/<[^>]+>/, ''))
183
159
  puts %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>)
184
160
  end
185
161
 
186
162
  def ul_begin
187
- level = block_given? ? yield : ""
163
+ level = block_given? ? yield : ''
188
164
  level = nil if level == 1
189
165
  puts "<ul#{level == 1 ? nil : level}>"
190
166
  end
@@ -194,36 +170,34 @@ module ReVIEW
194
170
  end
195
171
 
196
172
  def ul_item_end
197
- puts "</li>"
173
+ puts '</li>'
198
174
  end
199
175
 
200
176
  def choice_single_begin
201
- puts "<choice type='single'>"
177
+ puts %Q(<choice type='single'>)
202
178
  end
203
179
 
204
180
  def choice_multi_begin
205
- puts "<choice type='multi'>"
181
+ puts %Q(<choice type='multi'>)
206
182
  end
207
183
 
208
184
  def choice_single_end
209
- puts "</choice>"
185
+ puts '</choice>'
210
186
  end
211
187
 
212
188
  def choice_multi_end
213
- puts "</choice>"
189
+ puts '</choice>'
214
190
  end
215
191
 
216
192
  def ul_end
217
- level = block_given? ? yield : ""
193
+ level = block_given? ? yield : ''
218
194
  level = nil if level == 1
219
195
  puts "</ul#{level}>"
220
196
  end
221
197
 
222
198
  def ol_begin
223
199
  puts '<ol>'
224
- if !@ol_num
225
- @ol_num = 1
226
- end
200
+ @ol_num ||= 1
227
201
  end
228
202
 
229
203
  def ol_item(lines, num)
@@ -259,7 +233,7 @@ module ReVIEW
259
233
  def paragraph(lines)
260
234
  if @noindent.nil?
261
235
  if lines[0] =~ /\A(\t+)/
262
- puts %Q(<p inlist="#{$1.size}">#{lines.join('').sub(/\A\t+/, "")}</p>)
236
+ puts %Q(<p inlist="#{$1.size}">#{lines.join.sub(/\A\t+/, '')}</p>)
263
237
  else
264
238
  puts "<p>#{lines.join}</p>"
265
239
  end
@@ -270,95 +244,96 @@ module ReVIEW
270
244
  end
271
245
 
272
246
  def read(lines)
273
- puts %Q[<lead>#{split_paragraph(lines).join}</lead>]
247
+ puts %Q(<lead>#{split_paragraph(lines).join}</lead>)
274
248
  end
275
249
 
276
250
  alias_method :lead, :read
277
251
 
278
- def column_label(id)
279
- num = @chapter.column(id).number
252
+ def column_label(id, chapter = @chapter)
253
+ num = chapter.column(id).number
280
254
  "column-#{num}"
281
255
  end
282
256
  private :column_label
283
257
 
284
258
  def inline_column_chap(chapter, id)
285
- if @book.config["chapterlink"]
286
- %Q(<link href="#{column_label(id)}">#{I18n.t("column", compile_inline(chapter.column(id).caption))}</link>)
259
+ if @book.config['chapterlink']
260
+ %Q(<link href="#{column_label(id, chapter)}">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</link>)
287
261
  else
288
- I18n.t("column", compile_inline(chapter.column(id).caption))
262
+ I18n.t('column', compile_inline(chapter.column(id).caption))
289
263
  end
290
264
  end
291
265
 
292
266
  def inline_list(id)
293
267
  chapter, id = extract_chapter_id(id)
294
268
  if get_chap(chapter).nil?
295
- "<span type='list'>#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [chapter.list(id).number])}</span>"
269
+ "<span type='list'>#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [chapter.list(id).number])}</span>"
296
270
  else
297
- "<span type='list'>#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}</span>"
271
+ "<span type='list'>#{I18n.t('list')}#{I18n.t('format_number', [get_chap(chapter), chapter.list(id).number])}</span>"
298
272
  end
299
273
  end
300
274
 
301
- def list_header(id, caption, lang)
302
- puts %Q[<codelist>]
275
+ def list_header(id, caption, _lang)
276
+ puts '<codelist>'
277
+ return true unless caption.present?
303
278
  if get_chap.nil?
304
- puts %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
279
+ puts %Q(<caption>#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
305
280
  else
306
- puts %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
281
+ puts %Q(<caption>#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
307
282
  end
308
283
  end
309
284
 
310
285
  def codelines_body(lines)
311
286
  no = 1
312
287
  lines.each do |line|
313
- unless @book.config["listinfo"].nil?
314
- print "<listinfo line=\"#{no}\""
315
- print " begin=\"1\"" if no == 1
316
- print " end=\"#{no}\"" if no == lines.size
317
- print ">"
288
+ if @book.config['listinfo']
289
+ print %Q(<listinfo line="#{no}")
290
+ print %Q( begin="1") if no == 1
291
+ print %Q( end="#{no}") if no == lines.size
292
+ print '>'
318
293
  end
319
294
  print detab(line)
320
295
  print "\n"
321
- print "</listinfo>" unless @book.config["listinfo"].nil?
296
+ print '</listinfo>' if @book.config['listinfo']
322
297
  no += 1
323
298
  end
324
299
  end
325
300
 
326
- def list_body(id, lines, lang)
327
- print %Q(<pre>)
301
+ def list_body(_id, lines, _lang)
302
+ print '<pre>'
328
303
  codelines_body(lines)
329
- puts "</pre></codelist>"
304
+ puts '</pre></codelist>'
330
305
  end
331
306
 
332
- def emlist(lines, caption = nil, lang = nil)
307
+ def emlist(lines, caption = nil, _lang = nil)
333
308
  quotedlist lines, 'emlist', caption
334
309
  end
335
310
 
336
- def emlistnum(lines, caption = nil, lang = nil)
337
- _lines = []
338
- first_line_num = get_line_num
311
+ def emlistnum(lines, caption = nil, _lang = nil)
312
+ lines2 = []
313
+ first_line_num = line_num
339
314
  lines.each_with_index do |line, i|
340
- _lines << detab("<span type='lineno'>" + (i + first_line_num).to_s.rjust(2) + ": </span>" + line)
315
+ lines2 << detab(%Q(<span type='lineno'>) + (i + first_line_num).to_s.rjust(2) + ': </span>' + line)
341
316
  end
342
- quotedlist _lines, 'emlistnum', caption
317
+ quotedlist lines2, 'emlistnum', caption
343
318
  end
344
319
 
345
- def listnum_body(lines, lang)
346
- print %Q(<pre>)
320
+ def listnum_body(lines, _lang)
321
+ print '<pre>'
347
322
  no = 1
348
- first_line_num = get_line_num
323
+ first_line_num = line_num
349
324
  lines.each_with_index do |line, i|
350
- unless @book.config["listinfo"].nil?
351
- print "<listinfo line=\"#{no}\""
352
- print " begin=\"1\"" if no == 1
353
- print " end=\"#{no}\"" if no == lines.size
354
- print ">"
325
+ if @book.config['listinfo']
326
+ print %Q(<listinfo line="#{no}")
327
+ print %Q( begin="1") if no == 1
328
+ print %Q( end="#{no}") if no == lines.size
329
+ print '>'
355
330
  end
356
- print detab("<span type='lineno'>" + (i + first_line_num).to_s.rjust(2) + ": </span>" + line)
331
+ print detab(%Q(<span type='lineno'>) + (i + first_line_num).to_s.rjust(2) + ': </span>' + line)
357
332
  print "\n"
358
- print "</listinfo>" unless @book.config["listinfo"].nil?
333
+ print '</listinfo>' if @book.config['listinfo']
359
334
  no += 1
360
335
  end
361
- puts "</pre></codelist>"
336
+ puts '</pre></codelist>'
362
337
  end
363
338
 
364
339
  def cmd(lines, caption = nil)
@@ -366,20 +341,20 @@ module ReVIEW
366
341
  end
367
342
 
368
343
  def quotedlist(lines, css_class, caption)
369
- print %Q[<list type='#{css_class}'>]
344
+ print %Q(<list type='#{css_class}'>)
370
345
  puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>" if caption.present?
371
- print %Q[<pre>]
346
+ print '<pre>'
372
347
  no = 1
373
348
  lines.each do |line|
374
- unless @book.config["listinfo"].nil?
375
- print "<listinfo line=\"#{no}\""
376
- print " begin=\"1\"" if no == 1
377
- print " end=\"#{no}\"" if no == lines.size
378
- print ">"
349
+ if @book.config['listinfo']
350
+ print %Q(<listinfo line="#{no}")
351
+ print %Q( begin="1") if no == 1
352
+ print %Q( end="#{no}") if no == lines.size
353
+ print '>'
379
354
  end
380
355
  print detab(line)
381
356
  print "\n"
382
- print "</listinfo>" unless @book.config["listinfo"].nil?
357
+ print '</listinfo>' if @book.config['listinfo']
383
358
  no += 1
384
359
  end
385
360
  puts '</pre></list>'
@@ -388,24 +363,24 @@ module ReVIEW
388
363
 
389
364
  def quote(lines)
390
365
  blocked_lines = split_paragraph(lines)
391
- puts "<quote>#{blocked_lines.join("")}</quote>"
366
+ puts "<quote>#{blocked_lines.join}</quote>"
392
367
  end
393
368
 
394
369
  def inline_table(id)
395
370
  chapter, id = extract_chapter_id(id)
396
371
  if get_chap(chapter).nil?
397
- "<span type='table'>#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}</span>"
372
+ "<span type='table'>#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [chapter.table(id).number])}</span>"
398
373
  else
399
- "<span type='table'>#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}</span>"
374
+ "<span type='table'>#{I18n.t('table')}#{I18n.t('format_number', [get_chap(chapter), chapter.table(id).number])}</span>"
400
375
  end
401
376
  end
402
377
 
403
378
  def inline_img(id)
404
379
  chapter, id = extract_chapter_id(id)
405
380
  if get_chap(chapter).nil?
406
- "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}</span>"
381
+ "<span type='image'>#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])}</span>"
407
382
  else
408
- "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}</span>"
383
+ "<span type='image'>#{I18n.t('image')}#{I18n.t('format_number', [get_chap(chapter), chapter.image(id).number])}</span>"
409
384
  end
410
385
  end
411
386
 
@@ -413,69 +388,66 @@ module ReVIEW
413
388
  chapter, id = extract_chapter_id(id)
414
389
  if chapter.image(id).caption.blank?
415
390
  inline_img(id)
391
+ elsif get_chap(chapter).nil?
392
+ "<span type='image'>#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
416
393
  else
417
- if get_chap(chapter).nil?
418
- "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
419
- else
420
- "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
421
- end
394
+ "<span type='image'>#{I18n.t('image')}#{I18n.t('format_number', [get_chap(chapter), chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
422
395
  end
423
396
  end
424
397
 
425
398
  def handle_metric(str)
426
399
  k, v = str.split('=', 2)
427
- return %Q|#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
400
+ %Q(#{k}="#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}")
428
401
  end
429
402
 
430
403
  def result_metric(array)
431
404
  " #{array.join(' ')}"
432
405
  end
433
406
 
434
- def image_image(id, caption, metric=nil)
435
- metrics = parse_metric("idgxml", metric)
436
- puts "<img>"
437
- puts %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A.\//, "")}"#{metrics} />]
407
+ def image_image(id, caption, metric = nil)
408
+ metrics = parse_metric('idgxml', metric)
409
+ puts '<img>'
410
+ puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} />)
438
411
  image_header id, caption
439
- puts "</img>"
412
+ puts '</img>'
440
413
  end
441
414
 
442
415
  def image_dummy(id, caption, lines)
443
- puts "<img>"
444
- print %Q[<pre aid:pstyle="dummyimage">]
416
+ puts '<img>'
417
+ print %Q(<pre aid:pstyle="dummyimage">)
445
418
  lines.each do |line|
446
419
  print detab(line)
447
420
  print "\n"
448
421
  end
449
- print %Q[</pre>]
422
+ print '</pre>'
450
423
  image_header id, caption
451
- puts "</img>"
452
- warn "no such image: #{id}"
424
+ puts '</img>'
425
+ warn "image not bound: #{id}"
453
426
  end
454
427
 
455
428
  def image_header(id, caption)
429
+ return true unless caption.present?
456
430
  if get_chap.nil?
457
- puts %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
431
+ puts %Q(<caption>#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
458
432
  else
459
- puts %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
433
+ puts %Q(<caption>#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
460
434
  end
461
435
  end
462
436
 
463
437
  def texequation(lines)
464
438
  @texblockequation += 1
465
- puts %Q[<replace idref="texblock-#{@texblockequation}">]
439
+ puts %Q(<replace idref="texblock-#{@texblockequation}">)
466
440
  puts '<pre>'
467
- puts "#{lines.join("\n")}"
441
+ puts lines.join("\n")
468
442
  puts '</pre>'
469
443
  puts '</replace>'
470
444
  end
471
445
 
472
446
  def table(lines, id = nil, caption = nil)
473
- tablewidth = nil
447
+ tablewidth = @book.config['tableopt'] ? @book.config['tableopt'].split(',')[0].to_f / @book.config['pt_to_mm_unit'].to_f : nil
474
448
  col = 0
475
- if @book.config["tableopt"]
476
- tablewidth = @book.config["tableopt"].split(",")[0].to_f / @book.config["pt_to_mm_unit"].to_f
477
- end
478
- puts "<table>"
449
+
450
+ puts '<table>'
479
451
  rows = []
480
452
  sepidx = nil
481
453
  lines.each_with_index do |line, idx|
@@ -483,94 +455,90 @@ module ReVIEW
483
455
  sepidx ||= idx
484
456
  next
485
457
  end
486
- if tablewidth.nil?
487
- rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ""))
458
+ if tablewidth
459
+ rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
488
460
  else
489
- rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ""))
461
+ rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ''))
490
462
  end
491
- _col = rows[rows.length - 1].split(/\t/).length
492
- col = _col if _col > col
463
+ col2 = rows[rows.length - 1].split(/\t/).length
464
+ col = col2 if col2 > col
493
465
  end
494
466
 
495
467
  cellwidth = []
496
- unless tablewidth.nil?
468
+ if tablewidth
497
469
  if @tsize.nil?
498
- col.times {|n| cellwidth[n] = tablewidth / col }
470
+ col.times { |n| cellwidth[n] = tablewidth / col }
499
471
  else
500
472
  cellwidth = @tsize.split(/\s*,\s*/)
501
473
  totallength = 0
502
474
  cellwidth.size.times do |n|
503
- cellwidth[n] = cellwidth[n].to_f / @book.config["pt_to_mm_unit"].to_f
475
+ cellwidth[n] = cellwidth[n].to_f / @book.config['pt_to_mm_unit'].to_f
504
476
  totallength += cellwidth[n]
505
477
  warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
506
478
  end
507
479
  if cellwidth.size < col
508
480
  cw = (tablewidth - totallength) / (col - cellwidth.size)
509
481
  warn "auto cell sizing exceeds limit for table: #{id}" if cw <= 0
510
- (cellwidth.size..(col - 1)).each do |i|
511
- cellwidth[i] = cw
512
- end
482
+ (cellwidth.size..(col - 1)).each { |i| cellwidth[i] = cw }
513
483
  end
514
484
  end
515
485
  end
516
486
 
517
487
  begin
518
- table_header id, caption unless caption.nil?
488
+ table_header id, caption if caption.present?
519
489
  rescue KeyError
520
490
  error "no such table: #{id}"
521
491
  end
522
492
  return if rows.empty?
523
493
 
524
494
  if tablewidth.nil?
525
- print "<tbody>"
495
+ print '<tbody>'
526
496
  else
527
- print %Q[<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{col}">]
497
+ print %Q(<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{col}">)
528
498
  end
529
499
 
530
500
  if sepidx
531
501
  sepidx.times do |y|
532
502
  if tablewidth.nil?
533
- puts %Q[<tr type="header">#{rows.shift}</tr>]
503
+ puts %Q(<tr type="header">#{rows.shift}</tr>)
534
504
  else
535
505
  i = 0
536
- rows.shift.split(/\t/).each_with_index do |cell, x|
537
- print %Q[<td xyh="#{x + 1},#{y + 1},#{sepidx}" aid:table="cell" aid:theader="1" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.3f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>]
506
+ rows.shift.split("\t").each_with_index do |cell, x|
507
+ print %Q(<td xyh="#{x + 1},#{y + 1},#{sepidx}" aid:table="cell" aid:theader="1" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf('%.3f', cellwidth[i])}">#{cell.sub('DUMMYCELLSPLITTER', '')}</td>)
538
508
  i += 1
539
509
  end
540
510
  end
541
511
  end
542
512
  end
543
513
  trputs(tablewidth, rows, cellwidth, sepidx)
544
- puts "</tbody></table>"
514
+ puts '</tbody></table>'
545
515
  @tsize = nil
546
516
  end
547
517
 
548
518
  def trputs(tablewidth, rows, cellwidth, sepidx)
549
519
  sepidx = 0 if sepidx.nil?
550
- if tablewidth.nil?
551
- lastline = rows.pop
552
- rows.each {|row| puts %Q[<tr>#{row}</tr>] }
553
- puts %Q[<tr type="lastline">#{lastline}</tr>] unless lastline.nil?
554
- else
520
+ if tablewidth
555
521
  rows.each_with_index do |row, y|
556
522
  i = 0
557
- row.split(/\t/).each_with_index do |cell, x|
558
- print %Q[<td xyh="#{x + 1},#{y + 1 + sepidx},#{sepidx}" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.3f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>]
523
+ row.split("\t").each_with_index do |cell, x|
524
+ print %Q(<td xyh="#{x + 1},#{y + 1 + sepidx},#{sepidx}" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf('%.3f', cellwidth[i])}">#{cell.sub('DUMMYCELLSPLITTER', '')}</td>)
559
525
  i += 1
560
526
  end
561
527
  end
528
+ else
529
+ lastline = rows.pop
530
+ rows.each { |row| puts "<tr>#{row}</tr>" }
531
+ puts %Q(<tr type="lastline">#{lastline}</tr>) if lastline
562
532
  end
563
533
  end
564
534
 
565
535
  def table_header(id, caption)
566
536
  if id.nil?
567
- puts %Q[<caption>#{compile_inline(caption)}</caption>]
537
+ puts %Q(<caption>#{compile_inline(caption)}</caption>)
538
+ elsif get_chap
539
+ puts %Q(<caption>#{I18n.t('table')}#{I18n.t('format_number', [get_chap, @chapter.table(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
568
540
  else
569
- if get_chap.nil?
570
- puts %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
571
- else
572
- puts %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
573
- end
541
+ puts %Q(<caption>#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
574
542
  end
575
543
  end
576
544
 
@@ -578,11 +546,11 @@ module ReVIEW
578
546
  end
579
547
 
580
548
  def tr(rows)
581
- puts %Q[<tr>#{rows.join("\t")}</tr>]
549
+ puts %Q(<tr>#{rows.join("\t")}</tr>)
582
550
  end
583
551
 
584
552
  def th(str)
585
- %Q[<?dtp tablerow header?>#{str}]
553
+ %Q(<?dtp tablerow header?>#{str})
586
554
  end
587
555
 
588
556
  def td(str)
@@ -590,7 +558,7 @@ module ReVIEW
590
558
  end
591
559
 
592
560
  def table_end
593
- print "<?dtp tablerow last?>"
561
+ print '<?dtp tablerow last?>'
594
562
  end
595
563
 
596
564
  def emtable(lines, caption = nil)
@@ -599,11 +567,11 @@ module ReVIEW
599
567
 
600
568
  def imgtable(lines, id, caption = nil, metric = nil)
601
569
  if @chapter.image(id).bound?
602
- metrics = parse_metric("idgxml", metric)
603
- puts "<table>"
604
- table_header id, caption
605
- puts %Q[<imgtable><Image href="file://#{@chapter.image(id).path.sub(/\A.\//, "")}"#{metrics} /></imgtable>]
606
- puts "</table>"
570
+ metrics = parse_metric('idgxml', metric)
571
+ puts '<table>'
572
+ table_header id, caption if caption.present?
573
+ puts %Q(<imgtable><Image href="file://#{@chapter.image(id).path.sub(%r{\A./}, '')}"#{metrics} /></imgtable>)
574
+ puts '</table>'
607
575
  else
608
576
  warn "image not bound: #{id}" if @strict
609
577
  image_dummy id, caption, lines
@@ -611,16 +579,15 @@ module ReVIEW
611
579
  end
612
580
 
613
581
  def comment(lines, comment = nil)
614
- if @book.config["draft"]
615
- lines ||= []
616
- lines.unshift comment unless comment.blank?
617
- str = lines.join("\n")
618
- print "<msg>#{escape_html(str)}</msg>"
619
- end
582
+ return true unless @book.config['draft']
583
+ lines ||= []
584
+ lines.unshift comment unless comment.blank?
585
+ str = lines.join("\n")
586
+ print "<msg>#{escape_html(str)}</msg>"
620
587
  end
621
588
 
622
589
  def inline_comment(str)
623
- if @book.config["draft"]
590
+ if @book.config['draft']
624
591
  %Q(<msg>#{escape_html(str)}</msg>)
625
592
  else
626
593
  ''
@@ -632,11 +599,11 @@ module ReVIEW
632
599
  end
633
600
 
634
601
  def inline_fn(id)
635
- %Q[<footnote>#{compile_inline(@chapter.footnote(id).content.strip)}</footnote>]
602
+ %Q(<footnote>#{compile_inline(@chapter.footnote(id).content.strip)}</footnote>)
636
603
  end
637
604
 
638
605
  def compile_ruby(base, ruby)
639
- %Q[<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape_html(base.sub(/\A\s+/, "").sub(/\s+$/, ""))}</aid:rb><aid:rt>#{escape_html(ruby.sub(/\A\s+/, "").sub(/\s+$/, ""))}</aid:rt></aid:ruby></GroupRuby>]
606
+ %Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape_html(base.strip)}</aid:rb><aid:rt>#{escape_html(ruby.strip)}</aid:rt></aid:ruby></GroupRuby>)
640
607
  end
641
608
 
642
609
  def compile_kw(word, alt)
@@ -646,55 +613,55 @@ module ReVIEW
646
613
  else escape_html(word)
647
614
  end +
648
615
  '</keyword>' +
649
- %Q[<index value="#{escape_html(word)}" />] +
616
+ %Q(<index value="#{escape_html(word)}" />) +
650
617
  if alt
651
- alt.split(/\s*,\s*/).collect! {|e| %Q[<index value="#{escape_html(e.strip)}" />] }.join
618
+ alt.split(/\s*,\s*/).collect! { |e| %Q(<index value="#{escape_html(e.strip)}" />) }.join
652
619
  else
653
- ""
620
+ ''
654
621
  end
655
622
  end
656
623
 
657
624
  def compile_href(url, label)
658
- %Q[<a linkurl='#{escape_html(url)}'>#{label.nil? ? escape_html(url) : escape_html(label)}</a>]
625
+ %Q(<a linkurl='#{escape_html(url)}'>#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
659
626
  end
660
627
 
661
628
  def inline_sup(str)
662
- %Q[<sup>#{escape_html(str)}</sup>]
629
+ %Q(<sup>#{escape_html(str)}</sup>)
663
630
  end
664
631
 
665
632
  def inline_sub(str)
666
- %Q[<sub>#{escape_html(str)}</sub>]
633
+ %Q(<sub>#{escape_html(str)}</sub>)
667
634
  end
668
635
 
669
636
  def inline_raw(str)
670
- %Q[#{super(str).gsub("\\n", "\n")}]
637
+ super(str).gsub('\\n', "\n")
671
638
  end
672
639
 
673
640
  def inline_hint(str)
674
- if @book.config["nolf"].nil?
675
- %Q[\n<hint>#{escape_html(str)}</hint>]
641
+ if @book.config['nolf']
642
+ %Q(<hint>#{escape_html(str)}</hint>)
676
643
  else
677
- %Q[<hint>#{escape_html(str)}</hint>]
644
+ %Q(\n<hint>#{escape_html(str)}</hint>)
678
645
  end
679
646
  end
680
647
 
681
648
  def inline_maru(str)
682
649
  if str =~ /\A\d+\Z/
683
- sprintf("&#x%x;", 9311 + str.to_i)
650
+ sprintf('&#x%x;', 9311 + str.to_i)
684
651
  elsif str =~ /\A[A-Z]\Z/
685
652
  begin
686
- sprintf("&#x%x;", 9398 + str.codepoints.to_a[0] - 65)
653
+ sprintf('&#x%x;', 9398 + str.codepoints.to_a[0] - 65)
687
654
  rescue NoMethodError
688
- sprintf("&#x%x;", 9398 + str[0] - 65)
655
+ sprintf('&#x%x;', 9398 + str[0] - 65)
689
656
  end
690
657
  elsif str =~ /\A[a-z]\Z/
691
658
  begin
692
- sprintf("&#x%x;", 9392 + str.codepoints.to_a[0] - 65)
659
+ sprintf('&#x%x;', 9392 + str.codepoints.to_a[0] - 65)
693
660
  rescue NoMethodError
694
- sprintf("&#x%x;", 9392 + str[0] - 65)
661
+ sprintf('&#x%x;', 9392 + str[0] - 65)
695
662
  end
696
663
  else
697
- raise "can't parse maru: #{str}"
664
+ error "can't parse maru: #{str}"
698
665
  end
699
666
  end
700
667
 
@@ -738,42 +705,42 @@ module ReVIEW
738
705
 
739
706
  def inline_icon(id)
740
707
  begin
741
- %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A\.\//, "")}" type="inline" />]
708
+ %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}" type="inline" />)
742
709
  rescue
743
- warn "no such icon image: #{id}"
744
- ""
710
+ warn "image not bound: #{id}"
711
+ ''
745
712
  end
746
713
  end
747
714
 
748
715
  def inline_bou(str)
749
- %Q[<bou>#{escape_html(str)}</bou>]
716
+ %Q(<bou>#{escape_html(str)}</bou>)
750
717
  end
751
718
 
752
719
  def inline_keytop(str)
753
- %Q[<keytop>#{escape_html(str)}</keytop>]
720
+ %Q(<keytop>#{escape_html(str)}</keytop>)
754
721
  end
755
722
 
756
723
  def inline_labelref(idref)
757
- %Q[<ref idref='#{escape_html(idref)}'>「#{I18n.t("label_marker")}#{escape_html(idref)}」</ref>] # FIXME: 節名とタイトルも込みで要出力
724
+ %Q(<ref idref='#{escape_html(idref)}'>「#{I18n.t('label_marker')}#{escape_html(idref)}」</ref>) # FIXME: 節名とタイトルも込みで要出力
758
725
  end
759
726
 
760
727
  alias_method :inline_ref, :inline_labelref
761
728
 
762
729
  def inline_pageref(idref)
763
- %Q[<pageref idref='#{escape_html(idref)}'>●●</pageref>] # ページ番号を参照
730
+ %Q(<pageref idref='#{escape_html(idref)}'>●●</pageref>) # ページ番号を参照
764
731
  end
765
732
 
766
733
  def inline_balloon(str)
767
- %Q[<balloon>#{escape_html(str).gsub(/@maru\[(\d+)\]/) {|m| inline_maru($1)}}</balloon>]
734
+ %Q(<balloon>#{escape_html(str).gsub(/@maru\[(\d+)\]/) { inline_maru($1) }}</balloon>)
768
735
  end
769
736
 
770
737
  def inline_uchar(str)
771
- %Q[&#x#{str};]
738
+ %Q(&#x#{str};)
772
739
  end
773
740
 
774
741
  def inline_m(str)
775
742
  @texinlineequation += 1
776
- %Q[<replace idref="texinline-#{@texinlineequation}"><pre>#{escape_html(str)}</pre></replace>]
743
+ %Q(<replace idref="texinline-#{@texinlineequation}"><pre>#{escape_html(str)}</pre></replace>)
777
744
  end
778
745
 
779
746
  def noindent
@@ -782,22 +749,22 @@ module ReVIEW
782
749
 
783
750
  def linebreak
784
751
  # FIXME: pが閉じちゃってるので一度戻らないといけないが、難しい…。
785
- puts "<br />"
752
+ puts '<br />'
786
753
  end
787
754
 
788
755
  def pagebreak
789
- puts "<pagebreak />"
756
+ puts '<pagebreak />'
790
757
  end
791
758
 
792
- def nonum_begin(level, label, caption)
793
- puts %Q[<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{escape_html(compile_inline(caption))}"?>]
759
+ def nonum_begin(level, _label, caption)
760
+ puts %Q(<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{escape_html(compile_inline(caption))}"?>)
794
761
  end
795
762
 
796
763
  def nonum_end(level)
797
764
  end
798
765
 
799
- def circle_begin(level, label, caption)
800
- puts %Q[<title aid:pstyle="smallcircle">&#x2022;#{compile_inline(caption)}</title>]
766
+ def circle_begin(_level, _label, caption)
767
+ puts %Q(<title aid:pstyle="smallcircle">&#x2022;#{compile_inline(caption)}</title>)
801
768
  end
802
769
 
803
770
  def circle_end(level)
@@ -805,233 +772,234 @@ module ReVIEW
805
772
 
806
773
  def common_column_begin(type, caption)
807
774
  @column += 1
808
- a_id = %Q[id="column-#{@column}"]
775
+ a_id = %Q(id="column-#{@column}")
809
776
  print "<#{type}column #{a_id}>"
810
- puts %Q[<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title><?dtp level="9" section="#{escape_html(compile_inline(caption))}"?>]
777
+ puts %Q(<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title><?dtp level="9" section="#{escape_html(compile_inline(caption))}"?>)
811
778
  end
812
779
 
813
780
  def common_column_end(type)
814
781
  puts "</#{type}column>"
815
782
  end
816
783
 
817
- def column_begin(level, label, caption)
818
- common_column_begin("", caption)
784
+ def column_begin(_level, _label, caption)
785
+ common_column_begin('', caption)
819
786
  end
820
787
 
821
- def column_end(level)
822
- common_column_end("")
788
+ def column_end(_level)
789
+ common_column_end('')
823
790
  end
824
791
 
825
- def xcolumn_begin(level, label, caption)
826
- common_column_begin("x", caption)
792
+ def xcolumn_begin(_level, _label, caption)
793
+ common_column_begin('x', caption)
827
794
  end
828
795
 
829
- def xcolumn_end(level)
830
- common_column_end("x")
796
+ def xcolumn_end(_level)
797
+ common_column_end('x')
831
798
  end
832
799
 
833
- def world_begin(level, label, caption)
834
- common_column_begin("world", caption)
800
+ def world_begin(_level, _label, caption)
801
+ common_column_begin('world', caption)
835
802
  end
836
803
 
837
- def world_end(level)
838
- common_column_end("world")
804
+ def world_end(_level)
805
+ common_column_end('world')
839
806
  end
840
807
 
841
- def hood_begin(level, label, caption)
842
- common_column_begin("hood", caption)
808
+ def hood_begin(_level, _label, caption)
809
+ common_column_begin('hood', caption)
843
810
  end
844
811
 
845
- def hood_end(level)
846
- common_column_end("hood")
812
+ def hood_end(_level)
813
+ common_column_end('hood')
847
814
  end
848
815
 
849
- def edition_begin(level, label, caption)
850
- common_column_begin("edition", caption)
816
+ def edition_begin(_level, _label, caption)
817
+ common_column_begin('edition', caption)
851
818
  end
852
819
 
853
- def edition_end(level)
854
- common_column_end("edition")
820
+ def edition_end(_level)
821
+ common_column_end('edition')
855
822
  end
856
823
 
857
- def insideout_begin(level, label, caption)
858
- common_column_begin("insideout", caption)
824
+ def insideout_begin(_level, _label, caption)
825
+ common_column_begin('insideout', caption)
859
826
  end
860
827
 
861
- def insideout_end(level)
862
- common_column_end("insideout")
828
+ def insideout_end(_level)
829
+ common_column_end('insideout')
863
830
  end
864
831
 
865
- def ref_begin(level, label, caption)
866
- if !label.nil?
832
+ def ref_begin(_level, label, _caption)
833
+ if label
867
834
  puts "<reference id='#{label}'>"
868
835
  else
869
- puts "<reference>"
836
+ puts '<reference>'
870
837
  end
871
838
  end
872
839
 
873
- def ref_end(level)
874
- puts "</reference>"
840
+ def ref_end(_level)
841
+ puts '</reference>'
875
842
  end
876
843
 
877
- def sup_begin(level, label, caption)
878
- if !label.nil?
844
+ def sup_begin(_level, label, _caption)
845
+ if label
879
846
  puts "<supplement id='#{label}'>"
880
847
  else
881
- puts "<supplement>"
848
+ puts '<supplement>'
882
849
  end
883
850
  end
884
851
 
885
- def sup_end(level)
886
- puts "</supplement>"
852
+ def sup_end(_level)
853
+ puts '</supplement>'
887
854
  end
888
855
 
889
856
  def flushright(lines)
890
- puts split_paragraph(lines).join.gsub("<p>", "<p align='right'>")
857
+ puts split_paragraph(lines).join.gsub('<p>', %Q(<p align='right'>))
891
858
  end
892
859
 
893
860
  def centering(lines)
894
- puts split_paragraph(lines).join.gsub("<p>", "<p align='center'>")
861
+ puts split_paragraph(lines).join.gsub('<p>', %Q(<p align='center'>))
895
862
  end
896
863
 
897
864
  def captionblock(type, lines, caption, specialstyle = nil)
898
865
  print "<#{type}>"
899
866
  style = specialstyle.nil? ? "#{type}-title" : specialstyle
900
- puts "<title aid:pstyle='#{style}'>#{compile_inline(caption)}</title>" unless caption.nil?
867
+ puts "<title aid:pstyle='#{style}'>#{compile_inline(caption)}</title>" if caption.present?
901
868
  blocked_lines = split_paragraph(lines)
902
869
  puts "#{blocked_lines.join}</#{type}>"
903
870
  end
904
871
 
905
872
  def note(lines, caption = nil)
906
- captionblock("note", lines, caption)
873
+ captionblock('note', lines, caption)
907
874
  end
908
875
 
909
876
  def memo(lines, caption = nil)
910
- captionblock("memo", lines, caption)
877
+ captionblock('memo', lines, caption)
911
878
  end
912
879
 
913
880
  def tip(lines, caption = nil)
914
- captionblock("tip", lines, caption)
881
+ captionblock('tip', lines, caption)
915
882
  end
916
883
 
917
884
  def info(lines, caption = nil)
918
- captionblock("info", lines, caption)
885
+ captionblock('info', lines, caption)
919
886
  end
920
887
 
921
888
  def planning(lines, caption = nil)
922
- captionblock("planning", lines, caption)
889
+ captionblock('planning', lines, caption)
923
890
  end
924
891
 
925
892
  def best(lines, caption = nil)
926
- captionblock("best", lines, caption)
893
+ captionblock('best', lines, caption)
927
894
  end
928
895
 
929
896
  def important(lines, caption = nil)
930
- captionblock("important", lines, caption)
897
+ captionblock('important', lines, caption)
931
898
  end
932
899
 
933
900
  def security(lines, caption = nil)
934
- captionblock("security", lines, caption)
901
+ captionblock('security', lines, caption)
935
902
  end
936
903
 
937
904
  def caution(lines, caption = nil)
938
- captionblock("caution", lines, caption)
905
+ captionblock('caution', lines, caption)
939
906
  end
940
907
 
941
908
  def warning(lines, caption = nil)
942
- captionblock("warning", lines, caption)
909
+ captionblock('warning', lines, caption)
943
910
  end
944
911
 
945
912
  def term(lines)
946
- captionblock("term", lines, nil)
913
+ captionblock('term', lines, nil)
947
914
  end
948
915
 
949
916
  def link(lines, caption = nil)
950
- captionblock("link", lines, caption)
917
+ captionblock('link', lines, caption)
951
918
  end
952
919
 
953
920
  def notice(lines, caption = nil)
954
- if caption.nil?
955
- captionblock("notice", lines, nil)
921
+ if caption
922
+ captionblock('notice-t', lines, caption, 'notice-title')
956
923
  else
957
- captionblock("notice-t", lines, caption, "notice-title")
924
+ captionblock('notice', lines, nil)
958
925
  end
959
926
  end
960
927
 
961
928
  def point(lines, caption = nil)
962
- if caption.nil?
963
- captionblock("point", lines, nil)
929
+ if caption
930
+ captionblock('point-t', lines, caption, 'point-title')
964
931
  else
965
- captionblock("point-t", lines, caption, "point-title")
932
+ captionblock('point', lines, nil)
966
933
  end
967
934
  end
968
935
 
969
936
  def shoot(lines, caption = nil)
970
- if caption.nil?
971
- captionblock("shoot", lines, nil)
937
+ if caption
938
+ captionblock('shoot-t', lines, caption, 'shoot-title')
972
939
  else
973
- captionblock("shoot-t", lines, caption, "shoot-title")
940
+ captionblock('shoot', lines, nil)
974
941
  end
975
942
  end
976
943
 
977
944
  def reference(lines)
978
- captionblock("reference", lines, nil)
945
+ captionblock('reference', lines, nil)
979
946
  end
980
947
 
981
948
  def practice(lines)
982
- captionblock("practice", lines, nil)
949
+ captionblock('practice', lines, nil)
983
950
  end
984
951
 
985
952
  def expert(lines)
986
- captionblock("expert", lines, nil)
953
+ captionblock('expert', lines, nil)
987
954
  end
988
955
 
989
956
  def syntaxblock(type, lines, caption)
990
- if caption.nil?
991
- puts %Q[<#{type}>]
992
- else
993
- titleopentag = %Q[caption aid:pstyle="#{type}-title"]
994
- titleclosetag = "caption"
995
- if type == "insn"
996
- titleopentag = %Q[floattitle type="insn"]
997
- titleclosetag = "floattitle"
957
+ if caption.present?
958
+ titleopentag = %Q(caption aid:pstyle="#{type}-title")
959
+ titleclosetag = 'caption'
960
+ if type == 'insn'
961
+ titleopentag = %Q(floattitle type="insn")
962
+ titleclosetag = 'floattitle'
998
963
  end
999
- puts %Q[<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>]
964
+ puts %Q(<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>)
965
+ else
966
+ puts "<#{type}>"
1000
967
  end
968
+
1001
969
  no = 1
1002
970
  lines.each do |line|
1003
- unless @book.config["listinfo"].nil?
1004
- print %Q[<listinfo line="#{no}"]
1005
- print %Q[ begin="1"] if no == 1
1006
- print %Q[ end="#{no}"] if no == lines.size
1007
- print %Q[>]
971
+ if @book.config['listinfo']
972
+ print %Q(<listinfo line="#{no}")
973
+ print %Q( begin="1") if no == 1
974
+ print %Q( end="#{no}") if no == lines.size
975
+ print '>'
1008
976
  end
1009
977
  print detab(line)
1010
978
  print "\n"
1011
- print "</listinfo>" unless @book.config["listinfo"].nil?
979
+ print '</listinfo>' if @book.config['listinfo']
1012
980
  no += 1
1013
981
  end
1014
982
  puts "</#{type}>"
1015
983
  end
1016
984
 
1017
985
  def insn(lines, caption = nil)
1018
- syntaxblock("insn", lines, caption)
986
+ syntaxblock('insn', lines, caption)
1019
987
  end
1020
988
 
1021
989
  def box(lines, caption = nil)
1022
- syntaxblock("box", lines, caption)
990
+ syntaxblock('box', lines, caption)
1023
991
  end
1024
992
 
1025
- def indepimage(id, caption=nil, metric=nil)
1026
- metrics = parse_metric("idgxml", metric)
1027
- puts "<img>"
993
+ def indepimage(_lines, id, caption = nil, metric = nil)
994
+ metrics = parse_metric('idgxml', metric)
995
+ puts '<img>'
1028
996
  begin
1029
- puts %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A\.\//, "")}"#{metrics} />]
997
+ puts %Q(<Image href="file://#{@chapter.image(id).path.sub(%r{\A\./}, '')}"#{metrics} />)
1030
998
  rescue
1031
- warn %Q[no such image: #{id}]
999
+ warn %Q(image not bound: #{id})
1032
1000
  end
1033
- puts %Q[<caption>#{compile_inline(caption)}</caption>] if caption.present?
1034
- puts "</img>"
1001
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1002
+ puts '</img>'
1035
1003
  end
1036
1004
 
1037
1005
  alias_method :numberlessimage, :indepimage
@@ -1046,11 +1014,11 @@ module ReVIEW
1046
1014
  end
1047
1015
 
1048
1016
  def hr
1049
- print "<hr />"
1017
+ print '<hr />'
1050
1018
  end
1051
1019
 
1052
1020
  def bpo(lines)
1053
- puts %Q[<bpo>#{lines.join("\n")}</bpo>]
1021
+ puts %Q(<bpo>#{lines.join("\n")}</bpo>)
1054
1022
  end
1055
1023
 
1056
1024
  def inline_dtp(str)
@@ -1058,17 +1026,17 @@ module ReVIEW
1058
1026
  end
1059
1027
 
1060
1028
  def inline_code(str)
1061
- %Q[<tt type='inline-code'>#{escape_html(str)}</tt>]
1029
+ %Q(<tt type='inline-code'>#{escape_html(str)}</tt>)
1062
1030
  end
1063
1031
 
1064
- def inline_br(str)
1032
+ def inline_br(_str)
1065
1033
  "\n"
1066
1034
  end
1067
1035
 
1068
1036
  def rawblock(lines)
1069
1037
  no = 1
1070
1038
  lines.each do |l|
1071
- print l.gsub("&lt;", "<").gsub("&gt;", ">").gsub("&quot;", "\"").gsub("&amp;", "&")
1039
+ print l.gsub('&lt;', '<').gsub('&gt;', '>').gsub('&quot;', '"').gsub('&amp;', '&')
1072
1040
  print "\n" unless lines.length == no
1073
1041
  no += 1
1074
1042
  end
@@ -1079,17 +1047,17 @@ module ReVIEW
1079
1047
  end
1080
1048
 
1081
1049
  def inline_chapref(id)
1082
- chs = ["", "", ""]
1083
- if @book.config["chapref"]
1084
- _chs = @book.config["chapref"].split(",")
1085
- if _chs.size != 3
1086
- error "--chapsplitter must have exactly 3 parameters with comma."
1050
+ chs = ['', '', '']
1051
+ if @book.config['chapref']
1052
+ chs2 = @book.config['chapref'].split(',')
1053
+ if chs2.size != 3
1054
+ error '--chapsplitter must have exactly 3 parameters with comma.'
1087
1055
  else
1088
- chs = _chs
1056
+ chs = chs2
1089
1057
  end
1090
1058
  end
1091
1059
  s = "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
1092
- if @book.config["chapterlink"]
1060
+ if @book.config['chapterlink']
1093
1061
  %Q(<link href="#{id}">#{s}</link>)
1094
1062
  else
1095
1063
  s
@@ -1100,7 +1068,7 @@ module ReVIEW
1100
1068
  end
1101
1069
 
1102
1070
  def inline_chap(id)
1103
- if @book.config["chapterlink"]
1071
+ if @book.config['chapterlink']
1104
1072
  %Q(<link href="#{id}">#{@book.chapter_index.number(id)}</link>)
1105
1073
  else
1106
1074
  @book.chapter_index.number(id)
@@ -1112,7 +1080,7 @@ module ReVIEW
1112
1080
 
1113
1081
  def inline_title(id)
1114
1082
  title = super
1115
- if @book.config["chapterlink"]
1083
+ if @book.config['chapterlink']
1116
1084
  %Q(<link href="#{id}">#{title}</link>)
1117
1085
  else
1118
1086
  title
@@ -1123,31 +1091,29 @@ module ReVIEW
1123
1091
  end
1124
1092
 
1125
1093
  def source_header(caption)
1126
- puts %Q[<source>]
1127
- puts %Q[<caption>#{compile_inline(caption)}</caption>]
1094
+ puts '<source>'
1095
+ puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
1128
1096
  end
1129
1097
 
1130
- def source_body(lines, lang)
1131
- puts %Q[<pre>]
1098
+ def source_body(lines, _lang)
1099
+ puts '<pre>'
1132
1100
  codelines_body(lines)
1133
- puts %Q[</pre></source>]
1101
+ puts '</pre></source>'
1134
1102
  end
1135
1103
 
1136
1104
  def bibpaper(lines, id, caption)
1137
1105
  bibpaper_header id, caption
1138
- unless lines.empty?
1139
- bibpaper_bibpaper id, caption, lines
1140
- end
1141
- puts %Q(</bibitem>)
1106
+ bibpaper_bibpaper id, caption, lines unless lines.empty?
1107
+ puts '</bibitem>'
1142
1108
  end
1143
1109
 
1144
1110
  def bibpaper_header(id, caption)
1145
1111
  puts %Q(<bibitem id="bib-#{id}">)
1146
- puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>"
1112
+ puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>" if caption.present?
1147
1113
  end
1148
1114
 
1149
- def bibpaper_bibpaper(id, caption, lines)
1150
- print split_paragraph(lines).join("")
1115
+ def bibpaper_bibpaper(_id, _caption, lines)
1116
+ print split_paragraph(lines).join
1151
1117
  end
1152
1118
 
1153
1119
  def inline_bib(id)
@@ -1157,11 +1123,11 @@ module ReVIEW
1157
1123
  def inline_hd_chap(chap, id)
1158
1124
  if chap.number
1159
1125
  n = chap.headline_index.number(id)
1160
- if @book.config["secnolevel"] >= n.split('.').size
1161
- return I18n.t("chapter_quote", "#{n} #{compile_inline(chap.headline(id).caption)}")
1126
+ if @book.config['secnolevel'] >= n.split('.').size
1127
+ return I18n.t('chapter_quote', "#{n} #{compile_inline(chap.headline(id).caption)}")
1162
1128
  end
1163
1129
  end
1164
- I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
1130
+ I18n.t('chapter_quote', compile_inline(chap.headline(id).caption))
1165
1131
  end
1166
1132
 
1167
1133
  def inline_recipe(id)
@@ -1174,9 +1140,7 @@ module ReVIEW
1174
1140
  end
1175
1141
 
1176
1142
  def image_ext
1177
- "eps"
1143
+ 'eps'
1178
1144
  end
1179
-
1180
1145
  end
1181
-
1182
1146
  end # module ReVIEW