review 2.0.0.beta1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -1
  3. data/.rubocop_todo.yml +617 -0
  4. data/.travis.yml +16 -1
  5. data/ChangeLog +48 -0
  6. data/Dockerfile +22 -0
  7. data/Gemfile +0 -1
  8. data/README.md +97 -0
  9. data/Rakefile +10 -11
  10. data/appveyor.yml +9 -0
  11. data/bin/review +46 -0
  12. data/bin/review-check +8 -21
  13. data/bin/review-compile +26 -43
  14. data/bin/review-index +9 -22
  15. data/bin/review-init +21 -25
  16. data/bin/review-preproc +9 -13
  17. data/bin/review-validate +1 -1
  18. data/bin/review-vol +3 -17
  19. data/bin/review-webmaker +15 -0
  20. data/doc/NEWS.ja.md +534 -0
  21. data/doc/NEWS.md +538 -0
  22. data/doc/catalog.ja.md +10 -18
  23. data/doc/catalog.md +5 -9
  24. data/doc/config.yml.sample +319 -0
  25. data/doc/customize_epub.ja.md +42 -0
  26. data/doc/format.ja.md +320 -288
  27. data/doc/format.md +277 -170
  28. data/doc/format_idg.ja.md +82 -175
  29. data/doc/pdfmaker.ja.md +61 -0
  30. data/doc/pdfmaker.md +65 -0
  31. data/doc/quickstart.ja.md +88 -98
  32. data/doc/quickstart.md +72 -110
  33. data/doc/sample.css +41 -0
  34. data/doc/writing_vertical.ja.md +55 -0
  35. data/doc/writing_vertical.md +5 -0
  36. data/lib/epubmaker/content.rb +3 -3
  37. data/lib/epubmaker/epubcommon.rb +173 -145
  38. data/lib/epubmaker/epubv2.rb +24 -77
  39. data/lib/epubmaker/epubv3.rb +72 -73
  40. data/lib/epubmaker/producer.rb +54 -30
  41. data/lib/lineinput.rb +48 -0
  42. data/lib/review/book.rb +0 -1
  43. data/lib/review/book/base.rb +47 -27
  44. data/lib/review/book/chapter.rb +48 -19
  45. data/lib/review/book/compilable.rb +10 -14
  46. data/lib/review/book/index.rb +10 -19
  47. data/lib/review/book/page_metric.rb +0 -10
  48. data/lib/review/book/part.rb +17 -3
  49. data/lib/review/builder.rb +84 -68
  50. data/lib/review/catalog.rb +5 -1
  51. data/lib/review/compiler.rb +327 -4657
  52. data/lib/review/configure.rb +84 -10
  53. data/lib/review/converter.rb +28 -0
  54. data/lib/review/epubbuilder.rb +1 -1
  55. data/lib/review/epubmaker.rb +142 -158
  56. data/lib/review/ewbbuilder.rb +5 -5
  57. data/lib/review/exception.rb +1 -1
  58. data/lib/review/extentions.rb +1 -1
  59. data/lib/review/extentions/hash.rb +15 -0
  60. data/lib/review/extentions/string.rb +2 -1
  61. data/lib/review/htmlbuilder.rb +364 -348
  62. data/lib/review/htmltoc.rb +44 -0
  63. data/lib/review/htmlutils.rb +12 -6
  64. data/lib/review/i18n.rb +78 -6
  65. data/lib/review/i18n.yml +7 -4
  66. data/lib/review/idgxmlbuilder.rb +226 -267
  67. data/lib/review/latexbuilder.rb +281 -274
  68. data/lib/review/latexutils.rb +56 -49
  69. data/lib/review/makerhelper.rb +8 -4
  70. data/lib/review/markdownbuilder.rb +80 -124
  71. data/lib/review/pdfmaker.rb +197 -138
  72. data/lib/review/preprocessor.rb +16 -67
  73. data/lib/review/template.rb +24 -0
  74. data/lib/review/textbuilder.rb +1 -1
  75. data/lib/review/textutils.rb +18 -24
  76. data/lib/review/tocparser.rb +51 -106
  77. data/lib/review/tocprinter.rb +61 -117
  78. data/lib/review/topbuilder.rb +119 -126
  79. data/lib/review/unfold.rb +2 -2
  80. data/lib/review/version.rb +1 -1
  81. data/lib/review/webmaker.rb +302 -0
  82. data/lib/review/webtocprinter.rb +48 -0
  83. data/lib/review/yamlloader.rb +47 -0
  84. data/review.gemspec +3 -3
  85. data/templates/html/layout-html5.html.erb +17 -0
  86. data/templates/html/layout-xhtml1.html.erb +20 -0
  87. data/{lib/review → templates/latex}/layout.tex.erb +107 -115
  88. data/templates/ncx/epubv2.ncx.erb +11 -0
  89. data/templates/opf/epubv2.opf.erb +21 -0
  90. data/templates/opf/epubv3.opf.erb +18 -0
  91. data/templates/web/html/layout-html5.html.erb +56 -0
  92. data/templates/web/html/layout-xhtml1.html.erb +20 -0
  93. data/templates/xml/container.xml.erb +6 -0
  94. data/test/assets/test.xml.erb +3 -0
  95. data/test/assets/test_template.tex +28 -71
  96. data/test/assets/test_template_backmatter.tex +1 -9
  97. data/test/sample-book/src/Rakefile +12 -3
  98. data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
  99. data/test/sample-book/src/config.yml +40 -154
  100. data/test/sample-book/src/style-web.css +45 -0
  101. data/test/sample-book/src/style.css +23 -1
  102. data/test/test.re +1 -1
  103. data/test/test_book.rb +15 -17
  104. data/test/test_book_chapter.rb +2 -80
  105. data/test/test_book_part.rb +1 -1
  106. data/test/test_builder.rb +28 -6
  107. data/test/test_catalog.rb +17 -0
  108. data/test/test_compiler.rb +14 -59
  109. data/test/test_configure.rb +94 -0
  110. data/test/test_converter.rb +21 -0
  111. data/test/test_epub3maker.rb +155 -3
  112. data/test/test_epubmaker.rb +245 -30
  113. data/test/test_epubmaker_cmd.rb +2 -2
  114. data/test/test_extentions_hash.rb +60 -0
  115. data/test/test_helper.rb +4 -47
  116. data/test/test_htmlbuilder.rb +282 -175
  117. data/test/test_htmltoc.rb +33 -0
  118. data/test/test_i18n.rb +134 -70
  119. data/test/test_idgxmlbuilder.rb +58 -39
  120. data/test/test_latexbuilder.rb +132 -14
  121. data/test/test_lineinput.rb +5 -26
  122. data/test/test_makerhelper.rb +6 -4
  123. data/test/test_markdownbuilder.rb +23 -5
  124. data/test/test_pdfmaker.rb +86 -20
  125. data/test/test_pdfmaker_cmd.rb +1 -3
  126. data/test/test_review_ext.rb +1 -1
  127. data/test/test_template.rb +27 -0
  128. data/test/test_textutils.rb +36 -0
  129. data/test/test_tocparser.rb +25 -0
  130. data/test/test_topbuilder.rb +34 -2
  131. data/test/test_yamlloader.rb +188 -0
  132. metadata +71 -29
  133. data/README.rdoc +0 -81
  134. data/bin/review-epubmaker-legacy +0 -1024
  135. data/doc/ruby-uuid/README +0 -11
  136. data/doc/ruby-uuid/README.ja +0 -34
  137. data/lib/review/compiler/literals_1_8.kpeg +0 -19
  138. data/lib/review/compiler/literals_1_8.rb +0 -432
  139. data/lib/review/compiler/literals_1_9.kpeg +0 -22
  140. data/lib/review/compiler/literals_1_9.rb +0 -435
  141. data/lib/review/extentions/array.rb +0 -25
  142. data/lib/review/htmllayout.rb +0 -41
  143. data/lib/review/inaobuilder.rb +0 -357
  144. data/lib/review/location.rb +0 -24
  145. data/lib/review/node.rb +0 -267
  146. data/lib/review/review.kpeg +0 -724
  147. data/lib/uuid.rb +0 -312
  148. data/rubocop-todo.yml +0 -456
  149. data/test/test_inaobuilder.rb +0 -247
  150. data/test/test_uuid.rb +0 -157
@@ -1,22 +0,0 @@
1
- %% name = ReVIEW::Compiler::Literals
2
-
3
- %% header {
4
- # coding: UTF-8
5
-
6
- ##
7
- #--
8
- # This set of literals is for Ruby 1.9 regular expressions and gives full
9
- # unicode support.
10
- #
11
- # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
12
- # characters, newlines and spaces.
13
- }
14
-
15
- Alphanumeric = /\p{Word}/
16
- AlphanumericAscii = /[A-Za-z0-9]/
17
- LowerAlphabetAscii = /[a-z]/
18
- Digit = /[0-9]/
19
- BOM = "\uFEFF"
20
- Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
21
- NonAlphanumeric = /\p{^Word}/
22
- Spacechar = /\t|\p{Zs}/
@@ -1,435 +0,0 @@
1
- # coding: UTF-8
2
-
3
- ##
4
- #--
5
- # This set of literals is for Ruby 1.9 regular expressions and gives full
6
- # unicode support.
7
- #
8
- # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
9
- # characters, newlines and spaces.
10
- class ReVIEW::Compiler::Literals
11
- # :stopdoc:
12
-
13
- # This is distinct from setup_parser so that a standalone parser
14
- # can redefine #initialize and still have access to the proper
15
- # parser setup code.
16
- def initialize(str, debug=false)
17
- setup_parser(str, debug)
18
- end
19
-
20
-
21
-
22
- # Prepares for parsing +str+. If you define a custom initialize you must
23
- # call this method before #parse
24
- def setup_parser(str, debug=false)
25
- set_string str, 0
26
- @memoizations = Hash.new { |h,k| h[k] = {} }
27
- @result = nil
28
- @failed_rule = nil
29
- @failing_rule_offset = -1
30
-
31
- setup_foreign_grammar
32
- end
33
-
34
- attr_reader :string
35
- attr_reader :failing_rule_offset
36
- attr_accessor :result, :pos
37
-
38
- def current_column(target=pos)
39
- if c = string.rindex("\n", target-1)
40
- return target - c - 1
41
- end
42
-
43
- target + 1
44
- end
45
-
46
- def current_line(target=pos)
47
- cur_offset = 0
48
- cur_line = 0
49
-
50
- string.each_line do |line|
51
- cur_line += 1
52
- cur_offset += line.size
53
- return cur_line if cur_offset >= target
54
- end
55
-
56
- -1
57
- end
58
-
59
- def lines
60
- lines = []
61
- string.each_line { |l| lines << l }
62
- lines
63
- end
64
-
65
-
66
-
67
- def get_text(start)
68
- @string[start..@pos-1]
69
- end
70
-
71
- # Sets the string and current parsing position for the parser.
72
- def set_string string, pos
73
- @string = string
74
- @string_size = string ? string.size : 0
75
- @pos = pos
76
- end
77
-
78
- def show_pos
79
- width = 10
80
- if @pos < width
81
- "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
82
- else
83
- "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
84
- end
85
- end
86
-
87
- def failure_info
88
- l = current_line @failing_rule_offset
89
- c = current_column @failing_rule_offset
90
-
91
- if @failed_rule.kind_of? Symbol
92
- info = self.class::Rules[@failed_rule]
93
- "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
94
- else
95
- "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
96
- end
97
- end
98
-
99
- def failure_caret
100
- l = current_line @failing_rule_offset
101
- c = current_column @failing_rule_offset
102
-
103
- line = lines[l-1]
104
- "#{line}\n#{' ' * (c - 1)}^"
105
- end
106
-
107
- def failure_character
108
- l = current_line @failing_rule_offset
109
- c = current_column @failing_rule_offset
110
- lines[l-1][c-1, 1]
111
- end
112
-
113
- def failure_oneline
114
- l = current_line @failing_rule_offset
115
- c = current_column @failing_rule_offset
116
-
117
- char = lines[l-1][c-1, 1]
118
-
119
- if @failed_rule.kind_of? Symbol
120
- info = self.class::Rules[@failed_rule]
121
- "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
122
- else
123
- "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
124
- end
125
- end
126
-
127
- class ParseError < RuntimeError
128
- end
129
-
130
- def raise_error
131
- raise ParseError, failure_oneline
132
- end
133
-
134
- def show_error(io=STDOUT)
135
- error_pos = @failing_rule_offset
136
- line_no = current_line(error_pos)
137
- col_no = current_column(error_pos)
138
-
139
- io.puts "On line #{line_no}, column #{col_no}:"
140
-
141
- if @failed_rule.kind_of? Symbol
142
- info = self.class::Rules[@failed_rule]
143
- io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
144
- else
145
- io.puts "Failed to match rule '#{@failed_rule}'"
146
- end
147
-
148
- io.puts "Got: #{string[error_pos,1].inspect}"
149
- line = lines[line_no-1]
150
- io.puts "=> #{line}"
151
- io.print(" " * (col_no + 3))
152
- io.puts "^"
153
- end
154
-
155
- def set_failed_rule(name)
156
- if @pos > @failing_rule_offset
157
- @failed_rule = name
158
- @failing_rule_offset = @pos
159
- end
160
- end
161
-
162
- attr_reader :failed_rule
163
-
164
- def match_string(str)
165
- len = str.size
166
- if @string[pos,len] == str
167
- @pos += len
168
- return str
169
- end
170
-
171
- return nil
172
- end
173
-
174
- def scan(reg)
175
- if m = reg.match(@string[@pos..-1])
176
- width = m.end(0)
177
- @pos += width
178
- return true
179
- end
180
-
181
- return nil
182
- end
183
-
184
- if "".respond_to? :ord
185
- def get_byte
186
- if @pos >= @string_size
187
- return nil
188
- end
189
-
190
- s = @string[@pos].ord
191
- @pos += 1
192
- s
193
- end
194
- else
195
- def get_byte
196
- if @pos >= @string_size
197
- return nil
198
- end
199
-
200
- s = @string[@pos]
201
- @pos += 1
202
- s
203
- end
204
- end
205
-
206
- def parse(rule=nil)
207
- # We invoke the rules indirectly via apply
208
- # instead of by just calling them as methods because
209
- # if the rules use left recursion, apply needs to
210
- # manage that.
211
-
212
- if !rule
213
- apply(:_root)
214
- else
215
- method = rule.gsub("-","_hyphen_")
216
- apply :"_#{method}"
217
- end
218
- end
219
-
220
- class MemoEntry
221
- def initialize(ans, pos)
222
- @ans = ans
223
- @pos = pos
224
- @result = nil
225
- @set = false
226
- @left_rec = false
227
- end
228
-
229
- attr_reader :ans, :pos, :result, :set
230
- attr_accessor :left_rec
231
-
232
- def move!(ans, pos, result)
233
- @ans = ans
234
- @pos = pos
235
- @result = result
236
- @set = true
237
- @left_rec = false
238
- end
239
- end
240
-
241
- def external_invoke(other, rule, *args)
242
- old_pos = @pos
243
- old_string = @string
244
-
245
- set_string other.string, other.pos
246
-
247
- begin
248
- if val = __send__(rule, *args)
249
- other.pos = @pos
250
- other.result = @result
251
- else
252
- other.set_failed_rule "#{self.class}##{rule}"
253
- end
254
- val
255
- ensure
256
- set_string old_string, old_pos
257
- end
258
- end
259
-
260
- def apply_with_args(rule, *args)
261
- memo_key = [rule, args]
262
- if m = @memoizations[memo_key][@pos]
263
- @pos = m.pos
264
- if !m.set
265
- m.left_rec = true
266
- return nil
267
- end
268
-
269
- @result = m.result
270
-
271
- return m.ans
272
- else
273
- m = MemoEntry.new(nil, @pos)
274
- @memoizations[memo_key][@pos] = m
275
- start_pos = @pos
276
-
277
- ans = __send__ rule, *args
278
-
279
- lr = m.left_rec
280
-
281
- m.move! ans, @pos, @result
282
-
283
- # Don't bother trying to grow the left recursion
284
- # if it's failing straight away (thus there is no seed)
285
- if ans and lr
286
- return grow_lr(rule, args, start_pos, m)
287
- else
288
- return ans
289
- end
290
-
291
- return ans
292
- end
293
- end
294
-
295
- def apply(rule)
296
- if m = @memoizations[rule][@pos]
297
- @pos = m.pos
298
- if !m.set
299
- m.left_rec = true
300
- return nil
301
- end
302
-
303
- @result = m.result
304
-
305
- return m.ans
306
- else
307
- m = MemoEntry.new(nil, @pos)
308
- @memoizations[rule][@pos] = m
309
- start_pos = @pos
310
-
311
- ans = __send__ rule
312
-
313
- lr = m.left_rec
314
-
315
- m.move! ans, @pos, @result
316
-
317
- # Don't bother trying to grow the left recursion
318
- # if it's failing straight away (thus there is no seed)
319
- if ans and lr
320
- return grow_lr(rule, nil, start_pos, m)
321
- else
322
- return ans
323
- end
324
-
325
- return ans
326
- end
327
- end
328
-
329
- def grow_lr(rule, args, start_pos, m)
330
- while true
331
- @pos = start_pos
332
- @result = m.result
333
-
334
- if args
335
- ans = __send__ rule, *args
336
- else
337
- ans = __send__ rule
338
- end
339
- return nil unless ans
340
-
341
- break if @pos <= m.pos
342
-
343
- m.move! ans, @pos, @result
344
- end
345
-
346
- @result = m.result
347
- @pos = m.pos
348
- return m.ans
349
- end
350
-
351
- class RuleInfo
352
- def initialize(name, rendered)
353
- @name = name
354
- @rendered = rendered
355
- end
356
-
357
- attr_reader :name, :rendered
358
- end
359
-
360
- def self.rule_info(name, rendered)
361
- RuleInfo.new(name, rendered)
362
- end
363
-
364
-
365
- # :startdoc:
366
- # :stopdoc:
367
- def setup_foreign_grammar; end
368
-
369
- # Alphanumeric = /\p{Word}/
370
- def _Alphanumeric
371
- _tmp = scan(/\A(?-mix:\p{Word})/)
372
- set_failed_rule :_Alphanumeric unless _tmp
373
- return _tmp
374
- end
375
-
376
- # AlphanumericAscii = /[A-Za-z0-9]/
377
- def _AlphanumericAscii
378
- _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
379
- set_failed_rule :_AlphanumericAscii unless _tmp
380
- return _tmp
381
- end
382
-
383
- # LowerAlphabetAscii = /[a-z]/
384
- def _LowerAlphabetAscii
385
- _tmp = scan(/\A(?-mix:[a-z])/)
386
- set_failed_rule :_LowerAlphabetAscii unless _tmp
387
- return _tmp
388
- end
389
-
390
- # Digit = /[0-9]/
391
- def _Digit
392
- _tmp = scan(/\A(?-mix:[0-9])/)
393
- set_failed_rule :_Digit unless _tmp
394
- return _tmp
395
- end
396
-
397
- # BOM = "uFEFF"
398
- def _BOM
399
- _tmp = match_string("uFEFF")
400
- set_failed_rule :_BOM unless _tmp
401
- return _tmp
402
- end
403
-
404
- # Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
405
- def _Newline
406
- _tmp = scan(/\A(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
407
- set_failed_rule :_Newline unless _tmp
408
- return _tmp
409
- end
410
-
411
- # NonAlphanumeric = /\p{^Word}/
412
- def _NonAlphanumeric
413
- _tmp = scan(/\A(?-mix:\p{^Word})/)
414
- set_failed_rule :_NonAlphanumeric unless _tmp
415
- return _tmp
416
- end
417
-
418
- # Spacechar = /\t|\p{Zs}/
419
- def _Spacechar
420
- _tmp = scan(/\A(?-mix:\t|\p{Zs})/)
421
- set_failed_rule :_Spacechar unless _tmp
422
- return _tmp
423
- end
424
-
425
- Rules = {}
426
- Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/\\p{Word}/")
427
- Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
428
- Rules[:_LowerAlphabetAscii] = rule_info("LowerAlphabetAscii", "/[a-z]/")
429
- Rules[:_Digit] = rule_info("Digit", "/[0-9]/")
430
- Rules[:_BOM] = rule_info("BOM", "\"uFEFF\"")
431
- Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?|\\p{Zl}|\\p{Zp}/")
432
- Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/\\p{^Word}/")
433
- Rules[:_Spacechar] = rule_info("Spacechar", "/\\t|\\p{Zs}/")
434
- # :startdoc:
435
- end