review 2.5.0 → 3.0.0.preview1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -10
  3. data/.travis.yml +11 -2
  4. data/NEWS.ja.md +89 -17
  5. data/NEWS.md +92 -0
  6. data/README.md +1 -1
  7. data/Rakefile +0 -13
  8. data/bin/review-catalog-converter +83 -37
  9. data/bin/review-check +17 -5
  10. data/bin/review-compile +1 -1
  11. data/bin/review-index +6 -0
  12. data/bin/review-init +3 -155
  13. data/bin/review-preproc +0 -5
  14. data/bin/review-validate +21 -7
  15. data/bin/review-vol +13 -5
  16. data/doc/config.yml.sample +12 -7
  17. data/doc/config.yml.sample-simple +1 -1
  18. data/doc/format.ja.md +39 -3
  19. data/doc/format.md +39 -3
  20. data/doc/format_idg.ja.md +0 -4
  21. data/doc/pdfmaker.ja.md +1 -1
  22. data/doc/pdfmaker.md +1 -1
  23. data/doc/sample.css +7 -0
  24. data/lib/epubmaker/content.rb +31 -12
  25. data/lib/epubmaker/epubcommon.rb +10 -3
  26. data/lib/epubmaker/epubv2.rb +11 -3
  27. data/lib/epubmaker/epubv3.rb +11 -3
  28. data/lib/epubmaker/producer.rb +55 -20
  29. data/lib/review/book/base.rb +63 -48
  30. data/lib/review/book/chapter.rb +19 -7
  31. data/lib/review/book/compilable.rb +5 -20
  32. data/lib/review/book/image_finder.rb +10 -3
  33. data/lib/review/book/index.rb +30 -9
  34. data/lib/review/book/part.rb +9 -6
  35. data/lib/review/book.rb +0 -14
  36. data/lib/review/builder.rb +110 -18
  37. data/lib/review/catalog.rb +24 -4
  38. data/lib/review/compiler.rb +3 -1
  39. data/lib/review/configure.rb +43 -9
  40. data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
  41. data/lib/review/epubmaker.rb +129 -85
  42. data/lib/review/htmlbuilder.rb +76 -58
  43. data/lib/review/htmlutils.rb +20 -13
  44. data/lib/review/i18n.rb +6 -2
  45. data/lib/review/idgxmlbuilder.rb +52 -41
  46. data/lib/review/init.rb +194 -0
  47. data/lib/review/latexbuilder.rb +118 -34
  48. data/lib/review/latexutils.rb +5 -5
  49. data/lib/review/logger.rb +2 -1
  50. data/lib/review/makerhelper.rb +1 -1
  51. data/lib/review/markdownbuilder.rb +66 -6
  52. data/lib/review/md2inaobuilder.rb +2 -2
  53. data/lib/review/pdfmaker.rb +74 -22
  54. data/lib/review/plaintextbuilder.rb +8 -4
  55. data/lib/review/preprocessor.rb +14 -17
  56. data/lib/review/sec_counter.rb +8 -2
  57. data/lib/review/textmaker.rb +2 -2
  58. data/lib/review/textutils.rb +9 -2
  59. data/lib/review/tocparser.rb +7 -4
  60. data/lib/review/tocprinter.rb +3 -1
  61. data/lib/review/version.rb +1 -1
  62. data/lib/review/webmaker.rb +19 -7
  63. data/lib/review/webtocprinter.rb +8 -4
  64. data/review.gemspec +4 -3
  65. data/templates/latex/config.erb +84 -0
  66. data/templates/latex/layout.tex.erb +76 -361
  67. data/templates/latex/review-jlreq/README.md +22 -0
  68. data/templates/latex/review-jlreq/review-base.sty +178 -0
  69. data/templates/latex/review-jlreq/review-custom.sty +1 -0
  70. data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
  71. data/templates/latex/review-jlreq/review-style.sty +149 -0
  72. data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
  73. data/templates/latex/review-jsbook/jumoline.sty +310 -0
  74. data/templates/latex/review-jsbook/plistings.sty +326 -0
  75. data/templates/latex/review-jsbook/review-base.sty +405 -0
  76. data/templates/latex/review-jsbook/review-custom.sty +1 -0
  77. data/templates/latex/review-jsbook/review-style.sty +38 -0
  78. data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
  79. data/templates/latex-compat2/layout.tex.erb +387 -0
  80. data/test/assets/test_template.tex +105 -235
  81. data/test/assets/test_template_backmatter.tex +133 -14
  82. data/test/book_test_helper.rb +1 -1
  83. data/test/run_test.rb +2 -0
  84. data/test/sample-book/src/Rakefile +11 -6
  85. data/test/sample-book/src/config.yml +2 -2
  86. data/test/sample-book/src/sty/reviewmacro.sty +1 -39
  87. data/test/sample-book/src/style.css +6 -0
  88. data/test/syntax-book/config.yml +1 -1
  89. data/test/test_book.rb +13 -16
  90. data/test/test_book_chapter.rb +4 -10
  91. data/test/test_book_part.rb +4 -3
  92. data/test/test_catalog.rb +15 -4
  93. data/test/test_helper.rb +2 -2
  94. data/test/test_htmlbuilder.rb +78 -10
  95. data/test/test_htmlutils.rb +12 -5
  96. data/test/test_idgxmlbuilder.rb +1 -1
  97. data/test/test_latexbuilder.rb +94 -49
  98. data/test/test_latexbuilder_v2.rb +1077 -0
  99. data/test/test_logger.rb +20 -0
  100. data/test/test_markdownbuilder.rb +10 -0
  101. data/test/test_pdfmaker.rb +6 -7
  102. data/test/test_plaintextbuilder.rb +1 -1
  103. data/test/test_review_ext.rb +0 -1
  104. data/test/test_rstbuilder.rb +1 -1
  105. data/test/test_topbuilder.rb +19 -7
  106. data/test/test_webtocprinter.rb +14 -14
  107. data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
  108. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
  109. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
  110. data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
  111. data/vendor/plistings/.gitignore +9 -0
  112. data/vendor/plistings/LICENSE +21 -0
  113. data/vendor/plistings/README.md +18 -0
  114. data/vendor/plistings/plistings.sty +326 -0
  115. data/vendor/plistings/test1.tex +174 -0
  116. data/vendor/plistings/test2.tex +54 -0
  117. metadata +48 -19
  118. data/lib/review/unfold.rb +0 -129
  119. data/test/CHAPS +0 -2
  120. data/test/bib.re +0 -13
  121. data/test/test.re +0 -43
@@ -35,12 +35,6 @@ class ChapterTest < Test::Unit::TestCase
35
35
  # assert_raises(TypeError) { ch.name } # XXX: OK?
36
36
  end
37
37
 
38
- def test_open
39
- ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
40
- assert_equal :io, ch.open
41
- assert_equal [:io], (ch.open { |io| [io] })
42
- end
43
-
44
38
  def test_size
45
39
  ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
46
40
  assert_equal File.size(__FILE__), ch.size
@@ -53,7 +47,7 @@ class ChapterTest < Test::Unit::TestCase
53
47
 
54
48
  def test_title
55
49
  io = StringIO.new
56
- book = Book::Base.new(nil)
50
+ book = Book::Base.new
57
51
  ch = Book::Chapter.new(book, nil, nil, nil, io)
58
52
  assert_equal '', ch.title
59
53
 
@@ -68,7 +62,7 @@ class ChapterTest < Test::Unit::TestCase
68
62
  tf.print lines.join
69
63
  tf.close
70
64
 
71
- book = Book::Base.new(nil)
65
+ book = Book::Base.new
72
66
  ch = Book::Chapter.new(book, nil, nil, tf.path)
73
67
  assert_equal lines, ch.lines
74
68
 
@@ -95,12 +89,12 @@ class ChapterTest < Test::Unit::TestCase
95
89
  tf2.print content
96
90
  tf2.close
97
91
 
98
- book = Book::Base.new(nil)
92
+ book = Book::Base.new
99
93
  ch = Book::Chapter.new(book, nil, nil, tf1.path)
100
94
  assert ch.volume
101
95
  assert_equal content.gsub(/\s/, '').size, ch.volume.bytes
102
96
 
103
- book = Book::Base.new(nil)
97
+ book = Book::Base.new
104
98
  ch = Book::Chapter.new(book, nil, nil, tf1.path, tf2)
105
99
  assert ch.volume
106
100
  assert_equal content.gsub(/\s/, '').size, ch.volume.bytes # XXX: OK?
@@ -3,12 +3,13 @@ class PartTest < Test::Unit::TestCase
3
3
  include BookTestHelper
4
4
 
5
5
  def test_initialize
6
- part = Book::Part.new(nil, nil, nil)
6
+ book = Book::Base.new
7
+ part = Book::Part.new(book, nil, nil)
7
8
  assert_equal nil, part.number
8
9
  assert_equal nil, part.chapters
9
10
  assert_equal '', part.name
10
11
 
11
- part = Book::Part.new(nil, 123, [], 'name')
12
+ part = Book::Part.new(book, 123, [], 'name')
12
13
  assert_equal 123, part.number
13
14
  assert_equal [], part.chapters
14
15
  assert_equal 'name', part.name
@@ -23,7 +24,7 @@ class PartTest < Test::Unit::TestCase
23
24
  end
24
25
 
25
26
  def test_volume
26
- book = Book::Base.new(nil)
27
+ book = Book::Base.new
27
28
  part = Book::Part.new(book, nil, [])
28
29
  assert part.volume
29
30
  assert_equal 0, part.volume.bytes
data/test/test_catalog.rb CHANGED
@@ -97,7 +97,7 @@ ch02.re
97
97
  FileUtils.touch(file)
98
98
  end
99
99
  cat = Catalog.new(yaml_hash)
100
- cat.validate!(dir)
100
+ cat.validate!({ 'contentdir' => '.' }, dir)
101
101
  end
102
102
  end
103
103
 
@@ -107,7 +107,7 @@ ch02.re
107
107
  FileUtils.touch(file)
108
108
  end
109
109
  cat = Catalog.new(yaml_with_parts)
110
- cat.validate!(dir)
110
+ cat.validate!({ 'contentdir' => '.' }, dir)
111
111
  end
112
112
  end
113
113
 
@@ -118,7 +118,7 @@ ch02.re
118
118
  FileUtils.touch(file)
119
119
  end
120
120
  cat = Catalog.new(yaml_hash)
121
- cat.validate!(dir)
121
+ cat.validate!({ 'contentdir' => '.' }, dir)
122
122
  end
123
123
  end
124
124
  end
@@ -130,11 +130,22 @@ ch02.re
130
130
  FileUtils.touch(file)
131
131
  end
132
132
  cat = Catalog.new(yaml_hash)
133
- cat.validate!(dir)
133
+ cat.validate!({ 'contentdir' => '.' }, dir)
134
134
  end
135
135
  end
136
136
  end
137
137
 
138
+ def test_validate_contentdir
139
+ mktmpbookdir do |dir, _book, _files|
140
+ Dir.mkdir('content')
141
+ %w[content/pre01.re content/pre02.re content/ch01.re content/ch02.re content/post01.re content/post02.re content/back01.re content/back02.re].each do |file|
142
+ FileUtils.touch(file)
143
+ end
144
+ cat = Catalog.new(yaml_hash)
145
+ cat.validate!({ 'contentdir' => 'content' }, dir)
146
+ end
147
+ end
148
+
138
149
  private
139
150
 
140
151
  def yaml
data/test/test_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
2
2
  require 'test/unit'
3
+ require 'fileutils'
3
4
 
4
5
  def touch_file(path)
5
- File.open(path, 'w').close
6
- path
6
+ FileUtils.touch(path)
7
7
  end
8
8
 
9
9
  def assets_dir
@@ -1,8 +1,10 @@
1
1
  require 'test_helper'
2
+ require 'book_test_helper'
2
3
  require 'review'
3
4
 
4
5
  class HTMLBuidlerTest < Test::Unit::TestCase
5
6
  include ReVIEW
7
+ include BookTestHelper
6
8
 
7
9
  def setup
8
10
  ReVIEW::I18n.setup
@@ -297,6 +299,11 @@ class HTMLBuidlerTest < Test::Unit::TestCase
297
299
  assert_equal 'test &#x2460; test2', actual
298
300
  end
299
301
 
302
+ def test_inline_balloon
303
+ actual = compile_inline('test @<balloon>{①}')
304
+ assert_equal %Q(test <span class="balloon">①</span>), actual
305
+ end
306
+
300
307
  def test_inline_ruby
301
308
  actual = compile_inline('@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。')
302
309
  assert_equal '<ruby>粗雑<rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby>繊細<rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。', actual
@@ -436,8 +443,7 @@ EOS
436
443
  end
437
444
 
438
445
  def test_noindent
439
- @builder.noindent
440
- actual = compile_block("foo\nbar\n\nfoo2\nbar2\n")
446
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
441
447
  assert_equal %Q(<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n), actual
442
448
  end
443
449
 
@@ -747,14 +753,6 @@ EOS
747
753
  assert_equal %Q(<div id="samplelist" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list highlight">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n</pre>\n</div>\n), actual
748
754
  end
749
755
 
750
- def test_list_ext
751
- def @chapter.list(_id)
752
- Book::ListIndex::Item.new('samplelist.rb', 1)
753
- end
754
- actual = compile_block("//list[samplelist.rb][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
755
- assert_equal %Q(<div id="samplelist.rb" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list language-rb">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n), actual
756
- end
757
-
758
756
  def test_listnum
759
757
  def @chapter.list(_id)
760
758
  Book::ListIndex::Item.new('samplelist', 1)
@@ -1068,6 +1066,59 @@ EOS
1068
1066
  assert_equal %Q(<div class="cmd-code">\n<p class="caption">cap1</p>\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n), actual
1069
1067
  end
1070
1068
 
1069
+ def test_texequation
1070
+ return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
1071
+ return true unless system('latex -version 1>/dev/null 2>/dev/null')
1072
+ mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1073
+ 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P} q\n//}\n") do |dir, book, _files|
1074
+ @book = book
1075
+ @book.config = @config
1076
+ @config['imgmath'] = true
1077
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1078
+ location = Location.new(nil, nil)
1079
+ @builder.bind(@compiler, @chapter, location)
1080
+ FileUtils.mkdir_p(File.join(dir, 'images'))
1081
+ expected = <<-EOB
1082
+ <div class=\"equation\">
1083
+ <img src=\"././images/_review_math/_gen_XXX.png\" />
1084
+ </div>
1085
+ EOB
1086
+ tmpio = $stderr
1087
+ $stderr = StringIO.new
1088
+ begin
1089
+ result = compile_block("//texequation{\np \\land \\bm{P} q\n//}\n")
1090
+ ensure
1091
+ $stderr = tmpio
1092
+ end
1093
+ actual = result.gsub(/_gen_[0-9a-f]+\.png/, '_gen_XXX.png')
1094
+ assert_equal expected, actual
1095
+ end
1096
+ end
1097
+
1098
+ def test_texequation_fail
1099
+ return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
1100
+ return true unless system('latex -version 1>/dev/null 2>/dev/null')
1101
+ mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
1102
+ 'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P}} q\n//}\n") do |dir, book, _files|
1103
+ @book = book
1104
+ @book.config = @config
1105
+ @config['imgmath'] = true
1106
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
1107
+ location = Location.new(nil, nil)
1108
+ @builder.bind(@compiler, @chapter, location)
1109
+ FileUtils.mkdir_p(File.join(dir, 'images'))
1110
+ tmpio = $stderr
1111
+ $stderr = StringIO.new
1112
+ begin
1113
+ assert_raise(ReVIEW::ApplicationError) do
1114
+ _result = compile_block("//texequation{\np \\land \\bm{P}} q\n//}\n")
1115
+ end
1116
+ ensure
1117
+ $stderr = tmpio
1118
+ end
1119
+ end
1120
+ end
1121
+
1071
1122
  def test_bib
1072
1123
  def @chapter.bibpaper(_id)
1073
1124
  Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
@@ -1692,6 +1743,23 @@ EOS
1692
1743
  assert_equal 'test <code class="inline-code tt">@&lt;code&gt;{$サンプル$}</code>', actual
1693
1744
  end
1694
1745
 
1746
+ def test_inline_w
1747
+ Dir.mktmpdir do |dir|
1748
+ File.open(File.join(dir, 'words.csv'), 'w') do |f|
1749
+ f.write <<EOB
1750
+ "F","foo"
1751
+ "B","bar""\\<>_@<b>{BAZ}"
1752
+ EOB
1753
+ end
1754
+ @book.config['words_file'] = File.join(dir, 'words.csv')
1755
+ io = StringIO.new
1756
+ @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
1757
+ actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
1758
+ assert_equal %Q(<p>foo bar&quot;\\&lt;&gt;_@&lt;b&gt;{BAZ} <b>bar&quot;\\&lt;&gt;_@&lt;b&gt;{BAZ}</b> [missing word: N]</p>\n), actual
1759
+ assert_match(/WARN -- : :1: word not bound: N/, io.string)
1760
+ end
1761
+ end
1762
+
1695
1763
  def test_inline_unknown
1696
1764
  e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
1697
1765
  assert_equal ':1: error: unknown image: n', e.message
@@ -5,9 +5,16 @@ class HTMLUtilsTest < Test::Unit::TestCase
5
5
  include ReVIEW::HTMLUtils
6
6
 
7
7
  def test_escape_html
8
- assert_equal '&lt;', escape_html('<')
9
- assert_equal '&lt;&lt;', escape_html('<<')
10
- assert_equal '_&lt;_&lt;_', escape_html('_<_<_')
8
+ assert_equal '&lt;', escape('<')
9
+ assert_equal '&lt;&lt;', escape('<<')
10
+ assert_equal '_&lt;_&lt;_', escape('_<_<_')
11
+ end
12
+
13
+ def test_unescape_html
14
+ assert_equal '<', unescape('&lt;')
15
+ assert_equal '>', unescape('&gt;')
16
+ assert_equal '&', unescape('&amp;')
17
+ assert_equal '&amp;', unescape('&amp;amp;')
11
18
  end
12
19
 
13
20
  def test_escape_html_ex
@@ -15,9 +22,9 @@ class HTMLUtilsTest < Test::Unit::TestCase
15
22
  ESC['.'] = 'X'
16
23
  ESC.each_pair do |ch, ref|
17
24
  if keys.include?(ch)
18
- assert_equal ref, escape_html(ch)
25
+ assert_equal ref, escape(ch)
19
26
  else
20
- assert_equal ch, escape_html(ch)
27
+ assert_equal ch, escape(ch)
21
28
  end
22
29
  end
23
30
  end
@@ -12,7 +12,7 @@ class IDGXMLBuidlerTest < Test::Unit::TestCase
12
12
  @config = ReVIEW::Configure.values
13
13
  @config['secnolevel'] = 2
14
14
  @config['tableopt'] = '10'
15
- @book = Book::Base.new(nil)
15
+ @book = Book::Base.new
16
16
  @book.config = @config
17
17
  @compiler = ReVIEW::Compiler.new(@builder)
18
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)