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,17 @@
1
+ require 'lineinput'
2
+
3
+ module ReVIEW
4
+ class LineInput < LineInput
5
+ def skip_comment_lines
6
+ n = 0
7
+ while line = gets()
8
+ unless line.strip =~ /\A\#@/
9
+ ungets line
10
+ return n
11
+ end
12
+ n += 1
13
+ end
14
+ n
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
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_method :to_s, :string
23
+ end
24
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2012-2014 Yuto HAYAMIZU, 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
+ # For details of the GNU LGPL, see the file "COPYING".
9
+ #
10
+ require 'pathname'
11
+ require 'fileutils'
12
+
13
+ module ReVIEW
14
+ class MakerHelper
15
+ # Return review/bin directory
16
+ def self.bindir
17
+ Pathname.new("#{Pathname.new(__FILE__).realpath.dirname}/../../bin").realpath
18
+ end
19
+
20
+ # Copy image files under from_dir to to_dir recursively
21
+ # ==== Args
22
+ # from_dir :: path to the directory which has image files to be copied
23
+ # to_dir :: path to the directory to which the image files are copied
24
+ # options :: used to specify optional operations during copy
25
+ # ==== Returns
26
+ # list of image files
27
+ # ==== Options
28
+ # :convert :: Conversion rule
29
+ # ==== Examples
30
+ #
31
+ # copy_images_to_dir("/path/to/foo", "/path/to/bar", :convert => {:eps => :png})
32
+ #
33
+ # Image files are copied recursively, and each '.eps' file is converted into '.eps.png'
34
+ #
35
+
36
+ def self.copy_images_to_dir(from_dir, to_dir, options = {})
37
+ image_files = []
38
+
39
+ Dir.open(from_dir) do |dir|
40
+ dir.each do |fname|
41
+ next if fname =~ /^\./
42
+ if FileTest.directory?("#{from_dir}/#{fname}")
43
+ image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
44
+ else
45
+ FileUtils.mkdir_p(to_dir) unless File.exist?(to_dir)
46
+
47
+ is_converted = false
48
+ (options[:convert] || {}).each do |orig_type, conv_type|
49
+ next unless /\.#{orig_type}$/ =~ fname
50
+ is_converted = system("convert #{from_dir}/#{fname} #{to_dir}/#{fname}.#{conv_type}")
51
+ image_files << "#{from_dir}/#{fname}.#{conv_type}"
52
+ end
53
+
54
+ exts = options[:exts] || %w(png gif jpg jpeg svg pdf eps)
55
+ exts_str = exts.join('|')
56
+ if !is_converted && fname =~ /\.(#{exts_str})$/i
57
+ FileUtils.cp "#{from_dir}/#{fname}", to_dir
58
+ image_files << "#{from_dir}/#{fname}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ image_files
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,339 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This program is free software.
3
+ # You can distribute or modify this program under the terms of
4
+ # the GNU LGPL, Lesser General Public License version 2.1.
5
+
6
+ require 'review/builder'
7
+ require 'review/textutils'
8
+
9
+ module ReVIEW
10
+
11
+ class MARKDOWNBuilder < Builder
12
+ include TextUtils
13
+
14
+ def extname
15
+ '.md'
16
+ end
17
+
18
+ def builder_init_file
19
+ @ul_indent = 0
20
+ @chapter.book.image_types = %w( .png .jpg .jpeg .gif .svg )
21
+ end
22
+ private :builder_init_file
23
+
24
+ def blank_reset
25
+ @blank_seen = false
26
+ end
27
+
28
+ # def puts(str)
29
+ # @blank_seen = false
30
+ # "#{str}\n"
31
+ # end
32
+
33
+ def blank
34
+ buf = ""
35
+ unless @blank_seen
36
+ buf = "\n"
37
+ end
38
+ @blank_seen = true
39
+ buf
40
+ end
41
+
42
+ def headline(level, label, caption)
43
+ buf = ""
44
+ buf << blank
45
+ prefix = "#" * level
46
+ buf << "#{prefix} #{caption}\n"
47
+ blank_reset
48
+ buf << "\n"
49
+ buf
50
+ end
51
+
52
+ def quote(lines)
53
+ buf = ""
54
+ buf << blank
55
+ buf << lines.map{|line| line.chomp!;line.chomp!;"> #{line}"}.join("\n") << "\n"
56
+ blank_reset
57
+ buf << "\n"
58
+ buf
59
+ end
60
+
61
+ def paragraph(lines)
62
+ buf = lines.join << "\n"
63
+ blank_reset
64
+ buf << "\n"
65
+ buf
66
+ end
67
+
68
+ def list_header(id, caption, lang)
69
+ lang ||= ""
70
+ if get_chap.nil?
71
+ %Q[リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n] + "```#{lang}\n"
72
+ else
73
+ %Q[リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n] + "```#{lang}\n"
74
+ end
75
+ end
76
+
77
+ def list_body(id, lines, lang)
78
+ buf = ""
79
+ lines.each do |line|
80
+ buf << detab(line) << "\n"
81
+ end
82
+ buf << '```' << "\n"
83
+ buf
84
+ end
85
+
86
+ def ul_begin
87
+ buf = ""
88
+ buf << blank if @ul_indent == 0
89
+ @ul_indent += 1
90
+ buf
91
+ end
92
+
93
+ def ul_item(lines)
94
+ blank_reset
95
+ " " * (@ul_indent - 1) + "* " + "#{lines.join}" + "\n"
96
+ end
97
+
98
+ def ul_item_begin(lines)
99
+ blank_reset
100
+ " " * (@ul_indent - 1) + "* " + "#{lines.join}" + "\n"
101
+ end
102
+
103
+ def ul_item_end
104
+ ""
105
+ end
106
+
107
+ def ul_end
108
+ buf = ""
109
+ @ul_indent -= 1
110
+ buf << blank if @ul_indent == 0
111
+ buf
112
+ end
113
+
114
+ def ol_begin
115
+ buf = ""
116
+ buf << blank
117
+ buf
118
+ end
119
+
120
+ def ol_item(lines, num)
121
+ buf = ""
122
+ buf << "#{num}. #{lines.join}" << "\n"
123
+ blank_reset
124
+ buf
125
+ end
126
+
127
+ def ol_end
128
+ buf = ""
129
+ buf << blank
130
+ buf
131
+ end
132
+
133
+ def emlist(lines, caption = nil, lang = nil)
134
+ buf = ""
135
+ buf << blank
136
+ if caption
137
+ buf << caption << "\n\n"
138
+ end
139
+ lang ||= ""
140
+ buf << "```#{lang}\n"
141
+ blank_reset
142
+ lines.each do |line|
143
+ buf << detab(line) << "\n"
144
+ end
145
+ buf << "```\n"
146
+ buf << blank
147
+ buf
148
+ end
149
+
150
+ def hr
151
+ buf << "----\n"
152
+ blank_reset
153
+ buf
154
+ end
155
+
156
+ def compile_href(url, label)
157
+ label = url if label.blank?
158
+ "[#{label}](#{url})"
159
+ end
160
+
161
+ def inline_i(str)
162
+ "*#{str.gsub(/\*/, '\*')}*"
163
+ end
164
+
165
+ def inline_em(str)
166
+ "*#{str.gsub(/\*/, '\*')}*"
167
+ end
168
+
169
+ def inline_b(str)
170
+ "**#{str.gsub(/\*/, '\*')}**"
171
+ end
172
+
173
+ def inline_strong(str)
174
+ "**#{str.gsub(/\*/, '\*')}**"
175
+ end
176
+
177
+ def inline_code(str)
178
+ "`#{str}`"
179
+ end
180
+
181
+ def inline_tt(str)
182
+ "`#{str}`"
183
+ end
184
+
185
+
186
+ def image_image(id, caption, metric)
187
+ buf = ""
188
+ buf << blank
189
+ buf << "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(/\A\.\//, "")})" << "\n"
190
+ blank_reset
191
+ buf << blank
192
+ buf
193
+ end
194
+
195
+ def image_dummy(id, caption, lines)
196
+ buf = ""
197
+ buf << lines.join << "\n"
198
+ blank_reset
199
+ buf
200
+ end
201
+
202
+ def inline_img(id)
203
+ "#{I18n.t("image")}#{@chapter.image(id).number}"
204
+ rescue KeyError
205
+ error "unknown image: #{id}"
206
+ "[UnknownImage:#{id}]"
207
+ end
208
+
209
+ def indepimage(id, caption="", metric=nil)
210
+ buf = ""
211
+ buf << blank
212
+ buf << "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(/\A\.\//, "")})" << "\n"
213
+ blank_reset
214
+ buf << blank
215
+ buf
216
+ end
217
+
218
+ def pagebreak
219
+ buf = ""
220
+ buf << "{pagebreak}" << "\n"
221
+ buf
222
+ end
223
+
224
+ def image_ext
225
+ "jpg"
226
+ end
227
+
228
+ def cmd(lines, caption = nil)
229
+ buf = ""
230
+ buf << "```shell-session" << "\n"
231
+ blank_reset
232
+ lines.each do |line|
233
+ buf << detab(line) << "\n"
234
+ end
235
+ buf << "```" << "\n"
236
+ buf
237
+ end
238
+
239
+ def table(lines, id = nil, caption = nil)
240
+ buf = ""
241
+ rows = []
242
+ sepidx = nil
243
+ lines.each_with_index do |line, idx|
244
+ if /\A[\=\-]{12}/ =~ line
245
+ # just ignore
246
+ #error "too many table separator" if sepidx
247
+ sepidx ||= idx
248
+ next
249
+ end
250
+ rows.push line.strip.split(/\t+/).map{|s| s.sub(/\A\./, '') }
251
+ end
252
+ rows = adjust_n_cols(rows)
253
+
254
+ begin
255
+ buf << table_header(id, caption) unless caption.nil?
256
+ rescue KeyError
257
+ error "no such table: #{id}"
258
+ end
259
+ buf << table_begin(rows.first.size)
260
+ return buf if rows.empty?
261
+ if sepidx
262
+ sepidx.times do
263
+ buf << tr(rows.shift.map{|s| th(s) })
264
+ end
265
+ buf << table_border(rows.first.size)
266
+ rows.each do |cols|
267
+ buf << tr(cols.map{|s| td(s) })
268
+ end
269
+ else
270
+ rows.each do |cols|
271
+ h, *cs = *cols
272
+ tr([th(h)] + cs.map {|s| td(s) })
273
+ end
274
+ end
275
+ buf << table_end
276
+ buf
277
+ end
278
+
279
+ def table_header(id, caption)
280
+ buf = ""
281
+ if get_chap.nil?
282
+ buf << %Q[#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}] << "\n"
283
+ else
284
+ buf << %Q[#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}] << "\n"
285
+ end
286
+ blank_reset
287
+ buf << blank
288
+ buf
289
+ end
290
+
291
+ def table_begin(ncols)
292
+ ""
293
+ end
294
+
295
+ def tr(rows)
296
+ "|#{rows.join("|")}|\n"
297
+ end
298
+
299
+ def table_border(ncols)
300
+ blank_reset
301
+ (0..ncols).map{"|"}.join(":--") + "\n"
302
+ end
303
+
304
+ def th(str)
305
+ "#{str}"
306
+ end
307
+
308
+ def td(str)
309
+ "#{str}"
310
+ end
311
+
312
+ def table_end
313
+ buf = ""
314
+ buf << blank
315
+ buf
316
+ end
317
+
318
+ def footnote(id, str)
319
+ buf = ""
320
+ buf << "[^#{id}]: #{compile_inline(str)}" << "\n"
321
+ blank_reset
322
+ buf << blank
323
+ buf
324
+ end
325
+
326
+ def inline_fn(id)
327
+ "[^#{id}]"
328
+ end
329
+
330
+ def inline_br(str)
331
+ "\n"
332
+ end
333
+
334
+ def nofunc_text(str)
335
+ str
336
+ end
337
+ end
338
+
339
+ end # module ReVIEW