review 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/COPYING +515 -0
  2. data/ChangeLog +1278 -0
  3. data/README.rdoc +21 -0
  4. data/Rakefile +42 -0
  5. data/VERSION +1 -0
  6. data/bin/review-check +190 -0
  7. data/bin/review-checkdep +63 -0
  8. data/bin/review-compile +165 -0
  9. data/bin/review-epubmaker +525 -0
  10. data/bin/review-index +108 -0
  11. data/bin/review-preproc +140 -0
  12. data/bin/review-validate +51 -0
  13. data/bin/review-vol +106 -0
  14. data/doc/format.re +486 -0
  15. data/doc/format.txt +434 -0
  16. data/doc/format_idg.txt +194 -0
  17. data/doc/format_sjis.txt +313 -0
  18. data/doc/sample.css +91 -0
  19. data/doc/sample.yaml +46 -0
  20. data/lib/lineinput.rb +155 -0
  21. data/lib/review/book.rb +580 -0
  22. data/lib/review/builder.rb +274 -0
  23. data/lib/review/compat.rb +22 -0
  24. data/lib/review/compiler.rb +483 -0
  25. data/lib/review/epubbuilder.rb +692 -0
  26. data/lib/review/ewbbuilder.rb +382 -0
  27. data/lib/review/exception.rb +21 -0
  28. data/lib/review/htmlbuilder.rb +370 -0
  29. data/lib/review/htmllayout.rb +19 -0
  30. data/lib/review/htmlutils.rb +27 -0
  31. data/lib/review/idgxmlbuilder.rb +1078 -0
  32. data/lib/review/index.rb +224 -0
  33. data/lib/review/latexbuilder.rb +420 -0
  34. data/lib/review/latexindex.rb +35 -0
  35. data/lib/review/latexutils.rb +52 -0
  36. data/lib/review/preprocessor.rb +520 -0
  37. data/lib/review/textutils.rb +19 -0
  38. data/lib/review/tocparser.rb +333 -0
  39. data/lib/review/tocprinter.rb +220 -0
  40. data/lib/review/topbuilder.rb +572 -0
  41. data/lib/review/unfold.rb +138 -0
  42. data/lib/review/volume.rb +66 -0
  43. data/lib/review.rb +4 -0
  44. data/review.gemspec +93 -0
  45. data/setup.rb +1587 -0
  46. data/test/test_epubbuilder.rb +73 -0
  47. data/test/test_helper.rb +2 -0
  48. data/test/test_htmlbuilder.rb +42 -0
  49. data/test/test_latexbuilder.rb +74 -0
  50. metadata +122 -0
@@ -0,0 +1,572 @@
1
+ # $Id: topbuilder.rb 4304 2009-07-01 12:03:39Z kmuto $
2
+ #
3
+ # Copyright (c) 2002-2006 Minero Aoki
4
+ # 2008-2009 Minero Aoki, Kenshi Muto
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
+ #
10
+
11
+ require 'review/builder'
12
+ require 'review/textutils'
13
+
14
+ module ReVIEW
15
+
16
+ class TOPBuilder < Builder
17
+
18
+ include TextUtils
19
+
20
+ [:i, :tt, :ttbold, :tti, :idx, :hidx, :dtp, :sup, :sub, :hint, :raw, :maru, :keytop, :labelref, :ref, :pageref, :u, :icon, :balloon].each {|e|
21
+ Compiler.definline(e)
22
+ }
23
+ Compiler.defsingle(:dtp, 1)
24
+ Compiler.defsingle(:raw, 1)
25
+ Compiler.defsingle(:indepimage, 1)
26
+ Compiler.defsingle(:label, 1)
27
+ Compiler.defsingle(:tsize, 1)
28
+
29
+ Compiler.defblock(:insn, 1)
30
+ Compiler.defblock(:flushright, 0)
31
+ Compiler.defblock(:note, 0..1)
32
+ Compiler.defblock(:memo, 0..1)
33
+ Compiler.defblock(:tip, 0..1)
34
+ Compiler.defblock(:info, 0..1)
35
+ Compiler.defblock(:planning, 0..1)
36
+ Compiler.defblock(:best, 0..1)
37
+ Compiler.defblock(:important, 0..1)
38
+ Compiler.defblock(:securty, 0..1)
39
+ Compiler.defblock(:caution, 0..1)
40
+ Compiler.defblock(:notice, 0..1)
41
+ Compiler.defblock(:point, 0..1)
42
+ Compiler.defblock(:reference, 0)
43
+ Compiler.defblock(:term, 0)
44
+ Compiler.defblock(:practice, 0)
45
+ Compiler.defblock(:box, 0..1)
46
+ Compiler.defblock(:expert, 0)
47
+ Compiler.defblock(:lead, 0)
48
+
49
+ def builder_init_file
50
+ @section = 0
51
+ @blank_seen = true
52
+ @choice = nil
53
+ end
54
+ private :builder_init_file
55
+
56
+ def print(s)
57
+ @blank_seen = false
58
+ super
59
+ end
60
+ private :print
61
+
62
+ def puts(s)
63
+ @blank_seen = false
64
+ super
65
+ end
66
+ private :puts
67
+
68
+ def blank
69
+ @output.puts unless @blank_seen
70
+ @blank_seen = true
71
+ end
72
+ private :blank
73
+
74
+ def result
75
+ @output.string
76
+ end
77
+
78
+ def warn(msg)
79
+ $stderr.puts "#{@location.filename}:#{@location.lineno}: warning: #{msg}"
80
+ end
81
+
82
+ def error(msg)
83
+ $stderr.puts "#{@location.filename}:#{@location.lineno}: error: #{msg}"
84
+ end
85
+
86
+ def messages
87
+ error_messages() + warning_messages()
88
+ end
89
+
90
+ def headline(level, label, caption)
91
+ # FIXME: handling label
92
+ blank
93
+ case level
94
+ when 1
95
+ puts "■H1■第#{@chapter.number}章 #{caption}"
96
+ when 2
97
+ puts "■H2■#{@chapter.number}.#{@section += 1} #{caption}"
98
+ when 3
99
+ puts "■H3■#{caption}"
100
+ when 4
101
+ puts "■H4■#{caption}"
102
+ when 5
103
+ puts "■H5■#{caption}"
104
+ else
105
+ raise "caption level too deep or unsupported: #{level}"
106
+ end
107
+ end
108
+
109
+ def column_begin(level, label, caption)
110
+ blank
111
+ puts "◆→開始:コラム←◆"
112
+ puts "■#{caption}"
113
+ end
114
+
115
+ def column_end(level)
116
+ puts "◆→終了:コラム←◆"
117
+ blank
118
+ end
119
+
120
+ def ul_begin
121
+ blank
122
+ end
123
+
124
+ def ul_item(lines)
125
+ print @choice.nil? ? "●" : @choice
126
+ puts "\t#{lines.join('')}"
127
+ end
128
+
129
+ def ul_end
130
+ blank
131
+ end
132
+
133
+ def choice_single_begin
134
+ @choice = "○"
135
+ blank
136
+ end
137
+
138
+ def choice_single_end
139
+ @choice = nil
140
+ blank
141
+ end
142
+
143
+ def choice_multi_begin
144
+ @choice = "□"
145
+ blank
146
+ end
147
+
148
+ def choice_multi_end
149
+ @choice = nil
150
+ blank
151
+ end
152
+
153
+ def ol_begin
154
+ blank
155
+ @olitem = 0
156
+ end
157
+
158
+ def ol_item(lines, num)
159
+ #puts "#{@olitem += 1}\t#{lines.join('')}"
160
+ puts "#{num}\t#{lines.join('')}"
161
+ end
162
+
163
+ def ol_end
164
+ blank
165
+ @olitem = nil
166
+ end
167
+
168
+ def dl_begin
169
+ blank
170
+ end
171
+
172
+ def dt(line)
173
+ puts "★#{line}☆"
174
+ end
175
+
176
+ def dd(lines)
177
+ split_paragraph(lines).each do |paragraph|
178
+ puts "\t#{paragraph.gsub(/\n/, '')}"
179
+ end
180
+ end
181
+
182
+ def split_paragraph(lines)
183
+ lines.map {|line| line.strip }.join("\n").strip.split("\n\n")
184
+ end
185
+
186
+ def dl_end
187
+ blank
188
+ end
189
+
190
+ def paragraph(lines)
191
+ puts lines.join('')
192
+ end
193
+
194
+ def read(lines)
195
+ puts "◆→開始:リード←◆"
196
+ paragraph(lines)
197
+ puts "◆→終了:リード←◆"
198
+ end
199
+
200
+ alias lead read
201
+
202
+ def inline_list(id)
203
+ "リスト#{@chapter.number}.#{@chapter.list(id).number}"
204
+ end
205
+
206
+ def list_header(id, caption)
207
+ blank
208
+ puts "◆→開始:リスト←◆"
209
+ puts "リスト#{@chapter.number}.#{@chapter.list(id).number} #{caption}"
210
+ blank
211
+ end
212
+
213
+ def list_body(lines)
214
+ lines.each do |line|
215
+ puts line
216
+ end
217
+ puts "◆→終了:リスト←◆"
218
+ blank
219
+ end
220
+
221
+ def base_block(type, lines, caption = nil)
222
+ blank
223
+ puts "◆→開始:#{type}←◆"
224
+ puts "■#{caption}" unless caption.nil?
225
+ puts lines.join("\n")
226
+ puts "◆→終了:#{type}←◆"
227
+ blank
228
+ end
229
+
230
+ def emlist(lines, caption = nil)
231
+ base_block "インラインリスト", lines, caption
232
+ end
233
+
234
+ def cmd(lines, caption = nil)
235
+ base_block "コマンド", lines, caption
236
+ end
237
+
238
+ def quote(lines)
239
+ base_block "引用", lines, nil
240
+ end
241
+
242
+ def inline_img(id)
243
+ "図#{@chapter.number}.#{@chapter.image(id).number}"
244
+ end
245
+
246
+ def image(lines, id, caption)
247
+ blank
248
+ puts "◆→開始:図←◆"
249
+ puts "図#{@chapter.number}.#{@chapter.image(id).number} #{caption}"
250
+ blank
251
+ if @chapter.image(id).bound?
252
+ puts "◆→#{@chapter.image(id).path}←◆"
253
+ else
254
+ lines.each do |line|
255
+ puts line
256
+ end
257
+ end
258
+ puts "◆→終了:図←◆"
259
+ blank
260
+ end
261
+
262
+ def inline_table(id)
263
+ "表#{@chapter.number}.#{@chapter.table(id).number}"
264
+ end
265
+
266
+ def table_header(id, caption)
267
+ blank
268
+ puts "◆→開始:表←◆"
269
+ puts "表#{@chapter.number}.#{@chapter.table(id).number} #{caption}"
270
+ blank
271
+ end
272
+
273
+ def table_begin(ncols)
274
+ end
275
+
276
+ def tr(rows)
277
+ puts rows.join("\t")
278
+ end
279
+
280
+ def th(str)
281
+ "★#{str}☆"
282
+ end
283
+
284
+ def td(str)
285
+ str
286
+ end
287
+
288
+ def table_end
289
+ puts "◆→終了:表←◆"
290
+ blank
291
+ end
292
+
293
+ def comment(str)
294
+ puts "◆→DTP担当:#{str}←◆"
295
+ end
296
+
297
+ def inline_fn(id)
298
+ "【注#{@chapter.footnote(id).number}】"
299
+ end
300
+
301
+ def footnote(id, str)
302
+ puts "【注#{@chapter.footnote(id).number}】#{compile_inline(str)}"
303
+ end
304
+
305
+ def compile_kw(word, alt)
306
+ if alt
307
+ then "★#{word}☆(#{alt.sub(/\A\s+/,"")})"
308
+ else "★#{word}☆"
309
+ end
310
+ end
311
+
312
+ def inline_chap(id)
313
+ #"「第#{super}章 #{inline_title(id)}」"
314
+ # "第#{super}章"
315
+ super
316
+ end
317
+
318
+ def compile_ruby(base, ruby)
319
+ "#{base}◆→DTP担当:「#{base}」に「#{ruby}」とルビ←◆"
320
+ end
321
+
322
+ def inline_bou(str)
323
+ "#{str}◆→DTP担当:「#{str}」に傍点←◆"
324
+ end
325
+
326
+ def inline_i(str)
327
+ "▲#{str}☆"
328
+ end
329
+
330
+ def inline_b(str)
331
+ "★#{str}☆"
332
+ end
333
+
334
+ def inline_tt(str)
335
+ "△#{str}☆"
336
+ end
337
+
338
+ def inline_ttbold(str)
339
+ "★#{str}☆◆→等幅フォント太字←◆"
340
+ end
341
+
342
+ def inline_tti(str)
343
+ "▲#{str}☆◆→等幅フォントイタ←◆"
344
+ end
345
+
346
+ def inline_ttibold(str)
347
+ "▲#{str}☆◆→等幅フォント太字イタ←◆"
348
+ end
349
+
350
+ def inline_u(str)
351
+ "@#{str}@◆→@〜@部分に下線←◆"
352
+ end
353
+
354
+ def inline_icon(id)
355
+ "◆→画像 #{@chapter.id}-#{id}.eps←◆"
356
+ end
357
+
358
+ def inline_ami(str)
359
+ "#{str}◆→DTP担当:「#{str}」に網カケ←◆"
360
+ end
361
+
362
+ def inline_sup(str)
363
+ "#{str}◆→DTP担当:「#{str}」は上付き←◆"
364
+ end
365
+
366
+ def inline_sub(str)
367
+ "#{str}◆→DTP担当:「#{str}」は下付き←◆"
368
+ end
369
+
370
+ def inline_raw(str)
371
+ # FIXME
372
+ str
373
+ end
374
+
375
+ def inline_hint(str)
376
+ "◆→ヒントスタイル←◆#{str}"
377
+ end
378
+
379
+ def inline_maru(str)
380
+ "#{str}◆→丸数字#{str}←◆"
381
+ end
382
+
383
+ def inline_idx(str)
384
+ "#{str}◆→索引項目:#{str}←◆"
385
+ end
386
+
387
+ def inline_hidx(str)
388
+ "◆→索引項目:#{str}←◆"
389
+ end
390
+
391
+ def inline_keytop(str)
392
+ "#{str}◆→キートップ#{str}←◆"
393
+ end
394
+
395
+ def inline_labelref(idref)
396
+ %Q(「◆→#{idref}←◆」) # 節、項を参照
397
+ end
398
+
399
+ alias inline_ref inline_labelref
400
+
401
+ def inline_pageref(idref)
402
+ %Q(●ページ◆→#{idref}←◆) # ページ番号を参照
403
+ end
404
+
405
+ def inline_balloon(str)
406
+ %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))})
407
+ end
408
+
409
+ def noindent
410
+ %Q(◆→インデントなし←◆)
411
+ end
412
+
413
+ def nonum_begin(level, label, caption)
414
+ puts "■H#{level}■#{caption}"
415
+ end
416
+
417
+ def nonum_end(level)
418
+ end
419
+
420
+ def circle_begin(level, label, caption)
421
+ puts "・\t#{caption}"
422
+ end
423
+
424
+ def circle_end(level)
425
+ end
426
+
427
+ def flushright(lines)
428
+ base_block "右寄せ", lines, nil
429
+ end
430
+
431
+ def note(lines, caption = nil)
432
+ base_block "ノート", lines, caption
433
+ end
434
+
435
+ def memo(lines, caption = nil)
436
+ base_block "メモ", lines, caption
437
+ end
438
+
439
+ def tip(lines, caption = nil)
440
+ base_block "TIP", lines, caption
441
+ end
442
+
443
+ def info(lines, caption = nil)
444
+ base_block "情報", lines, caption
445
+ end
446
+
447
+ def planning(lines, caption = nil)
448
+ base_block "プランニング", lines, caption
449
+ end
450
+
451
+ def best(lines, caption = nil)
452
+ base_block "ベストプラクティス", lines, caption
453
+ end
454
+
455
+ def important(lines, caption = nil)
456
+ base_block "重要", lines, caption
457
+ end
458
+
459
+ def security(lines, caption = nil)
460
+ base_block "セキュリティ", lines, caption
461
+ end
462
+
463
+ def caution(lines, caption = nil)
464
+ base_block "警告", lines, caption
465
+ end
466
+
467
+ def term(lines)
468
+ base_block "用語解説", lines, nil
469
+ end
470
+
471
+ def notice(lines, caption = nil)
472
+ base_block "注意", lines, caption
473
+ end
474
+
475
+ def point(lines, caption = nil)
476
+ base_block "ここがポイント", lines, caption
477
+ end
478
+
479
+ def reference(lines)
480
+ base_block "参考", lines, nil
481
+ end
482
+
483
+ def practice(lines)
484
+ base_block "練習問題", lines, nil
485
+ end
486
+
487
+ def expert(lines)
488
+ base_block "エキスパートに訊け", lines, nil
489
+ end
490
+
491
+ def insn(lines, caption = nil)
492
+ base_block "書式", lines, caption
493
+ end
494
+
495
+ alias box insn
496
+
497
+ def indepimage(id)
498
+ puts "◆→画像 #{@chapter.id}-#{id}.eps←◆"
499
+ end
500
+
501
+ def label(id)
502
+ # FIXME
503
+ ""
504
+ end
505
+
506
+ def tsize(id)
507
+ # FIXME
508
+ ""
509
+ end
510
+
511
+ def dtp(str)
512
+ # FIXME
513
+ end
514
+
515
+ def inline_dtp(str)
516
+ # FIXME
517
+ ""
518
+ end
519
+
520
+ def raw(str)
521
+ if str =~ /\A<\/(.+)>$/
522
+ case $1
523
+ when "emlist": puts "◆→終了:インラインリスト←◆"
524
+ when "cmd": puts "◆→終了:コマンド←◆"
525
+ when "quote": puts "◆→終了:引用←◆"
526
+ when "flushright": puts "◆→終了:右寄せ←◆"
527
+ when "note": puts "◆→終了:ノート←◆"
528
+ when "important": puts "◆→終了:重要←◆"
529
+ when "term": puts "◆→終了:用語解説←◆"
530
+ when "notice": puts "◆→終了:注意←◆"
531
+ when "point": puts "◆→終了:ここがポイント←◆"
532
+ when "reference": puts "◆→終了:参考←◆"
533
+ when "practice": puts "◆→終了:練習問題←◆"
534
+ when "expert": puts "◆→終了:エキスパートに訊け←◆"
535
+ when "box": puts "◆→終了:書式←◆"
536
+ when "insn": puts "◆→終了:書式←◆"
537
+ end
538
+ elsif str =~ /\A<([^\/].+)>(?:<title[^>]>(.+)<\/title>)?(.*)/
539
+ case $1
540
+ when "emlist": puts "◆→開始:インラインリスト←◆"
541
+ when "cmd": puts "◆→開始:コマンド←◆"
542
+ when "quote": puts "◆→開始:引用←◆"
543
+ when "flushright": puts "◆→開始:右寄せ←◆"
544
+ when "note": puts "◆→開始:ノート←◆"
545
+ when "important": puts "◆→開始:重要←◆"
546
+ when "term": puts "◆→開始:用語解説←◆"
547
+ when "notice": puts "◆→開始:注意←◆"
548
+ when "point": puts "◆→開始:ここがポイント←◆"
549
+ when "reference": puts "◆→開始:参考←◆"
550
+ when "practice": puts "◆→開始:練習問題←◆"
551
+ when "expert": puts "◆→開始:エキスパートに訊け←◆"
552
+ when "box": puts "◆→開始:書式←◆"
553
+ when "insn": puts "◆→開始:書式←◆"
554
+ end
555
+ puts "■#{$2}" unless $2.nil?
556
+ print $3
557
+ else
558
+ puts str
559
+ end
560
+ end
561
+
562
+ def text(str)
563
+ str
564
+ end
565
+
566
+ def nofunc_text(str)
567
+ str
568
+ end
569
+
570
+ end
571
+
572
+ end # module ReVIEW