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,25 +0,0 @@
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
@@ -1,41 +0,0 @@
1
- # Copyright (c) 2009 Narihiro Nakamura <authornari@gmail.com>
2
- require 'erb'
3
-
4
- class HTMLLayout
5
- include ERB::Util
6
-
7
- def initialize(params, template)
8
- @body = params['body']
9
- @title = params['title']
10
- @toc = params['toc']
11
- @next = params['next']
12
- @prev = params['prev']
13
- @builder = params['builder']
14
- @template = template
15
- end
16
- attr_reader :body, :title, :toc
17
-
18
- def next_chapter
19
- if @next.present?
20
- "<a href='#{h @next.id}.html'>#{h @builder.compile_inline @next.title}</a>"
21
- else
22
- ""
23
- end
24
- end
25
-
26
- def prev_chapter
27
- if @prev.present?
28
- "<a href='#{h @prev.id}.html'>#{h @builder.compile_inline @prev.title}</a>"
29
- else
30
- ""
31
- end
32
- end
33
-
34
- def result
35
- if File.exist?(@template)
36
- return ERB.new(IO.read(@template)).result(binding)
37
- else
38
- return @src
39
- end
40
- end
41
- end
@@ -1,357 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Copyright (c) 2012 Kenshi Muto
4
- #
5
- # This program is free software.
6
- # You can distribute or modify this program under the terms of
7
- # the GNU LGPL, Lesser General Public License version 2.1.
8
- #
9
- # INAO Style (experimental)
10
-
11
- require 'review/builder'
12
- require 'review/textutils'
13
-
14
- module ReVIEW
15
-
16
- class INAOBuilder < Builder
17
-
18
- include TextUtils
19
-
20
- def pre_paragraph
21
- ''
22
- end
23
-
24
- def post_paragraph
25
- ''
26
- end
27
-
28
- def extname
29
- '.txt'
30
- end
31
-
32
- def builder_init_file
33
- @noindent = nil
34
-
35
- @titles = {
36
- "emlist" => "list",
37
- "list" => "list",
38
- "cmd" => "list",
39
- "source" => "list",
40
- "quote" => "quote",
41
- "column" => "column",
42
- }
43
- end
44
- private :builder_init_file
45
-
46
-
47
- def warn(msg)
48
- $stderr.puts "#{@location.filename}:#{@location.lineno}: warning: #{msg}"
49
- end
50
-
51
- def error(msg)
52
- $stderr.puts "#{@location.filename}:#{@location.lineno}: error: #{msg}"
53
- end
54
-
55
- def messages
56
- error_messages() + warning_messages()
57
- end
58
-
59
- def base_parablock(type, lines, caption=nil)
60
- buf = ""
61
- buf << "◆#{@titles[type]}/◆\n"
62
- buf << "■■■■■#{caption}\n" unless caption.nil?
63
- buf << lines.join("")
64
- buf << "◆/#{@titles[type]}◆\n"
65
- buf << "\n"
66
- buf
67
- end
68
-
69
- def headline(level, label, caption)
70
- prefix = "■" * level
71
- "#{prefix}#{caption}\n"
72
- end
73
-
74
- def paragraph(lines)
75
- buf = ""
76
- buf << " " if @noindent.nil?
77
- @noindent = nil
78
- buf << lines.join + "\n"
79
- buf
80
- end
81
-
82
- def noindent
83
- @noindent = true
84
- end
85
-
86
- def inline_b(str)
87
- "◆b/◆#{str}◆/b◆"
88
- end
89
-
90
- def inline_i(str)
91
- "◆i/◆#{str}◆/i◆"
92
- end
93
-
94
- def inline_tt(str)
95
- "◆cmd/◆#{str}◆/cmd◆"
96
- end
97
-
98
- def inline_cmd(str)
99
- inline_tt(str)
100
- end
101
-
102
- def footnote(id, str)
103
- #
104
- ""
105
- end
106
-
107
- def inline_fn(id)
108
- "◆注/◆#{@chapter.footnote(id).content.strip}◆/注◆"
109
- end
110
-
111
- def inline_keytop(str)
112
- "#{str}▲"
113
- end
114
-
115
- def inline_kbd(str)
116
- inline_keytop(str)
117
- end
118
-
119
- # 「赤文字」はなし
120
-
121
- def compile_ruby(base, ruby)
122
- "◆ルビ/◆#{base}◆#{ruby}◆/ルビ◆"
123
- end
124
-
125
- def quote(lines)
126
- lines_fixed = lines.map{|line| line.sub(/^ /,"")} ## インデントを消す
127
- base_parablock "quote", lines_fixed, nil
128
- end
129
-
130
- def column_begin(level, label, caption)
131
- buf = ""
132
- buf << "◆column/◆\n"
133
- buf << "■■■■#{caption}\n"
134
- buf
135
- end
136
-
137
- def column_end(level)
138
- "◆/column◆\n"
139
- end
140
-
141
- def ul_begin
142
- ""
143
- end
144
-
145
- def ul_item(lines)
146
- "・#{lines.join}\n"
147
- end
148
-
149
- def ul_end
150
- ""
151
- end
152
-
153
- def ol_begin
154
- @olitem = 0
155
- ""
156
- end
157
-
158
- def ol_item(lines, num)
159
- "(#{num})#{lines.join}\n"
160
- end
161
-
162
- def ol_end
163
- @olitem = nil
164
- ""
165
- end
166
-
167
- def inline_list(id)
168
- chapter, id = extract_chapter_id(id)
169
- if get_chap(chapter).nil?
170
- %Q[リスト#{@chapter.list(id).number}]
171
- else
172
- %Q[リスト#{get_chap(chapter)}.#{@chapter.list(id).number}]
173
- end
174
- end
175
-
176
- def list_header(id, caption, lang)
177
- buf = "◆list/◆\n"
178
- if get_chap.nil?
179
- buf << %Q[●リスト#{@chapter.list(id).number} #{caption}\n]
180
- else
181
- buf << %Q[●リスト#{get_chap}.#{@chapter.list(id).number} #{caption}\n]
182
- end
183
- buf
184
- end
185
-
186
- def list_body(id, lines, lang)
187
- buf = ""
188
- lines.each do |line|
189
- buf << detab(line) << "\n"
190
- end
191
- buf << "◆/list◆\n"
192
- buf
193
- end
194
-
195
- def listnum_body(lines, lang)
196
- buf = ""
197
- lines.each_with_index do |line, i|
198
- buf << detab((i+1).to_s.rjust(2) + " " + line) << "\n"
199
- end
200
- buf << "◆/list◆\n"
201
- buf
202
- end
203
-
204
- def emlist(lines, caption = nil)
205
- buf = ""
206
- buf << "◆list/◆\n"
207
- buf << %Q[●#{caption}\n] unless caption.nil?
208
- lines.each do |line|
209
- buf << detab(line) << "\n"
210
- end
211
- buf << "◆/list◆\n"
212
- buf
213
- end
214
-
215
- # o1,o2のようなことはできない
216
-
217
- def inline_balloon(str)
218
- "◆comment/◆#{str}◆/comment◆"
219
- end
220
-
221
- def inline_comment(str)
222
- inline_balloon(str)
223
- end
224
-
225
- # whiteリスト代用
226
- def cmd(lines, caption = nil)
227
- buf = "◆list-white/◆\n"
228
- buf << %Q[●#{caption}\n] unless caption.nil?
229
- lines.each do |line|
230
- buf << detab(line) << "\n"
231
- end
232
- buf << "◆/list-white◆\n"
233
- buf
234
- end
235
-
236
- def inline_img(id)
237
- chapter, id = extract_chapter_id(id)
238
- if get_chap(chapter).nil?
239
- "図#{chapter.image(id).number}"
240
- else
241
- "図#{get_chap(chapter)}.#{chapter.image(id).number}"
242
- end
243
- end
244
-
245
- def image(lines, id, caption, metric=nil)
246
- buf = ""
247
- if get_chap.nil?
248
- buf << "●図#{@chapter.image(id).number} #{caption}\n"
249
- else
250
- buf << "●図#{get_chap}.#{@chapter.image(id).number} #{caption}\n"
251
- end
252
- if @chapter.image(id).bound?
253
- buf << @chapter.image(id).path << "\n"
254
- else
255
- lines.each do |line|
256
- buf << line + "\n"
257
- end
258
- end
259
- buf
260
- end
261
-
262
- def inline_table(id)
263
- chapter, id = extract_chapter_id(id)
264
- if get_chap(chapter).nil?
265
- "表#{chapter.table(id).number}"
266
- else
267
- "表#{get_chap(chapter)}.#{chapter.table(id).number}"
268
- end
269
- end
270
-
271
- def table(lines, id = nil, caption = nil)
272
- buf = ""
273
- rows = []
274
- sepidx = nil
275
- lines.each_with_index do |line, idx|
276
- if /\A[\=\-]{12}/ =~ line
277
- # just ignore
278
- #error "too many table separator" if sepidx
279
- sepidx ||= idx
280
- next
281
- end
282
- rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
283
- end
284
- rows = adjust_n_cols(rows)
285
-
286
- buf << "◆table/◆\n"
287
- begin
288
- buf << table_header(id, caption) unless caption.nil?
289
- rescue KeyError
290
- error "no such table: #{id}"
291
- end
292
- return buf if rows.empty?
293
- buf << table_begin(rows.first.size)
294
- if sepidx
295
- sepidx.times do
296
- buf << "◆table-title◆"
297
- buf << tr(rows.shift.map {|s| th(s) })
298
- end
299
- rows.each do |cols|
300
- buf << tr(cols.map {|s| td(s) })
301
- end
302
- else
303
- rows.each do |cols|
304
- h, *cs = *cols
305
- buf << tr([th(h)] + cs.map {|s| td(s) })
306
- end
307
- end
308
- buf << table_end
309
- buf
310
- end
311
-
312
- def table_header(id, caption)
313
- if get_chap.nil?
314
- "●表#{@chapter.table(id).number} #{caption}\n"
315
- else
316
- "●表#{get_chap}.#{@chapter.table(id).number} #{caption}\n"
317
- end
318
- end
319
-
320
- def table_begin(ncols)
321
- ""
322
- end
323
-
324
- def tr(rows)
325
- rows.join("\t") + "\n"
326
- end
327
-
328
- def th(str)
329
- str
330
- end
331
-
332
- def td(str)
333
- str
334
- end
335
-
336
- def table_end
337
- "◆/table◆\n"
338
- end
339
-
340
- def inline_raw(str)
341
- %Q[#{super(str).gsub("\\n", "\n")}]
342
- end
343
-
344
- def inline_uchar(str)
345
- [str.to_i(16)].pack("U")
346
- end
347
-
348
- def text(str)
349
- str
350
- end
351
-
352
- def nofunc_text(str)
353
- str
354
- end
355
- end
356
-
357
- end # module ReVIEW
@@ -1,24 +0,0 @@
1
- module ReVIEW
2
- class Location
3
- def initialize(filename, compiler)
4
- @filename = filename
5
- @f = compiler
6
- end
7
-
8
- attr_reader :filename
9
-
10
- def lineno
11
- @f.current_line
12
- end
13
-
14
- def string
15
- begin
16
- "#{@filename}:#{self.lineno}"
17
- rescue
18
- "#{@filename}:nil"
19
- end
20
- end
21
-
22
- alias to_s string
23
- end
24
- end