review-peg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +605 -0
  5. data/.travis.yml +18 -0
  6. data/COPYING +515 -0
  7. data/ChangeLog +2449 -0
  8. data/Dockerfile +22 -0
  9. data/Gemfile +6 -0
  10. data/README.rdoc +81 -0
  11. data/Rakefile +51 -0
  12. data/bin/review-catalog-converter-peg +129 -0
  13. data/bin/review-check-peg +169 -0
  14. data/bin/review-checkdep-peg +63 -0
  15. data/bin/review-compile-peg +202 -0
  16. data/bin/review-epubmaker-legacy-peg +1024 -0
  17. data/bin/review-epubmaker-peg +44 -0
  18. data/bin/review-index-peg +110 -0
  19. data/bin/review-init-peg +151 -0
  20. data/bin/review-pdfmaker-peg +18 -0
  21. data/bin/review-preproc-peg +131 -0
  22. data/bin/review-validate-peg +51 -0
  23. data/bin/review-vol-peg +100 -0
  24. data/debian/README.Debian +12 -0
  25. data/debian/README.source +5 -0
  26. data/debian/changelog +5 -0
  27. data/debian/compat +1 -0
  28. data/debian/control +22 -0
  29. data/debian/copyright +62 -0
  30. data/debian/docs +6 -0
  31. data/debian/manpage.1.ex +59 -0
  32. data/debian/patches/path.diff +91 -0
  33. data/debian/patches/series +1 -0
  34. data/debian/review.install +13 -0
  35. data/debian/review.links +4 -0
  36. data/debian/rules +13 -0
  37. data/debian/source/format +1 -0
  38. data/doc/NEWS.ja.md +350 -0
  39. data/doc/NEWS.md +354 -0
  40. data/doc/catalog.ja.md +53 -0
  41. data/doc/catalog.md +52 -0
  42. data/doc/format.ja.md +734 -0
  43. data/doc/format.md +746 -0
  44. data/doc/format_idg.ja.md +203 -0
  45. data/doc/quickstart.ja.md +222 -0
  46. data/doc/quickstart.md +252 -0
  47. data/doc/ruby-uuid/README +11 -0
  48. data/doc/ruby-uuid/README.ja +34 -0
  49. data/doc/sample.css +108 -0
  50. data/doc/sample.yml +238 -0
  51. data/lib/epubmaker.rb +24 -0
  52. data/lib/epubmaker/content.rb +93 -0
  53. data/lib/epubmaker/epubcommon.rb +424 -0
  54. data/lib/epubmaker/epubv2.rb +139 -0
  55. data/lib/epubmaker/epubv3.rb +222 -0
  56. data/lib/epubmaker/producer.rb +330 -0
  57. data/lib/lineinput.rb +107 -0
  58. data/lib/review.rb +3 -0
  59. data/lib/review/book.rb +43 -0
  60. data/lib/review/book/base.rb +401 -0
  61. data/lib/review/book/chapter.rb +100 -0
  62. data/lib/review/book/compilable.rb +184 -0
  63. data/lib/review/book/image_finder.rb +71 -0
  64. data/lib/review/book/index.rb +413 -0
  65. data/lib/review/book/page_metric.rb +47 -0
  66. data/lib/review/book/part.rb +54 -0
  67. data/lib/review/book/volume.rb +67 -0
  68. data/lib/review/builder.rb +452 -0
  69. data/lib/review/catalog.rb +52 -0
  70. data/lib/review/compiler.rb +5183 -0
  71. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  72. data/lib/review/compiler/literals_1_9.rb +435 -0
  73. data/lib/review/configure.rb +64 -0
  74. data/lib/review/epubbuilder.rb +18 -0
  75. data/lib/review/epubmaker.rb +480 -0
  76. data/lib/review/ewbbuilder.rb +381 -0
  77. data/lib/review/exception.rb +21 -0
  78. data/lib/review/extentions.rb +4 -0
  79. data/lib/review/extentions/array.rb +25 -0
  80. data/lib/review/extentions/object.rb +9 -0
  81. data/lib/review/extentions/string.rb +33 -0
  82. data/lib/review/htmlbuilder.rb +1166 -0
  83. data/lib/review/htmllayout.rb +41 -0
  84. data/lib/review/htmltoc.rb +45 -0
  85. data/lib/review/htmlutils.rb +90 -0
  86. data/lib/review/i18n.rb +96 -0
  87. data/lib/review/i18n.yml +169 -0
  88. data/lib/review/idgxmlbuilder.rb +1233 -0
  89. data/lib/review/inaobuilder.rb +357 -0
  90. data/lib/review/latexbuilder.rb +941 -0
  91. data/lib/review/latexindex.rb +35 -0
  92. data/lib/review/latexutils.rb +95 -0
  93. data/lib/review/layout.tex.erb +340 -0
  94. data/lib/review/lineinput.rb +17 -0
  95. data/lib/review/location.rb +24 -0
  96. data/lib/review/makerhelper.rb +67 -0
  97. data/lib/review/markdownbuilder.rb +339 -0
  98. data/lib/review/node.rb +288 -0
  99. data/lib/review/pdfmaker.rb +332 -0
  100. data/lib/review/preprocessor.rb +530 -0
  101. data/lib/review/review.kpeg +745 -0
  102. data/lib/review/sec_counter.rb +69 -0
  103. data/lib/review/template.rb +21 -0
  104. data/lib/review/textbuilder.rb +17 -0
  105. data/lib/review/textutils.rb +16 -0
  106. data/lib/review/tocparser.rb +348 -0
  107. data/lib/review/tocprinter.rb +205 -0
  108. data/lib/review/topbuilder.rb +796 -0
  109. data/lib/review/unfold.rb +138 -0
  110. data/lib/review/version.rb +3 -0
  111. data/lib/uuid.rb +312 -0
  112. data/review.gemspec +32 -0
  113. data/templates/html/layout-html5.html.erb +17 -0
  114. data/templates/html/layout-xhtml1.html.erb +20 -0
  115. data/templates/ncx/epubv2.ncx.erb +11 -0
  116. data/templates/opf/epubv2.opf.erb +21 -0
  117. data/templates/opf/epubv3.opf.erb +18 -0
  118. data/templates/xml/container.xml.erb +6 -0
  119. data/test/CHAPS +2 -0
  120. data/test/assets/test.xml.erb +3 -0
  121. data/test/assets/test_template.tex +255 -0
  122. data/test/assets/test_template_backmatter.tex +32 -0
  123. data/test/bib.re +13 -0
  124. data/test/book_test_helper.rb +35 -0
  125. data/test/sample-book/README.md +7 -0
  126. data/test/sample-book/src/Rakefile +58 -0
  127. data/test/sample-book/src/_cover.html +3 -0
  128. data/test/sample-book/src/catalog.yml +10 -0
  129. data/test/sample-book/src/ch01.re +71 -0
  130. data/test/sample-book/src/ch02.re +3 -0
  131. data/test/sample-book/src/config.yml +186 -0
  132. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  133. data/test/sample-book/src/images/cover.jpg +0 -0
  134. data/test/sample-book/src/preface.re +15 -0
  135. data/test/sample-book/src/sty/jumoline.sty +310 -0
  136. data/test/sample-book/src/sty/reviewmacro.sty +39 -0
  137. data/test/sample-book/src/style.css +251 -0
  138. data/test/sample-book/src/vendor/jumoline/README +29 -0
  139. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  140. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  141. data/test/test.re +43 -0
  142. data/test/test_book.rb +556 -0
  143. data/test/test_book_chapter.rb +280 -0
  144. data/test/test_book_part.rb +54 -0
  145. data/test/test_builder.rb +80 -0
  146. data/test/test_catalog.rb +119 -0
  147. data/test/test_catalog_converter_cmd.rb +73 -0
  148. data/test/test_compiler.rb +92 -0
  149. data/test/test_configure.rb +50 -0
  150. data/test/test_epub3maker.rb +529 -0
  151. data/test/test_epubmaker.rb +569 -0
  152. data/test/test_epubmaker_cmd.rb +40 -0
  153. data/test/test_helper.rb +92 -0
  154. data/test/test_htmlbuilder.rb +1114 -0
  155. data/test/test_htmltoc.rb +32 -0
  156. data/test/test_htmlutils.rb +50 -0
  157. data/test/test_i18n.rb +180 -0
  158. data/test/test_idgxmlbuilder.rb +608 -0
  159. data/test/test_image_finder.rb +82 -0
  160. data/test/test_inaobuilder.rb +245 -0
  161. data/test/test_index.rb +174 -0
  162. data/test/test_latexbuilder.rb +732 -0
  163. data/test/test_lineinput.rb +182 -0
  164. data/test/test_makerhelper.rb +66 -0
  165. data/test/test_markdownbuilder.rb +125 -0
  166. data/test/test_pdfmaker.rb +171 -0
  167. data/test/test_pdfmaker_cmd.rb +40 -0
  168. data/test/test_preprocessor.rb +23 -0
  169. data/test/test_review_ext.rb +31 -0
  170. data/test/test_template.rb +26 -0
  171. data/test/test_textutils.rb +32 -0
  172. data/test/test_topbuilder.rb +291 -0
  173. data/test/test_uuid.rb +157 -0
  174. metadata +357 -0
@@ -0,0 +1,381 @@
1
+ # -*- coding: utf-8 -*-
2
+ # $Id: ewbbuilder.rb 2195 2005-11-13 21:52:18Z aamine $
3
+
4
+ require 'review/builder'
5
+ require 'review/textutils'
6
+ require 'review/exception'
7
+
8
+ module ReVIEW
9
+ class EWBBuilder < Builder
10
+ include TextUtils
11
+
12
+ def initialize(chap)
13
+ super
14
+ @footnote_buf = []
15
+ @index_buffer = []
16
+ end
17
+
18
+ def generate_index
19
+ @index_buffer.each_with_index do |str, n|
20
+ printf "%d\t%s\n", index_number(n + 1), str
21
+ end
22
+ end
23
+
24
+ def headline(level, caption)
25
+ puts unless level == 1
26
+ puts "//#{'i' * level} #{caption}"
27
+ puts
28
+ end
29
+
30
+ # Compiler.defsyntax(:emlist, :block, 0..1) {|args|
31
+ # if args[0] and not args[0] == 'noescape'
32
+ # raise SyntaxError, "unknown //emlist option: #{args[0]}"
33
+ # end
34
+ # }
35
+
36
+ def emlist(lines, caption = nil)
37
+ firstline = f.lineno
38
+ puts
39
+ puts caption
40
+ puts '//lst1'
41
+ lines.each do |line|
42
+ if noescape
43
+ puts detab(line)
44
+ else
45
+ puts escape(detab(line))
46
+ end
47
+ end
48
+ puts '//}'
49
+ puts
50
+ end
51
+
52
+ # Compiler.defsyntax(:cmd, :block, 0..1) {|args|
53
+ # if args[0] and not args[0] == 'noescape'
54
+ # raise SyntaxError, "unknown //cmd option: #{args[0]}"
55
+ # end
56
+ # }
57
+
58
+ def cmd(lines, caption = nil)
59
+ puts
60
+ puts caption
61
+ puts '//sc1{'
62
+ lines.each do |line|
63
+ if noescape
64
+ puts detab(line)
65
+ elsif /\AC:.*?>(.+)/ =~ line # DOS prompt hack
66
+ prompt, cmd = *line.split('>', 2)
67
+ puts "#{escape(prompt)}>//command{#{escape(cmd)}}//}"
68
+ else
69
+ puts escape(detab(line))
70
+ end
71
+ end
72
+ puts '//}'
73
+ puts
74
+ end
75
+
76
+ # Compiler.defsyntax(:list, :block, 0..1) {|args|
77
+ # if args[0] and not args[0] == 'noescape'
78
+ # raise SyntaxError, "unknown //list option: #{args[0]}"
79
+ # end
80
+ # }
81
+
82
+ def list(lines, id, caption)
83
+ puts
84
+ puts "//l#{list_number(id)} " + caption
85
+ puts '//lst2{'
86
+ lines.each do |line|
87
+ puts escape(detab(line))
88
+ end
89
+ puts '//}'
90
+ puts
91
+ end
92
+
93
+ def image_header(file, caption)
94
+ if /\.png\z/ =~ file and not FileTest.exist?('images/' + file)
95
+ warn "image file not exist: #{file}"
96
+ end
97
+ id = file.sub(/\.\w+\z/, '')
98
+ puts "//f#{figure_number(id)} #{text(caption)} file=#{file}" if id
99
+ end
100
+
101
+ def image_dummy
102
+ puts '//lst1{'
103
+ puts '---- dummy figure ----'
104
+ print dummy
105
+ puts '//}'
106
+ puts
107
+ end
108
+
109
+ def table
110
+ # %r<\A//table\[(\w+)\]>
111
+ spec = $1
112
+ buf = []
113
+ while line = f.gets
114
+ break if %r[\A//\}] === line
115
+ buf.push line.strip.split(/\t+/).map {|s| s == '.' ? '' : s }
116
+ end
117
+ table_type = 'tabm'
118
+ output.puts "//#{table_type}[" + spec + ']{'
119
+ buf.each_with_index do |col, idx|
120
+ if /----/ === col[0]
121
+ output.puts '//kb'
122
+ else
123
+ output.puts col.map {|s| text(s) }.join("\t")
124
+ end
125
+ end
126
+ output.puts '//}'
127
+ end
128
+
129
+ LI = '●'
130
+
131
+ def ul_begin
132
+ puts
133
+ puts '//k1{'
134
+ end
135
+
136
+ def ul_item(lines)
137
+ puts "#{LI}//|" + lines.join('')
138
+ end
139
+
140
+ def ul_end
141
+ puts '//}'
142
+ end
143
+
144
+ def ol_begin
145
+ output.puts
146
+ output.puts '//k2{'
147
+ end
148
+
149
+ def ol_item(num, lines)
150
+ print "#{num}//|" + lines.join('')
151
+ end
152
+
153
+ def ol_end
154
+ puts '//}'
155
+ end
156
+
157
+ def quote(lines)
158
+ puts '//c1{'
159
+ lines.each do |line|
160
+ puts text(line)
161
+ end
162
+ puts '//}'
163
+ end
164
+
165
+ def vspace
166
+ print %Q(
167
+ //h)
168
+ end
169
+
170
+ def noindent
171
+ @noindent = true
172
+ end
173
+
174
+ def refer(f)
175
+ puts
176
+ puts '//refer{'
177
+ cascade f
178
+ puts '//}'
179
+ end
180
+
181
+ def point(f)
182
+ puts
183
+ puts '//point{'
184
+ cascade f
185
+ puts '//}'
186
+ end
187
+
188
+ def note(f, caption)
189
+ puts
190
+ puts '//note{'
191
+ puts "//cg{#{caption}//}"
192
+ puts '//h'
193
+ cascade f
194
+ puts '//}'
195
+ end
196
+
197
+ def cascade(f)
198
+ # FIXME
199
+ end
200
+
201
+ Z_SPACE = "\241\241" # zen-kaku space in EUC-JP
202
+
203
+ def paragraph(lines)
204
+ if @noindent
205
+ @noindent = false
206
+ else
207
+ print Z_SPACE
208
+ end
209
+ prev = ''
210
+ lines.each do |line|
211
+ if /[a-zA-Z0-9]\z/ =~ prev and /\A[a-zA-Z0-9]/ =~ line
212
+ print ' '
213
+ end
214
+ print line
215
+ end
216
+ puts
217
+ end
218
+
219
+ def figure_filename(key)
220
+ if ext = key.slice(/\.\w+\z/)
221
+ base = key.sub(/\.\w+\z/, '')
222
+ else
223
+ base = key
224
+ ext = '.eps'
225
+ end
226
+ currname = "images/ch_#{chapter_id}_#{base}#{ext}"
227
+ destname = "images/fig#{figure_number(base)}#{ext}"
228
+ unless File.exist? currname
229
+ # error "image file not exist: #{currname}"
230
+ end
231
+ destname
232
+ end
233
+
234
+ def image_label(str)
235
+ "#{chapter_id}:#{str}"
236
+ end
237
+
238
+ def text(str)
239
+ str = str.gsub(/\t/, ' ')
240
+ str.gsub(/([^@^]+)|\^(.*?)\^|@<(\w+)>\{(.*?)\}|@\{(.*?)\}|([@^])/) do
241
+ if normal = $1
242
+ escape(normal)
243
+ elsif tt = $2
244
+ '//tt{' + escape(tt) + '//}'
245
+ elsif inline = $3
246
+ compile_inline(inline, $4)
247
+ elsif index = $5
248
+ error 'index not implemented'
249
+ text(index) + index_command(index)
250
+ elsif char = $6
251
+ escape(char)
252
+ else
253
+ error "unknown inline: #{str.inspect}"
254
+ end
255
+ end
256
+ rescue DocumentError => e
257
+ error e.message
258
+ return 'ERROR'
259
+ end
260
+
261
+ def inline_kw(arg)
262
+ word, eng, abbr = arg.split(/,/).map {|s| s.strip }
263
+ if abbr
264
+ add_index(word) + "//g{#{word}//}" +
265
+ add_index(abbr) + "(#{abbr}, " +
266
+ add_index(eng) + "#{eng})"
267
+ elsif eng
268
+ add_index(word) + "//g{#{word}//}" +
269
+ add_index(eng) + "(#{eng})"
270
+ else
271
+ add_index(word) + "//g{#{word}//}"
272
+ end
273
+ end
274
+
275
+ def inline_keytop(arg)
276
+ "//keytop{#{arg}//}"
277
+ end
278
+
279
+ def inline_chap(id)
280
+ chapter_number(arg)
281
+ end
282
+
283
+ def inline_chapref(id)
284
+ chapter_number(arg) + chapter_name(arg)
285
+ end
286
+
287
+ def inline_chapname(id)
288
+ chapter_name(arg)
289
+ end
290
+
291
+ def inline_list(arg)
292
+ '//l' + list_number(arg)
293
+ end
294
+
295
+ def inline_img(arg)
296
+ error "wrong image label: #{arg}" if /[^a-zA-Z\d\-]/ =~ arg
297
+ '//f' + figure_number(arg)
298
+ end
299
+
300
+ def inline_footnote(id)
301
+ '//ky' + footnote_number(id)
302
+ end
303
+
304
+ def inline_ruby(arg)
305
+ error 'wrong number of arg: @<ruby>' unless arg.count(',') == 1
306
+ "//ruby{#{arg}//}"
307
+ end
308
+
309
+ NAKAGURO = '・'
310
+
311
+ def inline_bou(str)
312
+ "//ruby{#{escape(str)},#{NAKAGURO * char_length(str)}//}"
313
+ end
314
+
315
+ def char_length(str)
316
+ str.gsub(/./, '.').length
317
+ end
318
+
319
+ def inline_em(str)
320
+ "//g{#{arg}//}"
321
+ end
322
+
323
+ def inline_math(arg)
324
+ "//LaTeX{ $#{arg}$ //}"
325
+ end
326
+
327
+ def chapter_id
328
+ File.basename(@filename, '.rd')
329
+ end
330
+
331
+ def chapter_prefix
332
+ sprintf('%02d', @chapter_table.number(chapter_id))
333
+ end
334
+
335
+ def chapter_number(key)
336
+ curr = @chapter_table.number(chapter_id)
337
+ dest = @chapter_table.number(key)
338
+
339
+ case chapter_id
340
+ when /\.ewb\z/, 'tmp', 'temp'
341
+ return '第' + dest + '章'
342
+ end
343
+ if dest == curr + 1
344
+ '次章'
345
+ elsif dest == curr - 1
346
+ '前章'
347
+ else
348
+ "第#{dest}章"
349
+ end
350
+ end
351
+
352
+ def chapter_name(key)
353
+ '『' + text(@chapter_table.title(key)) + '』'
354
+ end
355
+
356
+ def list_number(key)
357
+ sprintf(chapter_prefix + '%02d0', @list_table.number(key))
358
+ end
359
+
360
+ def figure_number(key)
361
+ sprintf(chapter_prefix + '%02d0', @figure_table.number(key))
362
+ end
363
+
364
+ def footnote_number(key)
365
+ sprintf('%02d', @footnote_index.number(key) * 5)
366
+ end
367
+
368
+ def add_index(str)
369
+ @index_buffer.push str
370
+ "//in#{index_number(@index_buffer.size)}"
371
+ end
372
+
373
+ def index_number(n)
374
+ 900_000 + @chapter_index.number(chapter_id) * 1000 + n
375
+ end
376
+
377
+ def escape(str)
378
+ str.gsub(%r{//}, '////')
379
+ end
380
+ end
381
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # $Id: exception.rb 3881 2008-02-09 14:44:17Z 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
+
12
+ module ReVIEW
13
+
14
+ class Error < ::StandardError; end
15
+ class ApplicationError < Error; end
16
+ class ConfigError < ApplicationError; end
17
+ class CompileError < ApplicationError; end
18
+ class SyntaxError < CompileError; end
19
+ class FileNotFound < ApplicationError; end
20
+ class KeyError < CompileError; end
21
+ end
@@ -0,0 +1,4 @@
1
+ require 'review/extentions/object'
2
+ require 'review/extentions/string'
3
+ require 'review/extentions/array'
4
+
@@ -0,0 +1,25 @@
1
+ class Array
2
+
3
+ # for ReVIEW::Node
4
+ #
5
+ def to_doc
6
+ self.map(&:to_doc).join("")
7
+ end
8
+
9
+ # for ReVIEW::Node
10
+ #
11
+ def to_raw
12
+ self.map(&:to_raw).join("")
13
+ end
14
+
15
+ if [].map.kind_of?(Array)
16
+ # Ruby 1.8
17
+ def map(&block)
18
+ if !block_given?
19
+ return to_enum :map
20
+ else
21
+ collect(&block) ## XXX same as original
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? empty? : !self
4
+ end
5
+
6
+ def present?
7
+ !blank?
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ if defined?(Encoding) && Encoding.respond_to?("default_external")
2
+ Encoding.default_external = "UTF-8"
3
+ end
4
+
5
+ unless String.method_defined?(:lines)
6
+ # Ruby 1.8
7
+ class String
8
+ alias_method :lines, :to_a
9
+ end
10
+ end
11
+
12
+ if String.method_defined?(:bytesize)
13
+ # Ruby 1.9
14
+ class String
15
+ alias_method :charsize, :size
16
+ end
17
+ else
18
+ # Ruby 1.8
19
+ class String
20
+ alias_method :bytesize, :size
21
+
22
+ def charsize
23
+ split(//).size
24
+ end
25
+ end
26
+ end
27
+
28
+ unless String.method_defined?(:each)
29
+ # Ruby 1.9
30
+ class String
31
+ alias_method :each, :each_line
32
+ end
33
+ end