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
data/.travis.yml CHANGED
@@ -1,9 +1,18 @@
1
+ language: ruby
2
+ sudo: false
3
+
1
4
  rvm:
2
5
  - 1.9.3
3
6
  - 2.0.0
4
7
  - 2.1.*
5
8
  - 2.2.*
9
+ - ruby-head
6
10
 
7
11
  branches:
8
12
  only:
9
13
  - master
14
+
15
+ script:
16
+ - bundle exec rake test
17
+ - bundle exec rubocop
18
+
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Thu Oct 29 13:58:22 2015 KADO Masanori <kdmsnr@gmail.com>
2
+
3
+ * Release 1.7.0
4
+
1
5
  Mon Jun 29 18:16:06 2015 KADO Masanori <kdmsnr@gmail.com>
2
6
 
3
7
  * Release 1.6.0
data/Dockerfile ADDED
@@ -0,0 +1,22 @@
1
+ # This file is a sample Dockerfile to build Re:VIEW documents.
2
+ #
3
+ # Build:
4
+ # $ docker build -t review .
5
+ #
6
+ # Usage:
7
+ # $ cd path/to/review/project
8
+ # $ docker run -it --rm -v `pwd`:/work review rake pdf
9
+ #
10
+ # cf. https://github.com/vvakame/docker-review/blob/master/Dockerfile
11
+
12
+ FROM debian:sid
13
+ MAINTAINER takahashim
14
+
15
+ RUN apt-get update \
16
+ && apt-get install -y --no-install-recommends git-core ruby locales zip \
17
+ && apt-get install -y --no-install-recommends texlive-lang-cjk texlive-lang-japanese texlive-fonts-recommended texlive-latex-extra ghostscript \
18
+ && rm -rf /var/lib/apt/lists/*
19
+ RUN gem install review rake bundler --no-rdoc --no-ri
20
+
21
+ VOLUME ["/work"]
22
+ WORKDIR /work
data/README.rdoc CHANGED
@@ -78,4 +78,4 @@ LGPL. See COPYING file.
78
78
 
79
79
  == Copyright
80
80
 
81
- Copyright (c) 2006-2014 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado.
81
+ Copyright (c) 2006-2015 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'rake/clean'
12
12
  task :default => [:test]
13
13
 
14
14
  Rake::TestTask.new("test") do |t|
15
- t.libs << "test"
15
+ t.libs << "test"
16
16
  t.test_files = Dir.glob("test/**/test_*.rb")
17
17
  t.verbose = true
18
18
  end
data/bin/review-check CHANGED
@@ -31,12 +31,7 @@ rescue Errno::EPIPE
31
31
  end
32
32
 
33
33
  def main
34
- $KCODE = 'UTF-8' unless defined?(Encoding)
35
34
  @config = ReVIEW::Configure.values
36
- @config.merge!({
37
- "inencoding" => "UTF-8",
38
- "outencoding" => "UTF-8"
39
- })
40
35
  @book = ReVIEW::Book::Base.load
41
36
  @book.config = @config
42
37
 
@@ -44,12 +39,6 @@ def main
44
39
  files = ARGV unless ARGV.empty?
45
40
  opts = OptionParser.new
46
41
  opts.version = ReVIEW::VERSION
47
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc|
48
- @config["inencoding"] = enc
49
- }
50
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc|
51
- @config["outencoding"] = enc
52
- }
53
42
  opts.on('-a', '--all-chapters', 'Check all chapters.') {
54
43
  files = @book.chapters.map {|ent| ent.path }
55
44
  }
@@ -95,11 +84,11 @@ def check_text(files)
95
84
  each_paragraph(f) do |para, lineno|
96
85
  s = para.join('')
97
86
  if m = re.match(s)
98
- next if m[0] == $ReVIEW_utils_word_ok
87
+ next if m[0] == @review_utils_word_ok
99
88
  next if neg and neg =~ s
100
89
  str, offset = find_line(para, re)
101
90
  out = sprintf("%s:%d: %s\n", path, lineno + offset, str)
102
- print convert_outencoding(out, @config["outencoding"])
91
+ print out
103
92
  end
104
93
  end
105
94
  }
@@ -109,14 +98,14 @@ end
109
98
  def find_line(lines, re)
110
99
  # single line?
111
100
  lines.each_with_index do |line, idx|
112
- return line.gsub(re, '<<<\&>>>'), idx if re =~ line
101
+ return line.gsub(re, '<<<\&>>>'), idx if re =~ line
113
102
  end
114
103
 
115
104
  # multiple lines?
116
105
  i = 0
117
106
  while i < lines.size - 1
118
107
  str = lines[i] + lines[i+1]
119
- return str.gsub(re, '<<<\&>>>'), i if re =~ str
108
+ return str.gsub(re, '<<<\&>>>'), i if re =~ str
120
109
  i += 1
121
110
  end
122
111
 
@@ -127,7 +116,7 @@ def words_re(rc)
127
116
  words = []
128
117
  nega = []
129
118
  File.foreach(rc) do |line|
130
- next if line[0,1] == '#'
119
+ next if line[0,1] == '#'
131
120
  if / !/ =~ line
132
121
  line, n = *line.split(/!/, 2)
133
122
  nega.push n.strip
@@ -139,13 +128,11 @@ def words_re(rc)
139
128
  end
140
129
 
141
130
  def each_paragraph(f)
142
- $ReVIEW_utils_word_ok = nil
131
+ @review_utils_word_ok = nil
143
132
  while line = f.gets
144
- line = convert_inencoding(line, @config["inencoding"])
145
-
146
133
  case line
147
134
  when /\A\#@ok\((.*)\)/
148
- $ReVIEW_utils_word_ok = $1
135
+ @review_utils_word_ok = $1
149
136
  when /\A\#@/
150
137
  ;
151
138
  when %r[\A//caption\{(.*?)//\}]
@@ -168,7 +155,7 @@ def each_paragraph(f)
168
155
  buf.push line.strip
169
156
  end
170
157
  yield buf, lineno
171
- $ReVIEW_utils_word_ok = nil
158
+ @review_utils_word_ok = nil
172
159
  end
173
160
  end
174
161
  end
data/bin/review-compile CHANGED
@@ -34,8 +34,6 @@ rescue Errno::EPIPE
34
34
  end
35
35
 
36
36
  def _main
37
- $KCODE = 'UTF-8' unless defined?(Encoding)
38
-
39
37
  mode = :files
40
38
  basedir = nil
41
39
  if /\Areview2/ =~ File.basename($0)
@@ -48,16 +46,14 @@ def _main
48
46
 
49
47
  config = ReVIEW::Configure.values
50
48
  config.merge!({
51
- "secnolevel" => 2, # for IDGXML and HTML
52
- "tableopt" => nil, # for IDGXML
53
- "nolf" => nil, # for IDGXML
54
- "chapref" => nil, # for IDGXML
49
+ "secnolevel" => 2, # for IDGXML and HTML
50
+ "tableopt" => nil, # for IDGXML
51
+ "nolf" => nil, # for IDGXML
52
+ "chapref" => nil, # for IDGXML
55
53
  "structuredxml" => nil, # for IDGXML
56
- "inencoding" => "UTF-8",
57
- "outencoding" => "UTF-8",
58
- "stylesheet" => [], # for HTML
59
- "mathml" => nil, # for HTML
60
- "language" => "ja", # for HTML
54
+ "stylesheet" => [], # for HTML
55
+ "mathml" => nil, # for HTML
56
+ "language" => "ja", # for HTML
61
57
  "deprecated-blocklines" => nil,
62
58
  "footnotetext" => false,
63
59
  "htmlext" => "html",
@@ -71,8 +67,6 @@ def _main
71
67
  require 'yaml'
72
68
  config = config.merge(YAML.load_file(yaml))
73
69
  end
74
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc| config["inencoding"] = enc }
75
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc| config["outencoding"] = enc }
76
70
  opts.on('-c', '--check', 'Check manuscript') { check_only = true }
77
71
  opts.on('--level=LVL', 'Section level to append number.') {|lvl| config["secnolevel"] = lvl.to_i }
78
72
  opts.on('--toclevel=LVL', 'Section level to append number.') {|lvl| config["toclevel"] = lvl.to_i }
@@ -173,12 +167,12 @@ def _main
173
167
  compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
174
168
  book.chapters.each do |chap|
175
169
  str = compiler.compile(chap)
176
- write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
170
+ write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
177
171
  end
178
172
  # PART
179
173
  book.parts_in_file.each do |part|
180
174
  str = compiler.compile(part)
181
- write "#{part.name}#{compiler.strategy.extname}", str unless check_only
175
+ write "#{part.name}#{compiler.strategy.extname}", str unless check_only
182
176
  end
183
177
  else
184
178
  raise "must not happen: #{mode}"
@@ -28,7 +28,7 @@ require 'review/i18n'
28
28
  require 'review/htmlutils'
29
29
  include ReVIEW::HTMLUtils
30
30
 
31
- $essential_files = ['top', 'toc', 'colophon']
31
+ @essential_files = ['top', 'toc', 'colophon']
32
32
  def main
33
33
  opts = OptionParser.new
34
34
  opts.version = ReVIEW::VERSION
@@ -57,7 +57,7 @@ def main
57
57
  yamlfile = ARGV[0]
58
58
  values = ReVIEW::Configure.values.merge(YAML.load_file(yamlfile))
59
59
  bookname = values["bookname"]
60
- $essential_files <<= bookname
60
+ @essential_files <<= bookname
61
61
  tmp = values["debug"].nil? ? Dir.mktmpdir : "."
62
62
  @bookdir = "#{tmp}/#{bookname}-epub"
63
63
  @epubversion = values["epubversion"] || 2
@@ -774,8 +774,8 @@ end
774
774
 
775
775
  def output_chaps_by_file(l, values)
776
776
  file_id = File.basename(l.chomp.strip,".*")
777
- if (idx = $essential_files.index(file_id))
778
- if idx == $essential_files.size - 1
777
+ if (idx = @essential_files.index(file_id))
778
+ if idx == @essential_files.size - 1
779
779
  STDERR.puts "#{file_id} is book name. Please rename #{l.chomp.strip}."
780
780
  else
781
781
  STDERR.puts "#{file_id} is special name. Please rename #{l.chomp.strip}."
@@ -800,8 +800,8 @@ def include_mathml?(filename)
800
800
  }
801
801
  return false
802
802
  }
803
- rescue
804
- false
803
+ rescue
804
+ false
805
805
  end
806
806
 
807
807
  def getFigId(filename)
data/bin/review-index CHANGED
@@ -32,25 +32,14 @@ rescue Errno::EPIPE
32
32
  end
33
33
 
34
34
  def _main
35
- $KCODE = 'UTF-8' unless defined?(Encoding)
36
-
37
35
  printer_class = ReVIEW::TextTOCPrinter
38
36
  source = nil
39
37
  upper = ReVIEW::TOCPrinter.default_upper_level
40
- param = {
41
- "inencoding" => "UTF-8",
42
- "outencoding" => "UTF-8"
43
- }
38
+ param = {}
44
39
  book = ReVIEW::Book::Base.load
45
40
 
46
41
  opts = OptionParser.new
47
42
  opts.version = ReVIEW::VERSION
48
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc|
49
- param["inencoding"] = enc
50
- }
51
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc|
52
- param["outencoding"] = enc
53
- }
54
43
  opts.on('-a', '--all', 'print all chapters.') {
55
44
  begin
56
45
  source = book
@@ -71,7 +60,7 @@ def _main
71
60
  }
72
61
  opts.on('-l', '--level N', 'list upto N level (1..4, default=4)') {|n|
73
62
  upper = Integer(n)
74
- unless (0..4).include?(upper) # 0 is hidden option
63
+ unless (0..4).include?(upper) # 0 is hidden option
75
64
  $stderr.puts "-l/--level option accepts only 1..4"
76
65
  exit 1
77
66
  end
data/bin/review-preproc CHANGED
@@ -35,25 +35,12 @@ rescue Errno::EPIPE
35
35
  end
36
36
 
37
37
  def main
38
- $KCODE = 'UTF-8' unless defined?(Encoding)
39
-
40
- param = {
41
- "inencoding" => "UTF-8",
42
- "outencoding" => "UTF-8",
43
- }
38
+ param = {}
44
39
 
45
40
  mode = :output
46
41
  opts = OptionParser.new
47
42
  opts.version = ReVIEW::VERSION
48
43
  opts.banner = "Usage: #{File.basename($0)} [-c|-d|-s|--replace] [<file>...]"
49
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and
50
- SJIS)') {|enc|
51
- param["inencoding"] = enc
52
- }
53
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC
54
- , JIS, and SJIS)') {|enc|
55
- param["outencoding"] = enc
56
- }
57
44
  opts.on('-c', '--check', 'Check if preprocess is needed.') {
58
45
  mode = :check
59
46
  }
data/bin/review-validate CHANGED
@@ -15,7 +15,7 @@ colcount = 0
15
15
  ln = 0
16
16
 
17
17
  ARGF.each {|line|
18
- ln = ln + 1
18
+ ln += 1
19
19
  if line =~ /\A\/\/([a-z]+).+\{/
20
20
  # block
21
21
  _block = $1
data/bin/review-vol CHANGED
@@ -21,13 +21,7 @@ require 'optparse'
21
21
  include ReVIEW::TextUtils
22
22
 
23
23
  def main
24
- $KCODE = 'UTF-8' unless defined?(Encoding)
25
-
26
24
  @config = ReVIEW::Configure.values
27
- @config.merge!({
28
- "inencoding" => "UTF-8",
29
- "outencoding" => "UTF-8"
30
- })
31
25
 
32
26
  part_sensitive = false
33
27
  basedir = nil
@@ -40,12 +34,6 @@ def main
40
34
  opts.on('-P', '--part-sensitive', 'Prints volume of each parts.') {
41
35
  part_sensitive = true
42
36
  }
43
- opts.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc|
44
- @config["inencoding"] = enc
45
- }
46
- opts.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc|
47
- @config["outencoding"] = enc
48
- }
49
37
  opts.on('--directory=DIR', 'Compile all chapters in DIR.') {|path|
50
38
  basedir = path
51
39
  }
@@ -95,7 +83,7 @@ end
95
83
 
96
84
  def print_chapter_volume(chap)
97
85
  vol = chap.volume
98
- title = convert_outencoding(chap.title, @config["outencoding"])
86
+ title = chap.title
99
87
  printf "%s %3dKB %6dC %5dL %3dP %s %-s\n",
100
88
  chapnumstr(chap.number), vol.kbytes, vol.chars, vol.lines, vol.page,
101
89
  "#{chap.name} ".ljust(25, '.'), title
data/doc/NEWS.ja.md CHANGED
@@ -1,3 +1,25 @@
1
+ # Version 1.7.0の主な変更点
2
+
3
+ ## 全般
4
+ * Rubocopの設定の追加とそれに伴うリファクタリングを実施しました
5
+ * 内部の文字コードをUTF-8に統一しました ([#399])
6
+ * Dockerfileを追加しました
7
+
8
+ ## バグ修正
9
+ * コードハイライト無効時に、htmlbuilderでlistnumおよびemlistnumにおいて行番号が表示されないバグを修正しました ([#449])
10
+
11
+ ## ビルダーとメーカー
12
+
13
+ ### epubmaker
14
+ * 綴じ方向を設定する``direction``パラメータをサポートしました ([#435])
15
+
16
+ ## コードコントリビュータ
17
+ * [@snoozer05](https://github.com/snoozer05)
18
+
19
+ [#399]: https://github.com/kmuto/review/pull/399
20
+ [#435]: https://github.com/kmuto/review/pull/435
21
+ [#449]: https://github.com/kmuto/review/issues/449
22
+
1
23
  # Version 1.6.0の主な変更点
2
24
 
3
25
  ## 全般
data/doc/NEWS.md CHANGED
@@ -1,3 +1,25 @@
1
+ # Version 1.7.0
2
+
3
+ ## In general
4
+ * Set up Rubocop settings and refactor code with the settings
5
+ * Change the internal encoding to UTF-8 altogether ([#399])
6
+ * Add a Dockerfile
7
+
8
+ ## Bug Fix
9
+ * Fix htmlbuilder to display line numbers with listnum/emlistnum under a syntax highlighting environment ([#449])
10
+
11
+ ## Builders and Makers
12
+
13
+ ### epubmaker
14
+ * Support ``direction`` parameter to set binding direction ([#435])
15
+
16
+ ## Code contributors
17
+ * [@snoozer05](https://github.com/snoozer05)
18
+
19
+ [#399]: https://github.com/kmuto/review/pull/399
20
+ [#435]: https://github.com/kmuto/review/pull/435
21
+ [#449]: https://github.com/kmuto/review/issues/449
22
+
1
23
  # Version 1.6.0
2
24
 
3
25
  ## In general
data/doc/quickstart.ja.md CHANGED
@@ -161,7 +161,7 @@ sample.re を HTML に変換すると、次のようになります。
161
161
  </html>
162
162
  ```
163
163
 
164
- Re:VIEW フォーマットについての詳細は、 [format.rdoc](https://github.com/kmuto/review/blob/master/doc/format.rdoc) を参照してください。
164
+ Re:VIEW フォーマットについての詳細は、 [format.ja.md](https://github.com/kmuto/review/blob/master/doc/format.ja.md) を参照してください。
165
165
 
166
166
  review-compile を含め、ほとんどのコマンドは `--help` オプションを付けるとオプションについてのヘルプが表示されます。`review-compile` には多数のオプションがあるので確認してください。
167
167
 
data/doc/quickstart.md CHANGED
@@ -191,7 +191,7 @@ You can get HTML file as follows:
191
191
  </html>
192
192
  ```
193
193
 
194
- For more information about Re:VIEW format, see [format.rdoc](https://github.com/kmuto/review/blob/master/doc/format.rdoc).
194
+ For more information about Re:VIEW format, see [format.md](https://github.com/kmuto/review/blob/master/doc/format.md).
195
195
 
196
196
  review-compile and other commands in Re:VIEW has `--help` option to output help. `review-compile` has many options, so you may see them.
197
197
 
@@ -60,12 +60,12 @@ module EPUBMaker
60
60
  complement
61
61
  end
62
62
 
63
- def ==(obj)
64
- if self.class != obj.class
63
+ def ==(other)
64
+ if self.class != other.class
65
65
  return false
66
66
  end
67
67
  [self.id, self.file, self.media, self.title, self.level, self.notoc, self.chaptype, self.properties] ==
68
- [obj.id, obj.file, obj.media, obj.title, obj.level, obj.notoc, obj.chaptype, obj.properties]
68
+ [other.id, other.file, other.media, other.title, other.level, other.notoc, other.chaptype, other.properties]
69
69
  end
70
70
 
71
71
  private