review 0.6.0 → 0.9.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 (68) hide show
  1. data/ChangeLog +441 -0
  2. data/README.rdoc +25 -0
  3. data/Rakefile +13 -1
  4. data/VERSION +1 -1
  5. data/bin/review-check +1 -1
  6. data/bin/review-compile +19 -10
  7. data/bin/review-epubmaker +114 -17
  8. data/bin/review-index +8 -1
  9. data/bin/review-pdfmaker +378 -0
  10. data/bin/review-preproc +2 -3
  11. data/bin/review-vol +1 -2
  12. data/debian/README.Debian +12 -0
  13. data/debian/README.source +5 -0
  14. data/debian/changelog +5 -0
  15. data/debian/compat +1 -0
  16. data/debian/control +22 -0
  17. data/debian/copyright +60 -0
  18. data/debian/docs +5 -0
  19. data/debian/manpage.1.ex +59 -0
  20. data/debian/patches/path.diff +91 -0
  21. data/debian/patches/series +1 -0
  22. data/debian/review.install +13 -0
  23. data/debian/review.links +4 -0
  24. data/debian/rules +13 -0
  25. data/debian/source/format +1 -0
  26. data/doc/format.rdoc +477 -0
  27. data/doc/format.re +19 -0
  28. data/doc/format_idg.rdoc +180 -0
  29. data/doc/ruby-uuid/README +11 -0
  30. data/doc/ruby-uuid/README.ja +34 -0
  31. data/doc/sample.css +17 -0
  32. data/doc/sample.yaml +8 -4
  33. data/lib/lineinput.rb +1 -1
  34. data/lib/review/book.rb +43 -36
  35. data/lib/review/builder.rb +78 -33
  36. data/lib/review/compiler.rb +45 -48
  37. data/lib/review/epubbuilder.rb +1 -675
  38. data/lib/review/exception.rb +1 -1
  39. data/lib/review/htmlbuilder.rb +627 -49
  40. data/lib/review/htmlutils.rb +5 -0
  41. data/lib/review/idgxmlbuilder.rb +239 -250
  42. data/lib/review/index.rb +84 -7
  43. data/lib/review/latexbuilder.rb +261 -42
  44. data/lib/review/latexutils.rb +15 -6
  45. data/lib/review/preprocessor.rb +40 -6
  46. data/lib/review/textutils.rb +22 -0
  47. data/lib/review/topbuilder.rb +4 -1
  48. data/lib/uuid.rb +312 -0
  49. data/review.gemspec +44 -12
  50. data/test/CHAPS +2 -0
  51. data/test/bib.re +13 -0
  52. data/test/test.re +43 -0
  53. data/test/test_book.rb +1191 -0
  54. data/test/test_builder.rb +147 -0
  55. data/test/test_htmlbuilder.rb +191 -10
  56. data/test/test_htmlutils.rb +24 -0
  57. data/test/test_idgxmlbuilder.rb +310 -0
  58. data/test/test_index.rb +15 -0
  59. data/test/test_latexbuilder.rb +217 -6
  60. data/test/test_lineinput.rb +198 -0
  61. data/test/test_textutils.rb +68 -0
  62. data/test/test_uuid.rb +156 -0
  63. metadata +43 -10
  64. data/doc/format.txt +0 -434
  65. data/doc/format_idg.txt +0 -194
  66. data/doc/format_sjis.txt +0 -313
  67. data/setup.rb +0 -1587
  68. data/test/test_epubbuilder.rb +0 -73
@@ -1,4 +1,4 @@
1
- # $Id: index.rb 4300 2009-06-21 23:45:49Z kmuto $
1
+ # encoding: utf-8
2
2
  #
3
3
  # Copyright (c) 2002-2007 Minero Aoki
4
4
  # 2008-2009 Minero Aoki, Kenshi Muto
@@ -48,10 +48,6 @@ module ReVIEW
48
48
  end
49
49
  end
50
50
 
51
- def setParameter(param)
52
- @param = param
53
- end
54
-
55
51
  def [](id)
56
52
  @index.fetch(id)
57
53
  end
@@ -63,6 +59,10 @@ module ReVIEW
63
59
  def each(&block)
64
60
  @items.each(&block)
65
61
  end
62
+
63
+ def has_key?(id)
64
+ return @index.has_key?(id)
65
+ end
66
66
  end
67
67
 
68
68
 
@@ -157,7 +157,7 @@ module ReVIEW
157
157
 
158
158
  # internal use only
159
159
  def find_pathes(id)
160
- if @param["subdirmode"].nil?
160
+ if ReVIEW.book.param["subdirmode"].nil?
161
161
  re = /\A#{@chapid}-#{id}(?i:#{@types.join('|')})\z/x
162
162
  entries().select {|ent| re =~ ent }\
163
163
  .sort_by {|ent| @types.index(File.extname(ent).downcase) }\
@@ -173,7 +173,7 @@ module ReVIEW
173
173
  private
174
174
 
175
175
  def entries
176
- if @param["subdirmode"].nil?
176
+ if ReVIEW.book.param["subdirmode"].nil?
177
177
  @entries ||= Dir.entries(@basedir)
178
178
  else
179
179
  @entries ||= Dir.entries(File.join(@basedir, @chapid))
@@ -221,4 +221,81 @@ module ReVIEW
221
221
  new(items)
222
222
  end
223
223
  end
224
+
225
+ class NumberlessImageIndex < ImageIndex
226
+ class Item < ImageIndex::Item
227
+ def initialize(id, number)
228
+ @id = id
229
+ @number = ""
230
+ @pathes = nil
231
+ end
232
+ end
233
+
234
+ def NumberlessImageIndex.item_type
235
+ 'numberlessimage'
236
+ end
237
+
238
+ def number(id)
239
+ ""
240
+ end
241
+ end
242
+
243
+ class IndepImageIndex < ImageIndex
244
+ class Item < ImageIndex::Item
245
+ def initialize(id, number)
246
+ @id = id
247
+ @number = ""
248
+ @pathes = nil
249
+ end
250
+ end
251
+
252
+ def IndepImageIndex.item_type
253
+ 'indepimage'
254
+ end
255
+
256
+ def number(id)
257
+ ""
258
+ end
259
+ end
260
+
261
+ class HeadlineIndex < Index
262
+ Item = Struct.new(:id, :number, :caption)
263
+
264
+ def HeadlineIndex.parse(src, chap)
265
+ items = []
266
+ indexs = []
267
+ headlines = []
268
+ src.each do |line|
269
+ if m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
270
+ next if m[2] == 'column'
271
+ index = m[1].size - 2
272
+ if index >= 0
273
+ if indexs.size > (index + 1)
274
+ indexs = indexs.take(index + 1)
275
+ headlines = headlines.take(index + 1)
276
+ end
277
+ indexs << 0 if indexs[index].nil?
278
+ indexs[index] += 1
279
+ headlines[index] = m[4].strip
280
+ items.push Item.new(headlines.join("|"), indexs.dup, m[4].strip)
281
+ end
282
+ end
283
+ end
284
+ new(items, chap)
285
+ end
286
+
287
+ def initialize(items, chap)
288
+ @items = items
289
+ @chap = chap
290
+ @index = {}
291
+ items.each do |i|
292
+ warn "warning: duplicate ID: #{i.id}" unless @index[i.id].nil?
293
+ @index[i.id] = i
294
+ end
295
+ end
296
+
297
+ def number(id)
298
+ return ([@chap.number] + @index.fetch(id).number).join(".")
299
+ end
300
+ end
224
301
  end
@@ -1,4 +1,4 @@
1
- #
1
+ # encoding: utf-8
2
2
  #
3
3
  # Copyright (c) 2002-2007 Minero Aoki
4
4
  # 2008-2009 Minero Aoki, Kenshi Muto
@@ -21,6 +21,13 @@ module ReVIEW
21
21
  include LaTeXUtils
22
22
  include TextUtils
23
23
 
24
+ [:icon, :dtp, :hd_chap].each {|e|
25
+ Compiler.definline(e)
26
+ }
27
+
28
+ Compiler.defblock(:memo, 0..1)
29
+ Compiler.defsingle(:latextsize, 1)
30
+
24
31
  def extname
25
32
  '.tex'
26
33
  end
@@ -28,6 +35,9 @@ module ReVIEW
28
35
  def builder_init_file
29
36
  #@index = indexes[:latex_index]
30
37
  @blank_needed = false
38
+ @latex_tsize = nil
39
+ @tsize = nil
40
+ @table_caption = nil
31
41
  end
32
42
  private :builder_init_file
33
43
 
@@ -63,32 +73,60 @@ module ReVIEW
63
73
 
64
74
  def headline(level, label, caption)
65
75
  prefix = ""
66
- if level > @param["secnolevel"]
76
+ if level > ReVIEW.book.param["secnolevel"]
67
77
  prefix = "*"
68
78
  end
69
79
  blank unless @output.pos == 0
70
- puts macro(HEADLINE[level]+prefix, escape(caption))
80
+ puts macro(HEADLINE[level]+prefix, compile_inline(caption))
81
+ end
82
+
83
+ def nonum_begin(level, label, caption)
84
+ blank unless @output.pos == 0
85
+ puts macro(HEADLINE[level]+"*", compile_inline(caption))
86
+ end
87
+
88
+ def nonum_end(level)
71
89
  end
72
90
 
73
91
  def column_begin(level, label, caption)
74
92
  blank
75
93
  ## puts '\vspace{2zw}'
76
- puts '\begin{center}'
77
- puts '\begin{minipage}{0.9\linewidth}'
78
- puts '\begin{framed}'
79
- puts '\setlength{\FrameSep}{2zw}'
94
+ ## puts '\begin{center}'
95
+ ## puts '\begin{minipage}{1.0\linewidth}'
96
+ ## puts '\begin{framed}'
97
+ ## puts '\setlength{\FrameSep}{1zw}'
98
+
99
+ ## nonum_begin(3, label, caption) # FIXME
100
+
101
+ puts "\\begin{reviewcolumn}\n"
102
+ puts macro('reviewcolumnhead', nil, compile_inline(caption))
80
103
 
81
- headline(2, label, caption) # FIXME
82
104
  end
83
105
 
84
106
  def column_end(level)
85
- puts '\end{framed}'
86
- puts '\end{minipage}'
87
- puts '\end{center}'
88
- ## puts '\vspace{2zw}'
107
+ ## puts '\end{framed}'
108
+ ## puts '\end{minipage}'
109
+ ## puts '\end{center}'
110
+ ## ## puts '\vspace{2zw}'
111
+ puts "\\end{reviewcolumn}\n"
89
112
  blank
90
113
  end
91
114
 
115
+ def minicolumn(type, lines, caption)
116
+ puts "\\begin{reviewminicolumn}\n"
117
+ unless caption.nil?
118
+ puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
119
+ end
120
+ lines.each {|l|
121
+ puts l
122
+ }
123
+ puts "\\end{reviewminicolumn}\n"
124
+ end
125
+
126
+ def memo(lines, caption = nil)
127
+ minicolumn("memo", lines, caption)
128
+ end
129
+
92
130
  def ul_begin
93
131
  blank
94
132
  puts '\begin{itemize}'
@@ -158,46 +196,91 @@ module ReVIEW
158
196
  def emlist(lines)
159
197
  blank
160
198
  puts '\begin{reviewemlist}'
161
- puts '\begin{verbatim}'
199
+ puts '\begin{alltt}'
162
200
  lines.each do |line|
163
201
  puts line
164
202
  end
165
- puts '\end{verbatim}'
203
+ puts '\end{alltt}'
204
+ puts '\end{reviewemlist}'
205
+ blank
206
+ end
207
+
208
+ def emlistnum(lines)
209
+ blank
210
+ puts '\begin{reviewemlist}'
211
+ puts '\begin{alltt}'
212
+ lines.each_with_index do |line, i|
213
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
214
+ end
215
+ puts '\end{alltt}'
166
216
  puts '\end{reviewemlist}'
167
217
  blank
168
218
  end
169
219
 
220
+ def listnum_body(lines)
221
+ puts '\begin{reviewlist}'
222
+ puts '\begin{alltt}'
223
+ lines.each_with_index do |line, i|
224
+ puts detab((i+1).to_s.rjust(2) + ": " + line)
225
+ end
226
+ puts '\end{alltt}'
227
+ puts '\end{reviewlist}'
228
+ puts
229
+
230
+ end
231
+
170
232
  def cmd(lines)
171
233
  blank
172
234
  puts '\begin{reviewcmd}'
173
- puts '\begin{verbatim}'
235
+ puts '\begin{alltt}'
174
236
  lines.each do |line|
175
237
  puts line
176
238
  end
177
- puts '\end{verbatim}'
239
+ puts '\end{alltt}'
178
240
  puts '\end{reviewcmd}'
179
241
  blank
180
242
  end
181
243
 
182
244
  def list_header(id, caption)
183
- puts macro('reviewlistcaption', "#{@chapter.number}.#{@chapter.list(id).number}", text(caption))
245
+ puts macro('reviewlistcaption', "リスト#{@chapter.number}.#{@chapter.list(id).number}: #{compile_inline(caption)}")
184
246
  end
185
247
 
186
248
  def list_body(lines)
187
249
  puts '\begin{reviewlist}'
188
- puts '\begin{verbatim}'
250
+ puts '\begin{alltt}'
189
251
  lines.each do |line|
190
252
  puts line
191
253
  end
192
- puts '\end{verbatim}'
254
+ puts '\end{alltt}'
193
255
  puts '\end{reviewlist}'
194
- puts
256
+ puts ""
257
+ end
258
+
259
+ def source(lines, caption)
260
+ puts '\begin{reviewlist}'
261
+ source_header caption
262
+ source_body lines
263
+ puts '\end{reviewlist}'
264
+ puts ""
265
+ end
266
+
267
+ def source_header(caption)
268
+ puts macro('reviewlistcaption', compile_inline(caption))
195
269
  end
196
270
 
271
+ def source_body(lines)
272
+ puts '\begin{alltt}'
273
+ lines.each do |line|
274
+ puts line
275
+ end
276
+ puts '\end{alltt}'
277
+ end
278
+
279
+
197
280
  def image_header(id, caption)
198
281
  end
199
282
 
200
- def image_image(id, metric, caption)
283
+ def image_image(id, caption, metric)
201
284
  # image is always bound here
202
285
  puts '\begin{reviewimage}'
203
286
  if metric
@@ -207,22 +290,22 @@ module ReVIEW
207
290
  end
208
291
  puts macro('label', image_label(id))
209
292
  if !caption.empty?
210
- puts macro('caption', text(caption))
293
+ puts macro('caption', compile_inline(caption))
211
294
  end
212
295
  puts '\end{reviewimage}'
213
296
  end
214
297
 
215
298
  def image_dummy(id, caption, lines)
216
299
  puts '\begin{reviewdummyimage}'
217
- puts '\begin{verbatim}'
300
+ puts '\begin{alltt}'
218
301
  path = @chapter.image(id).path
219
302
  puts "--[[path = #{path} (#{existence(id)})]]--"
220
303
  lines.each do |line|
221
304
  puts detab(line.rstrip)
222
305
  end
223
- puts '\end{verbatim}'
306
+ puts '\end{alltt}'
224
307
  puts macro('label', image_label(id))
225
- puts text(caption)
308
+ puts compile_inline(caption)
226
309
  puts '\end{reviewdummyimage}'
227
310
  end
228
311
 
@@ -236,13 +319,42 @@ module ReVIEW
236
319
  end
237
320
  private :image_label
238
321
 
322
+ def indepimage(id, caption=nil, metric=nil)
323
+ puts '\begin{reviewimage}'
324
+ if metric
325
+ puts "\\includegraphics[#{metric}]{#{@chapter.image(id).path}}"
326
+ else
327
+ puts macro('includegraphics', @chapter.image(id).path)
328
+ end
329
+ if !caption.nil? && !caption.empty?
330
+ puts macro('caption', compile_inline(caption))
331
+ end
332
+ puts '\end{reviewimage}'
333
+ end
334
+
335
+ alias :numberlessimage indepimage
336
+
239
337
  def table_header(id, caption)
240
- puts macro('reviewtablecaption', "#{@chapter.number}.#{@chapter.table(id).number}", text(caption))
338
+ if caption && !caption.empty?
339
+ @table_caption = true
340
+ puts '\begin{table}[h]'
341
+ ## puts macro('reviewtablecaption', "表#{@chapter.number}.#{@chapter.table(id).number} #{compile_inline(caption)}")
342
+ puts macro('reviewtablecaption', compile_inline(caption))
343
+ end
241
344
  end
242
345
 
243
346
  def table_begin(ncols)
244
- puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
347
+ if @latex_tsize
348
+ puts macro('begin', 'reviewtable', @latex_tsize)
349
+ elsif @tsize
350
+ cellwidth = @tsize.split(/\s*,\s*/)
351
+ puts macro('begin', 'reviewtable', '|'+(cellwidth.collect{|i| "p{#{i}mm}"}.join('|'))+'|')
352
+ else
353
+ puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
354
+ end
245
355
  puts '\hline'
356
+ @tsize = nil
357
+ @latex_tsize = nil
246
358
  end
247
359
 
248
360
  def table_separator
@@ -250,11 +362,21 @@ module ReVIEW
250
362
  end
251
363
 
252
364
  def th(s)
253
- macro('textgt', s)
365
+ ## use shortstack for @<br>
366
+ if /\\\\/i =~ s
367
+ macro('textgt', macro('shortstack[l]', s))
368
+ else
369
+ macro('textgt', s)
370
+ end
254
371
  end
255
372
 
256
373
  def td(s)
257
- s
374
+ ## use shortstack for @<br>
375
+ if /\\\\/ =~ s
376
+ macro('shortstack[l]', s)
377
+ else
378
+ s
379
+ end
258
380
  end
259
381
 
260
382
  def tr(rows)
@@ -264,26 +386,45 @@ module ReVIEW
264
386
 
265
387
  def table_end
266
388
  puts macro('end', 'reviewtable')
389
+ if @table_caption
390
+ puts '\end{table}'
391
+ end
392
+ @table_caption = nil
267
393
  blank
268
394
  end
269
395
 
270
396
  def quote(lines)
271
- latex_block 'quotation', lines
397
+ latex_block 'quote', lines
272
398
  end
273
399
 
274
400
  def center(lines)
275
401
  latex_block 'center', lines
276
402
  end
277
403
 
278
- def right(lines)
404
+ def flushright(lines)
279
405
  latex_block 'flushright', lines
280
406
  end
281
407
 
408
+ def texequation(lines)
409
+ blank
410
+ puts macro('begin','equation*')
411
+ lines.each do |line|
412
+ puts unescape_latex(line)
413
+ end
414
+ puts macro('end', 'equation*')
415
+ blank
416
+ end
417
+
282
418
  def latex_block(type, lines)
283
419
  blank
284
420
  puts macro('begin', type)
285
- lines.each do |line|
286
- puts line
421
+ if ReVIEW.book.param["deprecated-blocklines"].nil?
422
+ blocked_lines = split_paragraph(lines)
423
+ puts blocked_lines.join("\n\n")
424
+ else
425
+ lines.each do |line|
426
+ puts line
427
+ end
287
428
  end
288
429
  puts macro('end', type)
289
430
  blank
@@ -319,15 +460,18 @@ module ReVIEW
319
460
 
320
461
  # FIXME: use TeX native label/ref.
321
462
  def inline_list(id)
322
- macro('reviewlistref', "#{@chapter.number}.#{@chapter.list(id).number}")
463
+ chapter, id = extract_chapter_id(id)
464
+ macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}")
323
465
  end
324
466
 
325
467
  def inline_table(id)
326
- macro('reviewtableref', "#{@chapter.number}.#{@chapter.table(id).number}")
468
+ chapter, id = extract_chapter_id(id)
469
+ macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}")
327
470
  end
328
471
 
329
472
  def inline_img(id)
330
- macro('reviewimageref', "#{@chapter.number}.#{@chapter.image(id).number}")
473
+ chapter, id = extract_chapter_id(id)
474
+ macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}")
331
475
  end
332
476
 
333
477
  def footnote(id, content)
@@ -358,14 +502,39 @@ module ReVIEW
358
502
  index(str)
359
503
  end
360
504
 
361
- # index
505
+ # index -> italic
362
506
  def inline_i(str)
507
+ macro('textit', escape(str))
508
+ end
509
+
510
+ # index
511
+ def inline_idx(str)
363
512
  text(str) + index(str)
364
513
  end
365
514
 
515
+ # hidden index??
516
+ def inline_hidx(str)
517
+ index(str)
518
+ end
519
+
366
520
  # bold
367
521
  def inline_b(str)
368
- macro('textbf', text(str))
522
+ macro('textbf', escape(str))
523
+ end
524
+
525
+ # line break
526
+ def inline_br(str)
527
+ "\\\\\n"
528
+ end
529
+
530
+ def inline_dtp(str)
531
+ # ignore
532
+ ""
533
+ end
534
+
535
+ ## @<code> is same as @<tt>
536
+ def inline_code(str)
537
+ macro('texttt', escape(str))
369
538
  end
370
539
 
371
540
  def nofunc_text(str)
@@ -373,7 +542,53 @@ module ReVIEW
373
542
  end
374
543
 
375
544
  def inline_tt(str)
376
- macro('texttt', escape(str))
545
+ str_escaped = escape(str).gsub(/\-\-/, "{-}{-}")
546
+ macro('texttt', str_escaped)
547
+ end
548
+
549
+ def inline_tti(str)
550
+ macro('texttt', macro('textit', escape(str)))
551
+ end
552
+
553
+ def inline_ttb(str)
554
+ macro('texttt', macro('textbf', escape(str)))
555
+ end
556
+
557
+ def inline_hd_chap(chap, id)
558
+ "「#{chap.headline_index.number(id)} #{chap.headline(id).caption}」"
559
+ end
560
+
561
+ def inline_raw(str)
562
+ escape(str)
563
+ end
564
+
565
+ def inline_sub(str)
566
+ macro('textsubscript', escape(str))
567
+ end
568
+
569
+ def inline_sup(str)
570
+ macro('textsuperscript', escape(str))
571
+ end
572
+
573
+ def inline_em(str)
574
+ macro('textbf', escape(str))
575
+ end
576
+
577
+ def inline_strong(str)
578
+ macro('textbf', escape(str))
579
+ end
580
+
581
+ def inline_u(str)
582
+ macro('Underline', escape(str))
583
+ end
584
+
585
+ def inline_icon(id)
586
+ macro('includegraphics', @chapter.image(id).path)
587
+ end
588
+
589
+ def inline_uchar(str)
590
+ # with otf package
591
+ macro('UTF', escape(str))
377
592
  end
378
593
 
379
594
  def index(str)
@@ -396,9 +611,9 @@ module ReVIEW
396
611
 
397
612
  def compile_kw(word, alt)
398
613
  if alt
399
- macro('textgt', escape(word)) + "(#{escape(alt.strip)})"
614
+ macro('reviewkw', escape(word)) + "(#{escape(alt.strip)})"
400
615
  else
401
- macro('textgt', escape(word))
616
+ macro('reviewkw', escape(word))
402
617
  end
403
618
  end
404
619
 
@@ -412,7 +627,11 @@ module ReVIEW
412
627
  end
413
628
 
414
629
  def tsize(str)
415
- # dummy
630
+ @tsize = str
631
+ end
632
+
633
+ def latextsize(str)
634
+ @latex_tsize = str
416
635
  end
417
636
 
418
637
  end