review 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -38,6 +38,7 @@ module ReVIEW
38
38
  @latex_tsize = nil
39
39
  @tsize = nil
40
40
  @table_caption = nil
41
+ @ol_num = nil
41
42
  end
42
43
  private :builder_init_file
43
44
 
@@ -68,7 +69,9 @@ module ReVIEW
68
69
  1 => 'chapter',
69
70
  2 => 'section',
70
71
  3 => 'subsection',
71
- 4 => 'subsubsection'
72
+ 4 => 'subsubsection',
73
+ 5 => 'paragraph',
74
+ 6 => 'subparagraph'
72
75
  }
73
76
 
74
77
  def headline(level, label, caption)
@@ -78,9 +81,14 @@ module ReVIEW
78
81
  end
79
82
  blank unless @output.pos == 0
80
83
  puts macro(HEADLINE[level]+prefix, compile_inline(caption))
84
+ if prefix == "*" && level <= ReVIEW.book.param["toclevel"].to_i
85
+ puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
86
+ end
81
87
  if level == 1
82
88
  puts macro('label', chapter_label)
83
89
  end
90
+ rescue
91
+ error "unknown level: #{level}"
84
92
  end
85
93
 
86
94
  def nonum_begin(level, label, caption)
@@ -93,24 +101,12 @@ module ReVIEW
93
101
 
94
102
  def column_begin(level, label, caption)
95
103
  blank
96
- ## puts '\vspace{2zw}'
97
- ## puts '\begin{center}'
98
- ## puts '\begin{minipage}{1.0\linewidth}'
99
- ## puts '\begin{framed}'
100
- ## puts '\setlength{\FrameSep}{1zw}'
101
-
102
- ## nonum_begin(3, label, caption) # FIXME
103
-
104
104
  puts "\\begin{reviewcolumn}\n"
105
105
  puts macro('reviewcolumnhead', nil, compile_inline(caption))
106
106
 
107
107
  end
108
108
 
109
109
  def column_end(level)
110
- ## puts '\end{framed}'
111
- ## puts '\end{minipage}'
112
- ## puts '\end{center}'
113
- ## ## puts '\vspace{2zw}'
114
110
  puts "\\end{reviewcolumn}\n"
115
111
  blank
116
112
  end
@@ -133,13 +129,28 @@ module ReVIEW
133
129
  puts "\\end{reviewminicolumn}\n"
134
130
  end
135
131
 
132
+ def box(lines, caption = nil)
133
+ blank
134
+ if caption
135
+ puts macro('reviewboxcaption', "#{compile_inline(caption)}")
136
+ end
137
+ puts '\begin{reviewbox}'
138
+ lines.each do |line|
139
+ puts detab(line)
140
+ end
141
+ puts '\end{reviewbox}'
142
+ blank
143
+ end
144
+
136
145
  def ul_begin
137
146
  blank
138
147
  puts '\begin{itemize}'
139
148
  end
140
149
 
141
150
  def ul_item(lines)
142
- puts '\item ' + lines.join
151
+ str = lines.join
152
+ str.sub!(/\A(\[)/){'\lbrack{}'}
153
+ puts '\item ' + str
143
154
  end
144
155
 
145
156
  def ul_end
@@ -150,10 +161,16 @@ module ReVIEW
150
161
  def ol_begin
151
162
  blank
152
163
  puts '\begin{enumerate}'
164
+ if @ol_num
165
+ puts "\\setcounter{enumi}{#{@ol_num - 1}}"
166
+ @ol_num = nil
167
+ end
153
168
  end
154
169
 
155
170
  def ol_item(lines, num)
156
- puts '\item ' + lines.join
171
+ str = lines.join
172
+ str.sub!(/\A(\[)/){'\lbrack{}'}
173
+ puts '\item ' + str
157
174
  end
158
175
 
159
176
  def ol_end
@@ -167,6 +184,8 @@ module ReVIEW
167
184
  end
168
185
 
169
186
  def dt(str)
187
+ str.sub!(/\[/){'\lbrack{}'}
188
+ str.sub!(/\]/){'\rbrack{}'}
170
189
  puts '\item[' + str + '] \mbox{} \\\\'
171
190
  end
172
191
 
@@ -203,11 +222,9 @@ module ReVIEW
203
222
  puts macro('reviewemlistcaption', "#{compile_inline(caption)}")
204
223
  end
205
224
  puts '\begin{reviewemlist}'
206
- puts '\begin{alltt}'
207
225
  lines.each do |line|
208
- puts line
226
+ puts detab(line)
209
227
  end
210
- puts '\end{alltt}'
211
228
  puts '\end{reviewemlist}'
212
229
  blank
213
230
  end
@@ -218,26 +235,22 @@ module ReVIEW
218
235
  puts macro('reviewemlistcaption', "#{compile_inline(caption)}")
219
236
  end
220
237
  puts '\begin{reviewemlist}'
221
- puts '\begin{alltt}'
222
238
  lines.each_with_index do |line, i|
223
239
  puts detab((i+1).to_s.rjust(2) + ": " + line)
224
240
  end
225
- puts '\end{alltt}'
226
241
  puts '\end{reviewemlist}'
227
242
  blank
228
243
  end
229
244
 
230
245
  def listnum_body(lines)
231
246
  puts '\begin{reviewlist}'
232
- puts '\begin{alltt}'
233
247
  lines.each_with_index do |line, i|
234
248
  puts detab((i+1).to_s.rjust(2) + ": " + line)
235
249
  end
236
- puts '\end{alltt}'
237
250
  puts '\end{reviewlist}'
238
251
  blank
239
252
 
240
- end
253
+ end
241
254
 
242
255
  def cmd(lines, caption = nil)
243
256
  blank
@@ -245,26 +258,22 @@ module ReVIEW
245
258
  puts macro('reviewcmdcaption', "#{compile_inline(caption)}")
246
259
  end
247
260
  puts '\begin{reviewcmd}'
248
- puts '\begin{alltt}'
249
261
  lines.each do |line|
250
- puts line
262
+ puts detab(line)
251
263
  end
252
- puts '\end{alltt}'
253
264
  puts '\end{reviewcmd}'
254
265
  blank
255
266
  end
256
267
 
257
268
  def list_header(id, caption)
258
- puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])} #{compile_inline(caption)}")
269
+ puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
259
270
  end
260
271
 
261
- def list_body(lines)
272
+ def list_body(id, lines)
262
273
  puts '\begin{reviewlist}'
263
- puts '\begin{alltt}'
264
274
  lines.each do |line|
265
- puts line
275
+ puts detab(line)
266
276
  end
267
- puts '\end{alltt}'
268
277
  puts '\end{reviewlist}'
269
278
  puts ""
270
279
  end
@@ -282,11 +291,9 @@ module ReVIEW
282
291
  end
283
292
 
284
293
  def source_body(lines)
285
- puts '\begin{alltt}'
286
294
  lines.each do |line|
287
- puts line
295
+ puts detab(line)
288
296
  end
289
- puts '\end{alltt}'
290
297
  end
291
298
 
292
299
 
@@ -301,27 +308,25 @@ module ReVIEW
301
308
  metrics = parse_metric("latex", metric)
302
309
  # image is always bound here
303
310
  puts '\begin{reviewimage}'
304
- if !metrics.empty?
311
+ if metrics.present?
305
312
  puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
306
313
  else
307
314
  puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
308
315
  end
309
- puts macro('label', image_label(id))
310
- if !caption.empty?
316
+ if caption.present?
311
317
  puts macro('caption', compile_inline(caption))
312
318
  end
319
+ puts macro('label', image_label(id))
313
320
  puts '\end{reviewimage}'
314
321
  end
315
322
 
316
323
  def image_dummy(id, caption, lines)
317
324
  puts '\begin{reviewdummyimage}'
318
- puts '\begin{alltt}'
319
325
  path = @chapter.image(id).path
320
326
  puts "--[[path = #{path} (#{existence(id)})]]--"
321
327
  lines.each do |line|
322
328
  puts detab(line.rstrip)
323
329
  end
324
- puts '\end{alltt}'
325
330
  puts macro('label', image_label(id))
326
331
  puts compile_inline(caption)
327
332
  puts '\end{reviewdummyimage}'
@@ -342,29 +347,77 @@ module ReVIEW
342
347
  end
343
348
  private :chapter_label
344
349
 
350
+ def table_label(id)
351
+ "table:#{@chapter.id}:#{id}"
352
+ end
353
+ private :table_label
354
+
355
+ def bib_label(id)
356
+ "bib:#{id}"
357
+ end
358
+ private :bib_label
359
+
345
360
  def indepimage(id, caption=nil, metric=nil)
346
361
  metrics = parse_metric("latex", metric)
347
362
  puts '\begin{reviewimage}'
348
- if !metrics.empty?
363
+ if metrics.present?
349
364
  puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
350
365
  else
351
366
  puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
352
367
  end
353
- if !caption.nil? && !caption.empty?
354
- puts macro('caption', compile_inline(caption))
368
+ if caption.present?
369
+ puts macro('reviewindepimagecaption',
370
+ %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
355
371
  end
356
372
  puts '\end{reviewimage}'
357
373
  end
358
374
 
359
375
  alias :numberlessimage indepimage
360
376
 
377
+ def table(lines, id = nil, caption = nil)
378
+ rows = []
379
+ sepidx = nil
380
+ lines.each_with_index do |line, idx|
381
+ if /\A[\=\{\-\}]{12}/ =~ line
382
+ # just ignore
383
+ #error "too many table separator" if sepidx
384
+ sepidx ||= idx
385
+ next
386
+ end
387
+ rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
388
+ end
389
+ rows = adjust_n_cols(rows)
390
+
391
+ begin
392
+ table_header id, caption unless caption.nil?
393
+ rescue KeyError => err
394
+ error "no such table: #{id}"
395
+ end
396
+ return if rows.empty?
397
+ table_begin rows.first.size
398
+ if sepidx
399
+ sepidx.times do
400
+ tr rows.shift.map {|s| th(s) }
401
+ end
402
+ rows.each do |cols|
403
+ tr cols.map {|s| td(s) }
404
+ end
405
+ else
406
+ rows.each do |cols|
407
+ h, *cs = *cols
408
+ tr [th(h)] + cs.map {|s| td(s) }
409
+ end
410
+ end
411
+ table_end
412
+ end
413
+
361
414
  def table_header(id, caption)
362
- if caption && !caption.empty?
415
+ if caption.present?
363
416
  @table_caption = true
364
417
  puts '\begin{table}[h]'
365
- ## puts macro('reviewtablecaption', "表#{@chapter.number}.#{@chapter.table(id).number} #{compile_inline(caption)}")
366
418
  puts macro('reviewtablecaption', compile_inline(caption))
367
419
  end
420
+ puts macro('label', table_label(id))
368
421
  end
369
422
 
370
423
  def table_begin(ncols)
@@ -388,9 +441,9 @@ module ReVIEW
388
441
  def th(s)
389
442
  ## use shortstack for @<br>
390
443
  if /\\\\/i =~ s
391
- macro('textgt', macro('shortstack[l]', s))
444
+ macro('reviewth', macro('shortstack[l]', s))
392
445
  else
393
- macro('textgt', s)
446
+ macro('reviewth', s)
394
447
  end
395
448
  end
396
449
 
@@ -425,6 +478,8 @@ module ReVIEW
425
478
  latex_block 'center', lines
426
479
  end
427
480
 
481
+ alias centering center
482
+
428
483
  def flushright(lines)
429
484
  latex_block 'flushright', lines
430
485
  end
@@ -462,12 +517,19 @@ module ReVIEW
462
517
  end
463
518
  end
464
519
 
465
- def comment(str)
520
+ def comment(lines, comment = nil)
521
+ lines ||= []
522
+ lines.unshift comment unless comment.blank?
466
523
  if ReVIEW.book.param["draft"]
524
+ str = lines.join("")
467
525
  puts macro('pdfcomment', escape(str))
468
526
  end
469
527
  end
470
528
 
529
+ def hr
530
+ puts '\hrule'
531
+ end
532
+
471
533
  def label(id)
472
534
  puts macro('label', id)
473
535
  end
@@ -526,12 +588,12 @@ module ReVIEW
526
588
 
527
589
  def inline_table(id)
528
590
  chapter, id = extract_chapter_id(id)
529
- macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}")
591
+ macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id))
530
592
  end
531
593
 
532
594
  def inline_img(id)
533
595
  chapter, id = extract_chapter_id(id)
534
- macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}")
596
+ macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id))
535
597
  end
536
598
 
537
599
  def footnote(id, content)
@@ -610,8 +672,11 @@ module ReVIEW
610
672
  end
611
673
 
612
674
  def inline_tt(str)
613
- str_escaped = escape(str).gsub(/\-\-/, "{-}{-}")
614
- macro('texttt', str_escaped)
675
+ macro('texttt', escape(str))
676
+ end
677
+
678
+ def inline_del(str)
679
+ macro('reviewstrike', escape(str))
615
680
  end
616
681
 
617
682
  def inline_tti(str)
@@ -623,11 +688,11 @@ module ReVIEW
623
688
  end
624
689
 
625
690
  def inline_bib(id)
626
- "[#{@chapter.bibpaper(id).number}]"
691
+ macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
627
692
  end
628
693
 
629
694
  def inline_hd_chap(chap, id)
630
- "「#{chap.headline_index.number(id)} #{chap.headline(id).caption}」"
695
+ "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
631
696
  end
632
697
 
633
698
  def inline_raw(str)
@@ -643,17 +708,21 @@ module ReVIEW
643
708
  end
644
709
 
645
710
  def inline_em(str)
646
- macro('textbf', escape(str))
711
+ macro('reviewem', escape(str))
647
712
  end
648
713
 
649
714
  def inline_strong(str)
650
- macro('textbf', escape(str))
715
+ macro('reviewstrong', escape(str))
651
716
  end
652
717
 
653
718
  def inline_u(str)
654
719
  macro('Underline', escape(str))
655
720
  end
656
721
 
722
+ def inline_ami(str)
723
+ macro('reviewami', escape(str))
724
+ end
725
+
657
726
  def inline_icon(id)
658
727
  macro('includegraphics', @chapter.image(id).path)
659
728
  end
@@ -666,17 +735,18 @@ module ReVIEW
666
735
  def inline_comment(str)
667
736
  if ReVIEW.book.param["draft"]
668
737
  macro('pdfcomment', escape(str))
738
+ else
739
+ ""
669
740
  end
670
741
  end
671
742
 
672
743
  def bibpaper_header(id, caption)
673
744
  puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
745
+ puts macro('label', bib_label(id))
674
746
  end
675
747
 
676
748
  def bibpaper_bibpaper(id, caption, lines)
677
- lines.each do |line|
678
- puts detab(line)
679
- end
749
+ print split_paragraph(lines).join("")
680
750
  end
681
751
 
682
752
  def index(str)
@@ -706,7 +776,7 @@ module ReVIEW
706
776
  end
707
777
 
708
778
  def compile_href(url, label)
709
- if /\A[a-z]+:\/\// =~ url
779
+ if /\A[a-z]+:/ =~ url
710
780
  if label
711
781
  macro("href", escape_url(url), escape(label))
712
782
  else
@@ -729,6 +799,10 @@ module ReVIEW
729
799
  "svg"
730
800
  end
731
801
 
802
+ def olnum(num)
803
+ @ol_num = num.to_i
804
+ end
805
+
732
806
  end
733
807
 
734
808
  end