review 2.0.0.beta1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -1
  3. data/.rubocop_todo.yml +617 -0
  4. data/.travis.yml +16 -1
  5. data/ChangeLog +48 -0
  6. data/Dockerfile +22 -0
  7. data/Gemfile +0 -1
  8. data/README.md +97 -0
  9. data/Rakefile +10 -11
  10. data/appveyor.yml +9 -0
  11. data/bin/review +46 -0
  12. data/bin/review-check +8 -21
  13. data/bin/review-compile +26 -43
  14. data/bin/review-index +9 -22
  15. data/bin/review-init +21 -25
  16. data/bin/review-preproc +9 -13
  17. data/bin/review-validate +1 -1
  18. data/bin/review-vol +3 -17
  19. data/bin/review-webmaker +15 -0
  20. data/doc/NEWS.ja.md +534 -0
  21. data/doc/NEWS.md +538 -0
  22. data/doc/catalog.ja.md +10 -18
  23. data/doc/catalog.md +5 -9
  24. data/doc/config.yml.sample +319 -0
  25. data/doc/customize_epub.ja.md +42 -0
  26. data/doc/format.ja.md +320 -288
  27. data/doc/format.md +277 -170
  28. data/doc/format_idg.ja.md +82 -175
  29. data/doc/pdfmaker.ja.md +61 -0
  30. data/doc/pdfmaker.md +65 -0
  31. data/doc/quickstart.ja.md +88 -98
  32. data/doc/quickstart.md +72 -110
  33. data/doc/sample.css +41 -0
  34. data/doc/writing_vertical.ja.md +55 -0
  35. data/doc/writing_vertical.md +5 -0
  36. data/lib/epubmaker/content.rb +3 -3
  37. data/lib/epubmaker/epubcommon.rb +173 -145
  38. data/lib/epubmaker/epubv2.rb +24 -77
  39. data/lib/epubmaker/epubv3.rb +72 -73
  40. data/lib/epubmaker/producer.rb +54 -30
  41. data/lib/lineinput.rb +48 -0
  42. data/lib/review/book.rb +0 -1
  43. data/lib/review/book/base.rb +47 -27
  44. data/lib/review/book/chapter.rb +48 -19
  45. data/lib/review/book/compilable.rb +10 -14
  46. data/lib/review/book/index.rb +10 -19
  47. data/lib/review/book/page_metric.rb +0 -10
  48. data/lib/review/book/part.rb +17 -3
  49. data/lib/review/builder.rb +84 -68
  50. data/lib/review/catalog.rb +5 -1
  51. data/lib/review/compiler.rb +327 -4657
  52. data/lib/review/configure.rb +84 -10
  53. data/lib/review/converter.rb +28 -0
  54. data/lib/review/epubbuilder.rb +1 -1
  55. data/lib/review/epubmaker.rb +142 -158
  56. data/lib/review/ewbbuilder.rb +5 -5
  57. data/lib/review/exception.rb +1 -1
  58. data/lib/review/extentions.rb +1 -1
  59. data/lib/review/extentions/hash.rb +15 -0
  60. data/lib/review/extentions/string.rb +2 -1
  61. data/lib/review/htmlbuilder.rb +364 -348
  62. data/lib/review/htmltoc.rb +44 -0
  63. data/lib/review/htmlutils.rb +12 -6
  64. data/lib/review/i18n.rb +78 -6
  65. data/lib/review/i18n.yml +7 -4
  66. data/lib/review/idgxmlbuilder.rb +226 -267
  67. data/lib/review/latexbuilder.rb +281 -274
  68. data/lib/review/latexutils.rb +56 -49
  69. data/lib/review/makerhelper.rb +8 -4
  70. data/lib/review/markdownbuilder.rb +80 -124
  71. data/lib/review/pdfmaker.rb +197 -138
  72. data/lib/review/preprocessor.rb +16 -67
  73. data/lib/review/template.rb +24 -0
  74. data/lib/review/textbuilder.rb +1 -1
  75. data/lib/review/textutils.rb +18 -24
  76. data/lib/review/tocparser.rb +51 -106
  77. data/lib/review/tocprinter.rb +61 -117
  78. data/lib/review/topbuilder.rb +119 -126
  79. data/lib/review/unfold.rb +2 -2
  80. data/lib/review/version.rb +1 -1
  81. data/lib/review/webmaker.rb +302 -0
  82. data/lib/review/webtocprinter.rb +48 -0
  83. data/lib/review/yamlloader.rb +47 -0
  84. data/review.gemspec +3 -3
  85. data/templates/html/layout-html5.html.erb +17 -0
  86. data/templates/html/layout-xhtml1.html.erb +20 -0
  87. data/{lib/review → templates/latex}/layout.tex.erb +107 -115
  88. data/templates/ncx/epubv2.ncx.erb +11 -0
  89. data/templates/opf/epubv2.opf.erb +21 -0
  90. data/templates/opf/epubv3.opf.erb +18 -0
  91. data/templates/web/html/layout-html5.html.erb +56 -0
  92. data/templates/web/html/layout-xhtml1.html.erb +20 -0
  93. data/templates/xml/container.xml.erb +6 -0
  94. data/test/assets/test.xml.erb +3 -0
  95. data/test/assets/test_template.tex +28 -71
  96. data/test/assets/test_template_backmatter.tex +1 -9
  97. data/test/sample-book/src/Rakefile +12 -3
  98. data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
  99. data/test/sample-book/src/config.yml +40 -154
  100. data/test/sample-book/src/style-web.css +45 -0
  101. data/test/sample-book/src/style.css +23 -1
  102. data/test/test.re +1 -1
  103. data/test/test_book.rb +15 -17
  104. data/test/test_book_chapter.rb +2 -80
  105. data/test/test_book_part.rb +1 -1
  106. data/test/test_builder.rb +28 -6
  107. data/test/test_catalog.rb +17 -0
  108. data/test/test_compiler.rb +14 -59
  109. data/test/test_configure.rb +94 -0
  110. data/test/test_converter.rb +21 -0
  111. data/test/test_epub3maker.rb +155 -3
  112. data/test/test_epubmaker.rb +245 -30
  113. data/test/test_epubmaker_cmd.rb +2 -2
  114. data/test/test_extentions_hash.rb +60 -0
  115. data/test/test_helper.rb +4 -47
  116. data/test/test_htmlbuilder.rb +282 -175
  117. data/test/test_htmltoc.rb +33 -0
  118. data/test/test_i18n.rb +134 -70
  119. data/test/test_idgxmlbuilder.rb +58 -39
  120. data/test/test_latexbuilder.rb +132 -14
  121. data/test/test_lineinput.rb +5 -26
  122. data/test/test_makerhelper.rb +6 -4
  123. data/test/test_markdownbuilder.rb +23 -5
  124. data/test/test_pdfmaker.rb +86 -20
  125. data/test/test_pdfmaker_cmd.rb +1 -3
  126. data/test/test_review_ext.rb +1 -1
  127. data/test/test_template.rb +27 -0
  128. data/test/test_textutils.rb +36 -0
  129. data/test/test_tocparser.rb +25 -0
  130. data/test/test_topbuilder.rb +34 -2
  131. data/test/test_yamlloader.rb +188 -0
  132. metadata +71 -29
  133. data/README.rdoc +0 -81
  134. data/bin/review-epubmaker-legacy +0 -1024
  135. data/doc/ruby-uuid/README +0 -11
  136. data/doc/ruby-uuid/README.ja +0 -34
  137. data/lib/review/compiler/literals_1_8.kpeg +0 -19
  138. data/lib/review/compiler/literals_1_8.rb +0 -432
  139. data/lib/review/compiler/literals_1_9.kpeg +0 -22
  140. data/lib/review/compiler/literals_1_9.rb +0 -435
  141. data/lib/review/extentions/array.rb +0 -25
  142. data/lib/review/htmllayout.rb +0 -41
  143. data/lib/review/inaobuilder.rb +0 -357
  144. data/lib/review/location.rb +0 -24
  145. data/lib/review/node.rb +0 -267
  146. data/lib/review/review.kpeg +0 -724
  147. data/lib/uuid.rb +0 -312
  148. data/rubocop-todo.yml +0 -456
  149. data/test/test_inaobuilder.rb +0 -247
  150. data/test/test_uuid.rb +0 -157
@@ -0,0 +1,24 @@
1
+ require 'erb'
2
+ require 'review/extentions'
3
+ module ReVIEW
4
+ class Template
5
+ include ERB::Util
6
+
7
+ TEMPLATE_DIR = File.join(File.dirname(__FILE__), "../../templates")
8
+
9
+ def self.load(filename, mode = 1)
10
+ self.new(filename, mode)
11
+ end
12
+
13
+ def initialize(filename = nil, mode = nil)
14
+ if filename
15
+ content = File.read(filename)
16
+ @erb = ERB.new(content, nil, mode)
17
+ end
18
+ end
19
+
20
+ def result(bind_data = nil)
21
+ @erb.result(bind_data)
22
+ end
23
+ end
24
+ end
@@ -14,4 +14,4 @@ module ReVIEW
14
14
  class TEXTBuilder < TOPBuilder
15
15
  end
16
16
 
17
- end # module ReVIEW
17
+ end # module ReVIEW
@@ -13,32 +13,26 @@ module ReVIEW
13
13
  }
14
14
  end
15
15
 
16
- def convert_inencoding(str, enc)
17
- case enc
18
- when /^EUC$/i
19
- NKF.nkf("-E -w -m0x", str)
20
- when /^SJIS$/i
21
- NKF.nkf("-S -w -m0x", str)
22
- when /^JIS$/i
23
- NKF.nkf("-J -w -m0x", str)
24
- when /^UTF-8$/i
25
- NKF.nkf("-W -w -m0x", str)
26
- else
27
- NKF.nkf("-w -m0 -m0x", str)
28
- end
29
- end
16
+ def split_paragraph(lines)
17
+ pre = pre_paragraph
18
+ post = post_paragraph
30
19
 
31
- def convert_outencoding(str, enc)
32
- case enc
33
- when /^EUC$/i
34
- NKF.nkf("-W -e -m0x", str)
35
- when /^SJIS$/i
36
- NKF.nkf("-W -s -m0x", str)
37
- when /^JIS$/i
38
- NKF.nkf("-W -j -m0x", str)
39
- else
40
- str
20
+ blocked_lines = [[]]
21
+ lines.each {|element|
22
+ if element == ""
23
+ if blocked_lines.last != []
24
+ blocked_lines << []
25
+ end
26
+ else
27
+ blocked_lines.last << element
28
+ end
29
+ }
30
+
31
+ if !pre.nil? and !post.nil?
32
+ blocked_lines.map!{|i| [pre] + i + [post] }
41
33
  end
34
+
35
+ blocked_lines.map{|l| l.join("")}
42
36
  end
43
37
  end
44
38
  end
@@ -1,8 +1,6 @@
1
1
  #
2
- # $Id: tocparser.rb 4268 2009-05-27 04:17:08Z kmuto $
3
- #
4
2
  # Copyright (c) 2002-2007 Minero Aoki
5
- # 2008-2009 Minero Aoki, Kenshi Muto
3
+ # 2008-2016 Minero Aoki, Kenshi Muto
6
4
  #
7
5
  # This program is free software.
8
6
  # You can distribute or modify this program under the terms of
@@ -18,21 +16,27 @@ module ReVIEW
18
16
 
19
17
  class TOCParser
20
18
  def TOCParser.parse(chap)
21
- chap.open {|f|
22
- stream = Preprocessor::Strip.new(f)
23
- new.parse(stream, chap.id, chap.path, chap).map {|root|
24
- root.number = chap.number
25
- root
26
- }
27
- }
19
+ f = StringIO.new(chap.content, 'r:BOM|utf-8')
20
+ stream = Preprocessor::Strip.new(f)
21
+ new.parse(stream, chap).map do |root|
22
+ root.number = chap.number
23
+ root
24
+ end
28
25
  end
29
26
 
30
- def parse(f, id, filename, chap)
31
- roots = []
32
- path = []
27
+ def TOCParser.chapter_node(chap)
28
+ toc = TOCParser.parse(chap)
29
+ unless toc.size == 1
30
+ $stderr.puts "warning: chapter #{toc.join} contains more than 1 chapter"
31
+ end
32
+ toc.first
33
+ end
33
34
 
35
+ def parse(f, chap)
36
+ roots = [] ## list of chapters
37
+ node_stack = []
38
+ filename = chap.path
34
39
  while line = f.gets
35
- line.sub!(/\A\xEF\xBB\xBF/u, '') # remove BOM
36
40
  case line
37
41
  when /\A\#@/
38
42
  ;
@@ -41,29 +45,33 @@ module ReVIEW
41
45
  when /\A(={2,})[\[\s\{]/
42
46
  lev = $1.size
43
47
  error! filename, f.lineno, "section level too deep: #{lev}" if lev > 5
44
- if path.empty?
48
+ label = get_label(line)
49
+ if node_stack.empty?
45
50
  # missing chapter label
46
- path.push Chapter.new(get_label(line), id, filename, chap.book.page_metric)
47
- roots.push path.first
51
+ dummy_chapter = Chapter.new(label, chap)
52
+ node_stack.push dummy_chapter
53
+ roots.push dummy_chapter
48
54
  end
49
- next if get_label(line) =~ /\A\[\// # ex) "[/column]"
50
- new = Section.new(lev, get_label(line).gsub(/\A\{.*?\}\s?/, ""))
51
- until path.last.level < new.level
52
- path.pop
55
+ next if label =~ /\A\[\// # ex) "[/column]"
56
+ sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, ""))
57
+ until node_stack.last.level < sec.level
58
+ node_stack.pop
53
59
  end
54
- path.last.add_child new
55
- path.push new
60
+ node_stack.last.add_child sec
61
+ node_stack.push sec
56
62
 
57
- when /\A= /
58
- path.clear
59
- path.push Chapter.new(get_label(line), id, filename, chap.book.page_metric)
60
- roots.push path.first
63
+ when /\A=[^=]/
64
+ label = get_label(line)
65
+ node_stack.clear
66
+ new_chapter = Chapter.new(label, chap)
67
+ node_stack.push new_chapter
68
+ roots.push new_chapter
61
69
 
62
70
  when %r<\A//\w+(?:\[.*?\])*\{\s*\z>
63
- if path.empty?
71
+ if node_stack.empty?
64
72
  error! filename, f.lineno, 'list found before section label'
65
73
  end
66
- path.last.add_child(list = List.new)
74
+ node_stack.last.add_child(list = List.new)
67
75
  beg = f.lineno
68
76
  list.add line
69
77
  while line = f.gets
@@ -75,11 +83,11 @@ module ReVIEW
75
83
  when %r<\A//\w>
76
84
  ;
77
85
  else
78
- #if path.empty?
86
+ #if node_stack.empty?
79
87
  # error! filename, f.lineno, 'text found before section label'
80
88
  #end
81
- next if path.empty?
82
- path.last.add_child(par = Paragraph.new(chap.book.page_metric))
89
+ next if node_stack.empty?
90
+ node_stack.last.add_child(par = Paragraph.new(chap))
83
91
  par.add line
84
92
  while line = f.gets
85
93
  break if /\A\s*\z/ =~ line
@@ -151,7 +159,7 @@ module ReVIEW
151
159
  end
152
160
  end
153
161
 
154
- def n_sections
162
+ def section_size
155
163
  cnt = 0
156
164
  @children.each do |n|
157
165
  n.yield_section { cnt += 1 }
@@ -183,14 +191,6 @@ module ReVIEW
183
191
  attr_reader :level
184
192
  attr_reader :label
185
193
 
186
- def display_label
187
- if @filename
188
- @label + ' ' + @filename
189
- else
190
- @label
191
- end
192
- end
193
-
194
194
  def estimated_lines
195
195
  @children.inject(0) {|sum, n| sum + n.estimated_lines }
196
196
  end
@@ -208,11 +208,12 @@ module ReVIEW
208
208
 
209
209
  class Chapter < Section
210
210
 
211
- def initialize(label, id, path, page_metric)
212
- super 1, label, path
213
- @chapter_id = id
214
- @path = path
215
- @page_metric = page_metric
211
+ def initialize(label, chap)
212
+ super 1, label, chap.path
213
+ @chapter = chap
214
+ @chapter_id = chap.id
215
+ @path = chap.path
216
+ @page_metric = chap.book.page_metric
216
217
  @volume = nil
217
218
  @number = nil
218
219
  end
@@ -227,9 +228,7 @@ module ReVIEW
227
228
 
228
229
  def volume
229
230
  return @volume if @volume
230
- return Book::Volume.dummy unless @path
231
- @volume = Book::Volume.count_file(@path)
232
- @volume.page_per_kbyte = @page_metric.page_per_kbyte
231
+ @volume = @chapter.volume
233
232
  @volume.lines = estimated_lines()
234
233
  @volume
235
234
  end
@@ -243,9 +242,9 @@ module ReVIEW
243
242
 
244
243
  class Paragraph < Node
245
244
 
246
- def initialize(page_metric)
245
+ def initialize(chap)
247
246
  @bytes = 0
248
- @page_metric = page_metric
247
+ @page_metric = chap.book.page_metric
249
248
  end
250
249
 
251
250
  def inspect
@@ -290,59 +289,5 @@ module ReVIEW
290
289
  end
291
290
 
292
291
  end
293
-
294
-
295
- module TOCRoot
296
- def level
297
- 0
298
- end
299
-
300
- def chapter?
301
- false
302
- end
303
-
304
- def each_section_with_index
305
- idx = -1
306
- each_section do |node|
307
- yield node, (idx += 1)
308
- end
309
- end
310
-
311
- def each_section(&block)
312
- each_chapter do |chap|
313
- yield chap.toc
314
- end
315
- end
316
-
317
- def n_sections
318
- chapters.size
319
- end
320
-
321
- def estimated_lines
322
- chapters.inject(0) {|sum, chap| sum + chap.toc.estimated_lines }
323
- end
324
- end
325
-
326
- class Book::Base # reopen
327
- include TOCRoot
328
- end
329
-
330
- class Book::ChapterSet # reopen
331
- include TOCRoot
332
- end
333
-
334
- class Book::Part
335
- include TOCRoot
336
- end
337
-
338
- class Book::Chapter # reopen
339
- def toc
340
- @toc ||= TOCParser.parse(self)
341
- unless @toc.size == 1
342
- $stderr.puts "warning: chapter #{@toc.join} contains more than 1 chapter"
343
- end
344
- @toc.first
345
- end
346
- end
347
-
348
292
  end
293
+
@@ -12,54 +12,47 @@
12
12
  #
13
13
 
14
14
  require 'review/htmlutils'
15
- require 'review/htmllayout'
16
- require 'nkf'
15
+ require 'review/tocparser'
17
16
 
18
17
  module ReVIEW
19
18
 
20
19
  class TOCPrinter
21
20
 
22
21
  def TOCPrinter.default_upper_level
23
- 99 # no one use 99 level nest
22
+ 99 # no one use 99 level nest
24
23
  end
25
24
 
26
- def initialize(print_upper, param)
25
+ def initialize(print_upper, param, out = $stdout)
27
26
  @print_upper = print_upper
28
27
  @config = param
28
+ @out = out
29
29
  end
30
30
 
31
- def print?(level)
32
- level <= @print_upper
31
+ def print_book(book)
32
+ book.each_part do |part|
33
+ print_part(part)
34
+ end
33
35
  end
34
36
 
35
- def nkffilter(line)
36
- inc = ""
37
- outc = "-w"
38
- if @config["inencoding"] =~ /^EUC$/
39
- inc = "-E"
40
- elsif @config["inencoding"] =~ /^SJIS$/
41
- inc = "-S"
42
- elsif @config["inencoding"] =~ /^JIS$/
43
- inc = "-J"
37
+ def print_part(part)
38
+ part.each_chapter do |chap|
39
+ print_chapter(chap)
44
40
  end
41
+ end
45
42
 
46
- if @config["outencoding"] =~ /^EUC$/
47
- outc = "-e"
48
- elsif @config["outencoding"] =~ /^SJIS$/
49
- outc = "-s"
50
- elsif @config["outencoding"] =~ /^JIS$/
51
- outc = "-j"
52
- end
43
+ def print_chapter(chap)
44
+ chap_node = TOCParser.chapter_node(chap)
45
+ print_node 1, chap_node
46
+ print_children chap_node
47
+ end
53
48
 
54
- NKF.nkf("#{inc} #{outc}", line)
49
+ def print?(level)
50
+ level <= @print_upper
55
51
  end
56
52
  end
57
53
 
58
54
 
59
55
  class TextTOCPrinter < TOCPrinter
60
- def print_book(book)
61
- print_children book
62
- end
63
56
 
64
57
  private
65
58
 
@@ -76,14 +69,14 @@ module ReVIEW
76
69
  def print_node(number, node)
77
70
  if node.chapter?
78
71
  vol = node.volume
79
- printf "%3s %3dKB %6dC %5dL %s (%s)\n",
72
+ @out.printf "%3s %3dKB %6dC %5dL %s (%s)\n",
80
73
  chapnumstr(node.number),
81
74
  vol.kbytes, vol.chars, vol.lines,
82
- nkffilter(node.label), node.chapter_id
83
- else
84
- printf "%17s %5dL %s\n",
75
+ node.label, node.chapter_id
76
+ else ## for section node
77
+ @out.printf "%17s %5dL %s\n",
85
78
  '', node.estimated_lines,
86
- nkffilter(" #{' ' * (node.level - 1)}#{number} #{node.label}")
79
+ " #{' ' * (node.level - 1)}#{number} #{node.label}"
87
80
  end
88
81
  end
89
82
 
@@ -94,7 +87,7 @@ module ReVIEW
94
87
  def volume_columns(level, volstr)
95
88
  cols = ["", "", "", nil]
96
89
  cols[level - 1] = volstr
97
- cols[0, 3] # does not display volume of level-4 section
90
+ cols[0, 3] # does not display volume of level-4 section
98
91
  end
99
92
 
100
93
  end
@@ -105,38 +98,42 @@ module ReVIEW
105
98
  include HTMLUtils
106
99
 
107
100
  def print_book(book)
108
- return unless print?(1)
109
- html = ""
101
+ @out.puts '<ul class="book-toc">'
110
102
  book.each_part do |part|
111
- html << h1(part.name) if part.name
112
- part.each_section do |chap|
113
- if chap.number
114
- name = "chap#{chap.number}"
115
- label = "第#{chap.number}章 #{chap.label}"
116
- html << h2(a_name(escape_html(name), escape_html(label)))
117
- else
118
- label = "#{chap.label}"
119
- html << h2(escape_html(label))
120
- end
121
- return unless print?(2)
122
- if print?(3)
123
- html << chap_sections_to_s(chap)
124
- else
125
- html << chapter_to_s(chap)
126
- end
127
- end
103
+ print_part(part)
104
+ end
105
+ @out.puts '</ul>'
106
+ end
107
+
108
+ def print_part(part)
109
+ if part.number
110
+ @out.puts li(part.title)
111
+ end
112
+ super
113
+ end
114
+
115
+ def print_chapter(chap)
116
+ chap_node = TOCParser.chapter_node(chap)
117
+ ext = chap.book.config["htmlext"] || "html"
118
+ path = chap.path.sub(/\.re/, "."+ext)
119
+ if chap_node.number && chap.on_CHAPS?
120
+ label = "#{chap.number} #{chap.title}"
121
+ else
122
+ label = chap.title
128
123
  end
129
- layout_file = File.join(book.basedir, "layouts", "layout.html.erb")
130
- unless File.exist?(layout_file) # backward compatibility
131
- layout_file = File.join(book.basedir, "layouts", "layout.erb")
124
+ @out.puts li(a_name(path, escape_html(label)))
125
+ return unless print?(2)
126
+ if print?(3)
127
+ @out.puts chap_sections_to_s(chap_node)
128
+ else
129
+ @out.puts chapter_to_s(chap_node)
132
130
  end
133
- puts HTMLLayout.new(
134
- {'body' => html, 'title' => "目次"}, layout_file).result
135
131
  end
136
132
 
137
133
  private
138
134
 
139
135
  def chap_sections_to_s(chap)
136
+ return "" if chap.section_size < 1
140
137
  res = []
141
138
  res << "<ol>"
142
139
  chap.each_section do |sec|
@@ -146,33 +143,22 @@ module ReVIEW
146
143
  return res.join("\n")
147
144
  end
148
145
 
149
- def print_chapter_to_s(chap)
146
+ def chapter_to_s(chap)
150
147
  res = []
151
148
  chap.each_section do |sec|
152
- res << h3(escape_html(sec.label))
149
+ res << li(escape_html(sec.label))
153
150
  next unless print?(4)
154
- next if sec.n_sections == 0
155
- res << "<ul>"
156
- sec.each_section do |node|
157
- res << li(escape_html(node.label))
151
+ if sec.section_size > 0
152
+ res << "<ul>"
153
+ sec.each_section do |node|
154
+ res << li(escape_html(node.label))
155
+ end
156
+ res << "</ul>"
158
157
  end
159
- res << "</ul>"
160
158
  end
161
159
  return res.join("\n")
162
160
  end
163
161
 
164
- def h1(label)
165
- "<h1>#{label}</h1>"
166
- end
167
-
168
- def h2(label)
169
- "<h2>#{label}</h2>"
170
- end
171
-
172
- def h3(label)
173
- "<h3>#{label}</h3>"
174
- end
175
-
176
162
  def li(content)
177
163
  "<li>#{content}</li>"
178
164
  end
@@ -183,46 +169,4 @@ module ReVIEW
183
169
 
184
170
  end
185
171
 
186
- class IDGTOCPrinter < TOCPrinter
187
- def print_book(book)
188
- puts %Q(<?xml version="1.0" encoding="UTF-8"?>)
189
- puts nkffilter(%Q(<doc xmlns:aid='http://ns.adobe.com/AdobeInDesign/4.0/'><title aid:pstyle="h0">1 パート1</title><?dtp level="0" section="第1部 パート1"?>)) # FIXME: 部タイトルを取るには? & 部ごとに結果を分けるには?
190
- puts %Q(<ul aid:pstyle='ul-partblock'>)
191
- print_children book
192
- puts %Q(</ul></doc>)
193
- end
194
-
195
- private
196
-
197
- def print_children(node)
198
- return unless print?(node.level + 1)
199
- node.each_section_with_index do |sec, idx|
200
- print_node idx+1, sec
201
- print_children sec
202
- end
203
- end
204
-
205
- LABEL_LEN = 54
206
-
207
- def print_node(seq, node)
208
- if node.chapter?
209
- vol = node.volume
210
- printf "<li aid:pstyle='ul-part'>%s</li>\n",
211
- nkffilter("#{chapnumstr(node.number)}#{node.label}")
212
- else
213
- printf "<li>%-#{LABEL_LEN}s\n",
214
- nkffilter(" #{' ' * (node.level - 1)}#{seq} #{node.label}</li>")
215
- end
216
- end
217
-
218
- def chapnumstr(n)
219
- n ? nkffilter(sprintf('第%d章 ', n)) : ''
220
- end
221
-
222
- def volume_columns(level, volstr)
223
- cols = ["", "", "", nil]
224
- cols[level - 1] = volstr
225
- cols[0, 3]
226
- end
227
- end
228
172
  end