review 1.0.0 → 1.1.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 (100) hide show
  1. data/.travis.yml +1 -2
  2. data/ChangeLog +65 -0
  3. data/Gemfile +5 -0
  4. data/README.rdoc +6 -1
  5. data/Rakefile +14 -28
  6. data/bin/review-check +9 -21
  7. data/bin/review-compile +45 -12
  8. data/bin/review-epubmaker +477 -220
  9. data/bin/review-epubmaker-ng +5 -14
  10. data/bin/review-index +4 -2
  11. data/bin/review-init +94 -0
  12. data/bin/review-pdfmaker +70 -287
  13. data/bin/review-preproc +5 -2
  14. data/bin/review-vol +4 -11
  15. data/debian/changelog +3 -3
  16. data/debian/copyright +5 -3
  17. data/debian/docs +1 -0
  18. data/doc/format.rdoc +57 -11
  19. data/doc/quickstart.rdoc +4 -4
  20. data/doc/sample.yaml +11 -7
  21. data/lib/epubmaker.rb +1 -1
  22. data/lib/epubmaker/epubv2.rb +26 -27
  23. data/lib/epubmaker/epubv3.rb +13 -13
  24. data/lib/epubmaker/producer.rb +1 -1
  25. data/lib/review.rb +3 -4
  26. data/lib/review/book.rb +17 -581
  27. data/lib/review/book/base.rb +247 -0
  28. data/lib/review/book/chapter.rb +81 -0
  29. data/lib/review/book/compilable.rb +163 -0
  30. data/lib/review/book/index.rb +339 -0
  31. data/lib/review/book/page_metric.rb +38 -0
  32. data/lib/review/book/parameters.rb +97 -0
  33. data/lib/review/book/part.rb +44 -0
  34. data/lib/review/book/volume.rb +65 -0
  35. data/lib/review/builder.rb +34 -40
  36. data/lib/review/compiler.rb +32 -13
  37. data/lib/review/configure.rb +38 -0
  38. data/lib/review/ewbbuilder.rb +23 -21
  39. data/lib/review/extentions.rb +3 -0
  40. data/lib/review/extentions/object.rb +9 -0
  41. data/lib/review/{compat.rb → extentions/string.rb} +11 -0
  42. data/lib/review/htmlbuilder.rb +162 -74
  43. data/lib/review/htmlutils.rb +28 -1
  44. data/lib/review/i18n.yaml +11 -0
  45. data/lib/review/idgxmlbuilder.rb +119 -35
  46. data/lib/review/inaobuilder.rb +355 -0
  47. data/lib/review/latexbuilder.rb +133 -59
  48. data/lib/review/latexutils.rb +15 -6
  49. data/lib/review/makerhelper.rb +59 -0
  50. data/lib/review/markdownbuilder.rb +129 -0
  51. data/lib/review/preprocessor.rb +20 -7
  52. data/lib/review/review.tex.erb +250 -0
  53. data/lib/review/textutils.rb +28 -3
  54. data/lib/review/tocparser.rb +20 -12
  55. data/lib/review/tocprinter.rb +7 -3
  56. data/lib/review/topbuilder.rb +44 -27
  57. data/lib/review/version.rb +3 -0
  58. data/review.gemspec +20 -117
  59. data/test/book_test_helper.rb +35 -0
  60. data/test/sample-book/README.md +5 -0
  61. data/test/sample-book/src/CHAPS +2 -0
  62. data/test/sample-book/src/PREDEF +1 -0
  63. data/test/sample-book/src/Rakefile +26 -0
  64. data/test/sample-book/src/_cover.html +3 -0
  65. data/test/sample-book/src/ch01.re +71 -0
  66. data/test/sample-book/src/ch02.re +3 -0
  67. data/test/sample-book/src/config.yml +55 -0
  68. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  69. data/test/sample-book/src/images/cover.jpg +0 -0
  70. data/test/sample-book/src/main.css +251 -0
  71. data/test/sample-book/src/preface.re +15 -0
  72. data/test/sample-book/src/sty/jumoline.sty +310 -0
  73. data/test/sample-book/src/sty/samplemacro.sty +21 -0
  74. data/test/sample-book/src/vendor/jumoline/README +29 -0
  75. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  76. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  77. data/test/test_book.rb +26 -646
  78. data/test/test_book_chapter.rb +418 -0
  79. data/test/test_book_parameter.rb +42 -0
  80. data/test/test_book_part.rb +53 -0
  81. data/test/test_builder.rb +17 -10
  82. data/test/test_compiler.rb +46 -0
  83. data/test/test_epubmaker.rb +1 -1
  84. data/test/test_epubmaker_cmd.rb +36 -0
  85. data/test/test_helper.rb +17 -0
  86. data/test/test_htmlbuilder.rb +156 -24
  87. data/test/test_htmlutils.rb +4 -0
  88. data/test/test_i18n.rb +6 -2
  89. data/test/test_idgxmlbuilder.rb +33 -11
  90. data/test/test_inaobuilder.rb +247 -0
  91. data/test/test_index.rb +31 -0
  92. data/test/test_latexbuilder.rb +115 -35
  93. data/test/test_makerhelper.rb +50 -0
  94. data/test/test_pdfmaker_cmd.rb +36 -0
  95. data/test/test_preprocessor.rb +7 -7
  96. data/test/test_topbuilder.rb +6 -7
  97. data/test/test_uuid.rb +1 -0
  98. metadata +117 -12
  99. data/lib/review/index.rb +0 -323
  100. data/lib/review/volume.rb +0 -66
@@ -0,0 +1,44 @@
1
+ #
2
+ # $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
3
+ #
4
+ # Copyright (c) 2002-2008 Minero Aoki
5
+ # 2009 Minero Aoki, Kenshi Muto
6
+ #
7
+ # This program is free software.
8
+ # You can distribute or modify this program under the terms of
9
+ # the GNU LGPL, Lesser General Public License version 2.1.
10
+ # For details of the GNU LGPL, see the file "COPYING".
11
+ #
12
+ require 'review/book/compilable'
13
+ module ReVIEW
14
+ module Book
15
+ class Part
16
+ include Compilable
17
+
18
+ def initialize(book, number, chapters, name="")
19
+ @book = book
20
+ @number = number
21
+ @chapters = chapters
22
+ @path = name
23
+ @name = name ? File.basename(name, '.*') : nil
24
+ end
25
+
26
+ attr_reader :number
27
+ attr_reader :chapters
28
+ attr_reader :name
29
+
30
+ def each_chapter(&block)
31
+ @chapters.each(&block)
32
+ end
33
+
34
+ def volume
35
+ Volume.sum(@chapters.map {|chap| chap.volume })
36
+ end
37
+
38
+ def file?
39
+ (name.present? and path =~ /\.re\z/) ? true : false
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # $Id: volume.rb 3883 2008-02-10 11:48:23Z aamine $
3
+ #
4
+ # Copyright (c) 2002-2007 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute or modify this program under the terms of
8
+ # the GNU LGPL, Lesser General Public License version 2.1.
9
+ # For details of the GNU LGPL, see the file "COPYING".
10
+ #
11
+ module ReVIEW
12
+ module Book
13
+ class Volume
14
+
15
+ def Volume.count_file(path)
16
+ b = c = l = 0
17
+ File.foreach(path) do |line|
18
+ next if %r<\A\#@> =~ line
19
+ text = line.gsub(/\s+/, '')
20
+ b += text.bytesize
21
+ c += text.charsize
22
+ l += 1
23
+ end
24
+ new(b, c, l)
25
+ end
26
+
27
+ def Volume.sum(vols)
28
+ vols.inject(new()) {|sum, i| sum + i }
29
+ end
30
+
31
+ def Volume.dummy
32
+ new(-1, -1, -1)
33
+ end
34
+
35
+ def initialize(bytes = 0, chars = 0, lines = 0)
36
+ @bytes = bytes
37
+ @chars = chars
38
+ @lines = lines
39
+ end
40
+
41
+ attr_reader :bytes
42
+ attr_reader :chars
43
+ attr_accessor :lines
44
+
45
+ def kbytes
46
+ (@bytes.to_f / 1024).ceil
47
+ end
48
+
49
+ def page
50
+ (kbytes.to_f/ReVIEW.book.page_metric.page_per_kbyte).ceil
51
+ end
52
+
53
+ def to_s
54
+ "#{kbytes()}KB #{@chars}C #{@lines}L #{page()}P"
55
+ end
56
+
57
+ def +(other)
58
+ Volume.new(@bytes + other.bytes,
59
+ @chars + other.chars,
60
+ @lines + other.lines)
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -7,15 +7,17 @@
7
7
  # the GNU LGPL, Lesser General Public License version 2.1.
8
8
  #
9
9
 
10
- require 'review/index'
10
+ require 'review/book/index'
11
11
  require 'review/exception'
12
+ require 'review/textutils'
12
13
  require 'stringio'
13
- require 'nkf'
14
14
  require 'cgi'
15
15
 
16
16
  module ReVIEW
17
17
 
18
18
  class Builder
19
+ include TextUtils
20
+
19
21
  CAPTION_TITLES = %w(note memo tip info planning best important security caution term link notice point shoot reference practice expert)
20
22
 
21
23
  def pre_paragraph
@@ -27,6 +29,10 @@ module ReVIEW
27
29
 
28
30
  def initialize(strict = false, *args)
29
31
  @strict = strict
32
+ @tabwidth = nil
33
+ if ReVIEW.book.param && ReVIEW.book.param["tabwidth"]
34
+ @tabwidth = ReVIEW.book.param["tabwidth"]
35
+ end
30
36
  builder_init(*args)
31
37
  end
32
38
 
@@ -53,28 +59,16 @@ module ReVIEW
53
59
 
54
60
  alias :raw_result result
55
61
 
56
- def convert_outencoding(*s)
57
- if ReVIEW.book.param["outencoding"] =~ /^EUC$/i
58
- NKF.nkf("-W, -e", *s)
59
- elsif ReVIEW.book.param["outencoding"] =~ /^SJIS$/i
60
- NKF.nkf("-W, -s", *s)
61
- elsif ReVIEW.book.param["outencoding"] =~ /^JIS$/i
62
- NKF.nkf("-W, -j", *s)
63
- else
64
- ## for 1.9 compatibility
65
- if s.size == 1
66
- return s[0]
67
- end
68
- return *s
69
- end
70
- end
71
-
72
62
  def print(*s)
73
- @output.print(convert_outencoding(*s))
63
+ @output.print *s.map{|i|
64
+ convert_outencoding(i, ReVIEW.book.param["outencoding"])
65
+ }
74
66
  end
75
67
 
76
68
  def puts(*s)
77
- @output.puts(convert_outencoding(*s))
69
+ @output.puts *s.map{|i|
70
+ convert_outencoding(i, ReVIEW.book.param["outencoding"])
71
+ }
78
72
  end
79
73
 
80
74
  def list(lines, id, caption)
@@ -83,7 +77,7 @@ module ReVIEW
83
77
  rescue KeyError
84
78
  error "no such list: #{id}"
85
79
  end
86
- list_body lines
80
+ list_body id, lines
87
81
  end
88
82
 
89
83
  def listnum(lines, id, caption)
@@ -230,7 +224,9 @@ module ReVIEW
230
224
  end
231
225
 
232
226
  def inline_ruby(arg)
233
- base, ruby = *arg.split(',', 2)
227
+ base, *ruby = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/)
228
+ base = base.gsub(/\\,/, ",") if base
229
+ ruby = ruby.join(",").gsub(/\\,/, ",") if ruby
234
230
  compile_ruby(base, ruby)
235
231
  end
236
232
 
@@ -276,7 +272,6 @@ module ReVIEW
276
272
  ""
277
273
  end
278
274
  else
279
- warn "It is recommended to set builder(s)."
280
275
  print str.gsub("\\n", "\n")
281
276
  end
282
277
  end
@@ -327,7 +322,7 @@ module ReVIEW
327
322
  end
328
323
 
329
324
  def parse_metric(type, metric)
330
- return "" if metric.nil? || metric.empty?
325
+ return "" if metric.blank?
331
326
  params = metric.split(/,\s*/)
332
327
  results = []
333
328
  params.each do |p|
@@ -352,7 +347,7 @@ module ReVIEW
352
347
  end
353
348
 
354
349
  def extract_chapter_id(chap_ref)
355
- m = /\A(\w+)\|(.+)/.match(chap_ref)
350
+ m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
356
351
  if m
357
352
  return [@book.chapters.detect{|chap| chap.id == m[1]}, m[2]]
358
353
  else
@@ -405,27 +400,16 @@ module ReVIEW
405
400
  end
406
401
 
407
402
  def inline_include(file_name)
408
- enc = inencoding()
409
- compile_inline NKF.nkf("--#{enc}", File.open(file_name).read)
403
+ compile_inline convert_inencoding(File.open(file_name).read,
404
+ ReVIEW.book.param["inencoding"])
410
405
  end
411
406
 
412
407
  def include(file_name)
413
- enc = inencoding()
414
408
  File.foreach(file_name) do |line|
415
- paragraph([NKF.nkf("--#{enc}", line)])
409
+ paragraph([convert_inencoding(line, ReVIEW.book.param["inencoding"])])
416
410
  end
417
411
  end
418
412
 
419
- def inencoding
420
- if ReVIEW.book.param["inencoding"].nil?
421
- enc = "utf8"
422
- else
423
- # UTF-8, SJIS, EUC => utf8, sjis, euc
424
- enc = ReVIEW.book.param["inencoding"].gsub(/-/, '').downcase
425
- end
426
- end
427
- private :inencoding
428
-
429
413
  def ul_item_begin(lines)
430
414
  ul_item(lines)
431
415
  end
@@ -443,10 +427,20 @@ module ReVIEW
443
427
  ""
444
428
  end
445
429
  else
446
- warn "It is recommended to set builder(s)."
447
430
  args.gsub("\\n", "\n")
448
431
  end
449
432
  end
433
+
434
+ ## override TextUtils::detab
435
+ def detab(str, num = nil)
436
+ if num
437
+ super(str, num)
438
+ elsif @tabwidth
439
+ super(str, @tabwidth)
440
+ else
441
+ super(str)
442
+ end
443
+ end
450
444
  end
451
445
 
452
446
  end # module ReVIEW
@@ -8,7 +8,7 @@
8
8
  # the GNU LGPL, Lesser General Public License version 2.1.
9
9
  #
10
10
 
11
- require 'review/compat'
11
+ require 'review/extentions'
12
12
  require 'review/preprocessor'
13
13
  require 'review/exception'
14
14
  require 'lineinput'
@@ -136,7 +136,7 @@ module ReVIEW
136
136
  defblock :table, 0..2
137
137
  defblock :quote, 0
138
138
  defblock :image, 2..3, true
139
- defblock :source, 1
139
+ defblock :source, 0..1
140
140
  defblock :listnum, 2
141
141
  defblock :emlistnum, 0..1
142
142
  defblock :bibpaper, 2..3, true
@@ -149,11 +149,12 @@ module ReVIEW
149
149
  defblock :blockquote, 0
150
150
  defblock :bpo, 0
151
151
  defblock :flushright, 0
152
+ defblock :centering, 0
152
153
  defblock :note, 0..1
153
154
  defblock :box, 0..1
155
+ defblock :comment, 0..1, true
154
156
 
155
157
  defsingle :footnote, 2
156
- defsingle :comment, 1
157
158
  defsingle :noindent, 0
158
159
  defsingle :linebreak, 0
159
160
  defsingle :pagebreak, 0
@@ -165,6 +166,7 @@ module ReVIEW
165
166
  defsingle :raw, 1
166
167
  defsingle :tsize, 1
167
168
  defsingle :include, 1
169
+ defsingle :olnum, 1
168
170
 
169
171
  definline :chapref
170
172
  definline :chap
@@ -224,6 +226,8 @@ module ReVIEW
224
226
  tagged_section_init
225
227
  while f.next?
226
228
  case f.peek
229
+ when /\A\#@/
230
+ f.gets # Nothing to do
227
231
  when /\A=+[\[\s\{]/
228
232
  compile_headline f.gets
229
233
  when %r<\A\s+\*>
@@ -280,7 +284,6 @@ module ReVIEW
280
284
  unless prev_tag_info.first == open_tag
281
285
  raise CompileError, "#{open_tag} is not opened."
282
286
  end
283
- @strategy.warn("It is not recommended to use \"#{line.chomp}\"")
284
287
  close_tagged_section(*prev_tag_info)
285
288
  end
286
289
  else
@@ -340,7 +343,8 @@ module ReVIEW
340
343
 
341
344
  def compile_ulist(f)
342
345
  level = 0
343
- f.while_match(/\A\s+\*/) do |line|
346
+ f.while_match(/\A\s+\*|\A\#@/) do |line|
347
+ next if line =~ /\A\#@/
344
348
 
345
349
  buf = [text(line.sub(/\*+/, '').strip)]
346
350
  f.while_match(/\A\s+(?!\*)\S/) do |cont|
@@ -368,8 +372,8 @@ module ReVIEW
368
372
  (1..level_diff).to_a.reverse.each do |i|
369
373
  @strategy.ul_item_end
370
374
  @strategy.ul_end {level + i}
371
- @strategy.ul_item_end
372
375
  end
376
+ @strategy.ul_item_end
373
377
  # body
374
378
  @strategy.ul_item_begin buf
375
379
  end
@@ -383,7 +387,9 @@ module ReVIEW
383
387
 
384
388
  def compile_olist(f)
385
389
  @strategy.ol_begin
386
- f.while_match(/\A\s+\d+\./) do |line|
390
+ f.while_match(/\A\s+\d+\.|\A\#@/) do |line|
391
+ next if line =~ /\A\#@/
392
+
387
393
  num = line.match(/(\d+)\./)[1]
388
394
  buf = [text(line.sub(/\d+\./, '').strip)]
389
395
  f.while_match(/\A\s+(?!\d+\.)\S/) do |cont|
@@ -406,7 +412,7 @@ module ReVIEW
406
412
 
407
413
  def compile_paragraph(f)
408
414
  buf = []
409
- f.until_match(%r<\A//>) do |line|
415
+ f.until_match(%r<\A//|\A\#@|\A===+>) do |line|
410
416
  break if line.strip.empty?
411
417
  buf.push text(line.sub(/^(\t+)\s*/) {|m| "<!ESCAPETAB!>" * m.size}.strip.gsub(/<!ESCAPETAB!>/, "\t"))
412
418
  end
@@ -429,7 +435,9 @@ module ReVIEW
429
435
  head = f.lineno
430
436
  buf = []
431
437
  f.until_match(%r<\A//\}>) do |line|
432
- buf.push text(line.rstrip)
438
+ unless line =~ /\A\#@/
439
+ buf.push text(line.rstrip)
440
+ end
433
441
  end
434
442
  unless %r<\A//\}> =~ f.peek
435
443
  error "unexpected EOF (block begins at: #{head})"
@@ -441,11 +449,20 @@ module ReVIEW
441
449
 
442
450
  def parse_args(str, name=nil)
443
451
  return [] if str.empty?
444
- unless str[0,1] == '[' and str[-1,1] == ']'
445
- error "argument syntax error: #{str.inspect}"
452
+ scanner = StringScanner.new(str)
453
+ words = []
454
+ while word = scanner.scan(/(\[\]|\[.*?[^\\]\])/)
455
+ w2 = word[1..-2].gsub(/\\(.)/){
456
+ ch = $1
457
+ (ch == "]" or ch == "\\") ? ch : "\\" + ch
458
+ }
459
+ words << w2
460
+ end
461
+ if !scanner.eos?
462
+ error "argument syntax error: #{scanner.rest} in #{str.inspect}"
446
463
  return []
447
464
  end
448
- str[1..-2].split('][', -1)
465
+ return words
449
466
  end
450
467
 
451
468
  def compile_command(syntax, args, lines)
@@ -458,7 +475,7 @@ module ReVIEW
458
475
  syntax.check_args args
459
476
  rescue CompileError => err
460
477
  error err.message
461
- args = ['(NoArgument)'] * SYNTAX[name].min_argc
478
+ args = ['(NoArgument)'] * syntax.min_argc
462
479
  end
463
480
  if syntax.block_allowed?
464
481
  compile_block syntax, args, lines
@@ -501,6 +518,8 @@ module ReVIEW
501
518
  result << @strategy.nofunc_text(words.shift)
502
519
  end
503
520
  result
521
+ rescue => err
522
+ error err.message
504
523
  end
505
524
  public :text # called from strategy
506
525
 
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ module ReVIEW
3
+ class Configure
4
+ def self.values
5
+ { # These parameters can be overridden by YAML file.
6
+ "bookname"=> "example", # it defines epub file name also
7
+ "booktitle" => "ReVIEW EPUBサンプル",
8
+ "title" => "example",
9
+ "aut" => nil, # author
10
+ "prt" => nil, # printer(publisher)
11
+ "asn" => nil, # associated name
12
+ "ant" => nil, # bibliographic antecedent
13
+ "clb" => nil, # Collaborator
14
+ "edt" => nil, # Editor
15
+ "dsr" => nil, # Designer
16
+ "ill" => nil, # Illustrator
17
+ "pht" => nil, # Photographer
18
+ "trl" => nil, # Translator
19
+ "date" => nil, # publishing date
20
+ "rights" => nil, # Copyright messages
21
+ "description" => nil, # Description
22
+ "urnid" => nil, # Identifier (nil makes random uuid)
23
+ "stylesheet" => "stylesheet.css", # stylesheet file
24
+ "coverfile" => nil, # content file of body of cover page
25
+ "mytoc" => nil, # whether make own table of contents or not
26
+ "params" => "", # specify review2html parameters
27
+ "toclevel" => 3, # level of toc
28
+ "secnolevel" => 2, # level of section #
29
+ "posthook" => nil, # command path of post hook
30
+ "epubversion" => 2,
31
+ "titlepage" => true, # Use title page
32
+ "toc" => true, # Use table of contents
33
+ "colophon" => false, # Use colophon
34
+ "debug" => nil, # debug flag
35
+ }
36
+ end
37
+ end
38
+ end