review-retrovert 0.9.11 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +1 -1
  4. data/Rakefile +15 -0
  5. data/lib/review/retrovert/cli.rb +6 -0
  6. data/lib/review/retrovert/converter.rb +38 -0
  7. data/lib/review/retrovert/version.rb +1 -1
  8. data/lib/review/retrovert/yamlconfig.rb +38 -1
  9. metadata +49 -146
  10. data/.dockerignore +0 -9
  11. data/.editorconfig +0 -16
  12. data/.gitattributes +0 -5
  13. data/.github/FUNDING.yml +0 -4
  14. data/.github/workflows/docker-build.yml +0 -26
  15. data/.github/workflows/release.yml +0 -26
  16. data/.github/workflows/retrovert.yml +0 -91
  17. data/.gitignore +0 -15
  18. data/.rspec +0 -3
  19. data/.ruby-version +0 -1
  20. data/.vscode/launch.json +0 -48
  21. data/Dockerfile +0 -5
  22. data/Gemfile +0 -8
  23. data/Gemfile.lock +0 -118
  24. data/Makefile +0 -31
  25. data/bin/console +0 -14
  26. data/bin/setup +0 -8
  27. data/docker/review.Dockerfile +0 -10
  28. data/hooks/post_push +0 -8
  29. data/package-lock.json +0 -6
  30. data/package.json +0 -1
  31. data/review-retrovert.code-workspace +0 -8
  32. data/review-retrovert.gemspec +0 -37
  33. data/testdata/mybook/.gitignore +0 -13
  34. data/testdata/mybook/.textlintrc +0 -11
  35. data/testdata/mybook/README.md +0 -43
  36. data/testdata/mybook/Rakefile +0 -24
  37. data/testdata/mybook/catalog.yml +0 -60
  38. data/testdata/mybook/config-noretrovert.yml +0 -404
  39. data/testdata/mybook/config-retrovert.yml +0 -16
  40. data/testdata/mybook/config-starter.yml +0 -264
  41. data/testdata/mybook/config.yml +0 -404
  42. data/testdata/mybook/contents/00-preface.re +0 -129
  43. data/testdata/mybook/contents/01-install.re +0 -305
  44. data/testdata/mybook/contents/02-tutorial.re +0 -1228
  45. data/testdata/mybook/contents/03-syntax.re +0 -4610
  46. data/testdata/mybook/contents/04-customize.re +0 -1064
  47. data/testdata/mybook/contents/05-faq.re +0 -606
  48. data/testdata/mybook/contents/06-bestpractice.re +0 -1343
  49. data/testdata/mybook/contents/91-compare.re +0 -418
  50. data/testdata/mybook/contents/92-filelist.re +0 -125
  51. data/testdata/mybook/contents/93-background.re +0 -267
  52. data/testdata/mybook/contents/99-postface.re +0 -39
  53. data/testdata/mybook/contents/r0-inner.re +0 -2
  54. data/testdata/mybook/contents/r0-root.re +0 -49
  55. data/testdata/mybook/contents/table.csv +0 -4
  56. data/testdata/mybook/contents/test.txt +0 -1
  57. data/testdata/mybook/contents/ut.re +0 -5
  58. data/testdata/mybook/css/normalize.css +0 -349
  59. data/testdata/mybook/css/webstyle.css +0 -692
  60. data/testdata/mybook/data/terms.txt +0 -3
  61. data/testdata/mybook/data/words.txt +0 -15
  62. data/testdata/mybook/images/03-syntax/favicon-16x16.png +0 -0
  63. data/testdata/mybook/images/03-syntax/figure_heretop.png +0 -0
  64. data/testdata/mybook/images/03-syntax/index-page.png +0 -0
  65. data/testdata/mybook/images/03-syntax/order-detail.png +0 -0
  66. data/testdata/mybook/images/03-syntax/tw-icon1.jpg +0 -0
  67. data/testdata/mybook/images/03-syntax/tw-icon2.jpg +0 -0
  68. data/testdata/mybook/images/03-syntax/tw-icon3.jpg +0 -0
  69. data/testdata/mybook/images/03-syntax/tw-icon4.jpg +0 -0
  70. data/testdata/mybook/images/04-customize/caption_pagebreak.png +0 -0
  71. data/testdata/mybook/images/04-customize/chaptitlepage_sample.png +0 -0
  72. data/testdata/mybook/images/04-customize/section_decoration_samples.png +0 -0
  73. data/testdata/mybook/images/05-faq/codeblock_rpadding1.png +0 -0
  74. data/testdata/mybook/images/05-faq/codeblock_rpadding2.png +0 -0
  75. data/testdata/mybook/images/05-faq/dummy-image.png +0 -0
  76. data/testdata/mybook/images/06-bestpractice/figure_heretop.png +0 -0
  77. data/testdata/mybook/images/06-bestpractice/font_beramono.png +0 -0
  78. data/testdata/mybook/images/06-bestpractice/heading_design1.png +0 -0
  79. data/testdata/mybook/images/06-bestpractice/heading_design2.png +0 -0
  80. data/testdata/mybook/images/06-bestpractice/margin_book.png +0 -0
  81. data/testdata/mybook/images/06-bestpractice/multiline-title.png +0 -0
  82. data/testdata/mybook/images/06-bestpractice/preface_numbered.png +0 -0
  83. data/testdata/mybook/images/06-bestpractice/program_border.png +0 -0
  84. data/testdata/mybook/images/06-bestpractice/sechead_design_4.png +0 -0
  85. data/testdata/mybook/images/06-bestpractice/section_title_wlines.png +0 -0
  86. data/testdata/mybook/images/06-bestpractice/titlepage-samples.png +0 -0
  87. data/testdata/mybook/images/93-background/bug913.png +0 -0
  88. data/testdata/mybook/images/93-background/slide2.png +0 -0
  89. data/testdata/mybook/images/avatar-b.png +0 -0
  90. data/testdata/mybook/images/avatar-g.png +0 -0
  91. data/testdata/mybook/images/avatar-r.png +0 -0
  92. data/testdata/mybook/images/caution-icon.png +0 -0
  93. data/testdata/mybook/images/cover_a5.pdf +0 -0
  94. data/testdata/mybook/images/cover_b5.pdf +0 -0
  95. data/testdata/mybook/images/info-icon.png +0 -0
  96. data/testdata/mybook/images/tw-icon.jpg +0 -0
  97. data/testdata/mybook/images/warning-icon.png +0 -0
  98. data/testdata/mybook/layouts/layout.epub.erb +0 -29
  99. data/testdata/mybook/layouts/layout.html5.erb +0 -108
  100. data/testdata/mybook/layouts/layout.tex.erb +0 -432
  101. data/testdata/mybook/layouts/layout.tex.erb.orig +0 -386
  102. data/testdata/mybook/lib/hooks/beforetexcompile.rb +0 -55
  103. data/testdata/mybook/lib/ruby/review-book.rb +0 -64
  104. data/testdata/mybook/lib/ruby/review-builder.rb +0 -1342
  105. data/testdata/mybook/lib/ruby/review-cli.rb +0 -58
  106. data/testdata/mybook/lib/ruby/review-compiler.rb +0 -1176
  107. data/testdata/mybook/lib/ruby/review-epubbuilder.rb +0 -33
  108. data/testdata/mybook/lib/ruby/review-epubmaker.rb +0 -609
  109. data/testdata/mybook/lib/ruby/review-htmlbuilder.rb +0 -949
  110. data/testdata/mybook/lib/ruby/review-latexbuilder.rb +0 -1065
  111. data/testdata/mybook/lib/ruby/review-maker.rb +0 -346
  112. data/testdata/mybook/lib/ruby/review-markdownbuilder.rb +0 -945
  113. data/testdata/mybook/lib/ruby/review-markdownmaker.rb +0 -91
  114. data/testdata/mybook/lib/ruby/review-monkeypatch.rb +0 -93
  115. data/testdata/mybook/lib/ruby/review-pdfmaker.rb +0 -546
  116. data/testdata/mybook/lib/ruby/review-textbuilder.rb +0 -36
  117. data/testdata/mybook/lib/ruby/review-tocparser.rb +0 -285
  118. data/testdata/mybook/lib/ruby/review-webmaker.rb +0 -448
  119. data/testdata/mybook/lib/tasks/mytasks.rake +0 -31
  120. data/testdata/mybook/lib/tasks/review.rake +0 -156
  121. data/testdata/mybook/lib/tasks/review.rake.orig +0 -72
  122. data/testdata/mybook/lib/tasks/starter.rake +0 -470
  123. data/testdata/mybook/locale.yml +0 -6
  124. data/testdata/mybook/review-ext.rb +0 -206
  125. data/testdata/mybook/sty/indexstyle.ist +0 -25
  126. data/testdata/mybook/sty/jumoline.sty +0 -310
  127. data/testdata/mybook/sty/mycolophon.sty +0 -81
  128. data/testdata/mybook/sty/mystyle.sty +0 -8
  129. data/testdata/mybook/sty/mytextsize.sty +0 -94
  130. data/testdata/mybook/sty/mytitlepage.sty +0 -126
  131. data/testdata/mybook/sty/review-base.sty +0 -276
  132. data/testdata/mybook/sty/reviewmacro.sty +0 -60
  133. data/testdata/mybook/sty/starter-codeblock.sty +0 -463
  134. data/testdata/mybook/sty/starter-color.sty +0 -134
  135. data/testdata/mybook/sty/starter-font.sty +0 -112
  136. data/testdata/mybook/sty/starter-heading.sty +0 -561
  137. data/testdata/mybook/sty/starter-misc.sty +0 -894
  138. data/testdata/mybook/sty/starter-note.sty +0 -180
  139. data/testdata/mybook/sty/starter-section.sty +0 -262
  140. data/testdata/mybook/sty/starter-talklist.sty +0 -105
  141. data/testdata/mybook/sty/starter-toc.sty +0 -72
  142. data/testdata/mybook/sty/starter-util.sty +0 -39
  143. data/testdata/mybook/sty/starter.sty +0 -36
  144. data/testdata/mybook/sty/ut.sty +0 -26
  145. data/testdata/mybook/style.css +0 -597
  146. data/testdata/mybook/ut-catalog.yml +0 -61
  147. data/testdata/mybook/ut-config-starter.yml +0 -3
  148. data/testdata/mybook/ut-config.yml +0 -404
@@ -1,448 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ###
4
- ### ReVIEW::WEBMakerクラスを書き直す
5
- ### (でも元がひどすぎるので書き直すにも限界がある)
6
- ###
7
-
8
- require 'pathname'
9
- require 'fileutils'
10
- require 'erb'
11
- require 'review/converter'
12
- require 'review/htmlbuilder'
13
- require 'review/template'
14
- require 'review/webmaker'
15
- require_relative './review-maker'
16
-
17
-
18
- module ReVIEW
19
-
20
- remove_const :WEBMaker
21
-
22
-
23
- class WEBMaker < Maker
24
-
25
- SCRIPT_NAME = "review-webmaker"
26
-
27
- def initialize(*args)
28
- super
29
- @config['htmlext'] = 'html'
30
- @docroot = @config['docroot'] || 'webroot'
31
- end
32
-
33
- def generate()
34
- remove_old_files()
35
- FileUtils.mkdir_p(@docroot)
36
- #
37
- @book = ReVIEW::Book.load(@basedir)
38
- @book.config = @config
39
- #
40
- copy_stylesheet()
41
- copy_frontmatter()
42
- build_body()
43
- copy_backmatter()
44
- #
45
- imagedir = @config['imagedir']
46
- destdir = "#{@docroot}/#{imagedir}"
47
- copy_images(imagedir, destdir)
48
- #
49
- copy_resources('covers', destdir)
50
- copy_resources('adv', destdir)
51
- copy_resources(@config['fontdir'], "#{@docroot}/fonts", @config['font_ext'])
52
- end
53
-
54
- def build_body()
55
- base_path = Pathname.new(@basedir)
56
- @converter = ReVIEW::Converter.new(@book, new_builder())
57
- @book.parts.each do |part|
58
- if part.name.present?
59
- if part.file?
60
- build_chap(part, base_path, true)
61
- else
62
- htmlfile = "part_#{part.number}.#{@config['htmlext']}"
63
- build_part(part, htmlfile)
64
- # title = ReVIEW::I18n.t('part', part.number)
65
- # title += ReVIEW::I18n.t('chapter_postfix') + part.name.strip unless part.name.strip.empty?
66
- end
67
- end
68
- part.chapters.each do |chap|
69
- build_chap(chap, base_path, false)
70
- end
71
- end
72
- end
73
-
74
- def new_builder()
75
- builder = ReVIEW::WEBBuilder.new()
76
- builder.starter_config = @starter_config
77
- return builder
78
- end
79
-
80
- def new_renderer()
81
- return WEBRenderer.new(@config, @book, @basedir, @starter_config)
82
- end
83
-
84
- def build_part(part, htmlfile)
85
- html = new_renderer().render_part(part)
86
- filepath = File.join(@docroot, htmlfile)
87
- File.write(filepath, html)
88
- end
89
-
90
- def build_chap(chap, base_path, ispart)
91
- filename = \
92
- if ispart.present?
93
- chap.path
94
- else
95
- Pathname.new(chap.path).relative_path_from(base_path).to_s
96
- end
97
- chapter_id = filename.sub(/\.re\Z/, '')
98
- htmlfile = "#{chapter_id}.#{@config['htmlext']}"
99
- #
100
- if @config['params'].present?
101
- warn "'params:' in config.yml is obsoleted."
102
- end
103
- #
104
- begin
105
- @converter.convert(filename, File.join(@docroot, htmlfile))
106
- ## 文法エラーだけキャッチし、それ以外のエラーはキャッチしないよう変更
107
- #rescue => ex
108
- rescue ApplicationError => ex
109
- warn "compile error in #{filename} (#{ex.class})"
110
- warn colored_errmsg(ex.message)
111
- generate_errorpage(ex, filename, htmlfile)
112
- end
113
- end
114
-
115
- def remove_old_files()
116
- math_dir = "./#{@config['imagedir']}/_review_math"
117
- FileUtils.rm_rf(math_dir) if @config['imgmath'] && Dir.exist?(math_dir)
118
- FileUtils.rm_rf(@docroot)
119
- end
120
-
121
- def copy_images(srcdir, destdir)
122
- copy_resources(srcdir, destdir, nil)
123
- end
124
-
125
- def copy_resources(srcdir, destdir, allow_exts=nil)
126
- if srcdir && File.exist?(srcdir)
127
- FileUtils.mkdir_p(destdir)
128
- allow_exts ||= @config['image_ext']
129
- ok = allow_exts && ! allow_exts.empty?
130
- ext_rexp = ok ? /\.(#{allow_exts.join('|')})\Z/i : nil
131
- _recursive_copy_files(srcdir, destdir, ext_rexp)
132
- end
133
- end
134
-
135
- def _recursive_copy_files(srcdir, destdir, ext_rexp)
136
- Dir.open(srcdir) do |dir|
137
- dir.each do |fname|
138
- next if fname.start_with?('.')
139
- srcpath = "#{srcdir}/#{fname}"
140
- if File.directory?(srcpath)
141
- destpath = "#{destdir}/#{fname}"
142
- _recursive_copy_files(srcpath, destpath, ext_rexp)
143
- elsif ext_rexp.nil? || fname =~ ext_rexp
144
- FileUtils.mkdir_p(destdir)
145
- FileUtils.cp(srcpath, destdir)
146
- end
147
- end
148
- end
149
- end
150
-
151
- def copy_stylesheet()
152
- cssdir = File.join(@docroot, "css")
153
- Dir.mkdir(cssdir) unless File.directory?(cssdir)
154
- [@config['stylesheet']].flatten.compact.each do |x|
155
- FileUtils.cp("css/#{x}", cssdir)
156
- end
157
- end
158
-
159
- def copy_frontmatter()
160
- generate_indexpage('index.html')
161
- #
162
- if @config['titlepage']
163
- destfile = "titlepage.#{@config['htmlext']}"
164
- if @config['titlefile']
165
- FileUtils.cp(@config['titlefile'], "#{@docroot}/#{destfile}")
166
- else
167
- generate_titlepage(destfile)
168
- end
169
- end
170
- #
171
- _copy_file(@config['creditfile'])
172
- _copy_file(@config['originaltitlefile'])
173
- end
174
-
175
- def generate_errorpage(ex, filename, htmlfile)
176
- s = new_renderer().render_exception(ex, filename)
177
- File.write(File.join(@docroot, htmlfile), s)
178
- end
179
-
180
- def generate_indexpage(htmlfile)
181
- s = new_renderer().render_indexpage()
182
- File.write(File.join(@docroot, htmlfile), s)
183
- rescue => ex
184
- generate_errorpage(ex, nil, htmlfile)
185
- end
186
-
187
- def generate_titlepage(htmlfile)
188
- s = new_renderer().render_titlepage()
189
- File.write(File.join(@docroot, htmlfile), s)
190
- end
191
-
192
- def copy_backmatter()
193
- conf = @config
194
- ext = conf['htmlext']
195
- _copy_file(conf['profile'])
196
- _copy_file(conf['advfile'])
197
- _copy_file(conf['colophon'], "colophon.#{ext}") if conf['colophon'].is_a?(String)
198
- _copy_file(conf['backcover'])
199
- end
200
-
201
- def _copy_file(srcfile, destfile=nil)
202
- if srcfile && File.exist?(srcfile)
203
- destfile ||= File.basename(srcfile)
204
- FileUtils.cp(srcfile, File.join(@docroot, destfile))
205
- end
206
- end
207
-
208
- end
209
-
210
-
211
- class WEBBuilder < HTMLBuilder
212
-
213
- def target_name
214
- #"web"
215
- "html"
216
- end
217
-
218
- def layoutfile
219
- "layouts/layout.html5.erb"
220
- end
221
-
222
- end
223
-
224
-
225
- class WEBRenderer < BaseRenderer
226
-
227
- def initialize(*args)
228
- super
229
- @language = @config['language']
230
- @stylesheets = @config['stylesheet']
231
- end
232
-
233
- def layout_template_name()
234
- #if @config['htmlversion'].to_i == 5
235
- # 'web/html/layout-html5.html.erb'
236
- #else
237
- # 'web/html/layout-xhtml1.html.erb'
238
- #end
239
- "layout.html5.erb"
240
- end
241
-
242
- def render_exception(error, textfile)
243
- @error = error
244
- @textfile = textfile
245
- #
246
- return render()
247
- end
248
-
249
- def render_part(part)
250
- part_name = part.name.strip
251
- #
252
- sb = ""
253
- sb << "<div class=\"part\">\n"
254
- sb << "<h1 class=\"part-number\">#{h i18n('part', part.number)}</h1>\n"
255
- sb << "<h2 class=\"part-title\">#{h part_name}</h2>\n" if part_name.present?
256
- sb << "<ul>\n"
257
- part.chapters.each do |c|
258
- htmlfile = c.path.sub(/\.re\z/, ".#{@config['htmlext']}")
259
- sb << " <li><a href=\"#{h htmlfile}\">第#{h c.number}章 #{h c.title}</a></li>\n"
260
- end
261
- sb << "</ul>\n"
262
- sb << "</div>\n"
263
- @body = sb
264
- #
265
- return render()
266
- end
267
-
268
- def render_indexpage()
269
- if @config['coverimage']
270
- imgfile = File.join(@config['imagedir'], @config['coverimage'])
271
- else
272
- imgfile = nil
273
- end
274
- #
275
- sb = ""
276
- if imgfile
277
- sb << " <div id=\"cover-image\" class=\"cover-image\">\n"
278
- sb << " <img src=\"#{imgfile}\" class=\"max\"/>\n"
279
- sb << " </div>\n"
280
- end
281
- @body = sb
282
- @toc = ReVIEW::WEBTOCPrinter.book_to_html(@book, nil)
283
- @next = @book.chapters[0]
284
- @next_title = @next ? @next.title : ''
285
- #
286
- return render()
287
- end
288
-
289
- def render_titlepage()
290
- author = @config['aut'] ? _join_names(@config.names_of('aut')) : nil
291
- publisher = @config['pbl'] ? _join_names(@config.names_of('pbl')) : nil
292
- #
293
- sb = ""
294
- sb << "<div class=\"titlepage\">\n"
295
- sb << "<h1 class=\"tp-title\">#{h @config.name_of('booktitle')}</h1>\n"
296
- sb << "<h2 class=\"tp-author\">#{author}</h2>\n" if author
297
- sb << "<h3 class=\"tp-publisher\">#{publisher}</h3>\n" if publisher
298
- sb << "</div>\n"
299
- @body = sb
300
- #
301
- return render()
302
- end
303
-
304
- private
305
-
306
- def _join_names(names)
307
- sep = i18n('names_splitter')
308
- return [names].flatten.join(sep)
309
- end
310
-
311
- end
312
-
313
-
314
- class WEBTOCPrinter
315
-
316
- def self.book_to_html(book, current_chapter)
317
- printer = self.new(nil, nil, nil)
318
- arr = printer.handle_book(book, current_chapter)
319
- html = printer.render_html(arr)
320
- return html
321
- end
322
-
323
- def render_html(arr)
324
- tag, attr, children = arr
325
- tag == "book" or raise "internal error: tag=#{tag.inspect}"
326
- buf = "<ul class=\"toc toc-1\">\n"
327
- children.each do |child|
328
- _render_li(child, buf, 1)
329
- end
330
- buf << "</ul>\n"
331
- return buf
332
- end
333
-
334
- def parse_inline(str)
335
- builder = HTMLBuilder.new
336
- builder.instance_variable_set('@book', @_book)
337
- @compiler ||= Compiler.new(builder)
338
- return @compiler.text(str)
339
- end
340
-
341
- def _render_li(arr, buf, n)
342
- tag, attr, children = arr
343
- case tag
344
- when "part"
345
- buf << "<li class=\"toc-part\">#{parse_inline(attr[:label])}\n"
346
- buf << " <ul class=\"toc toc-#{n+1}\">\n"
347
- children.each {|child| _render_li(child, buf, n+1) }
348
- buf << " </ul>\n"
349
- buf << "</li>\n"
350
- when "chapter"
351
- buf << " <li class=\"toc-chapter\"><a href=\"#{h attr[:path]}\">#{parse_inline(attr[:label])}</a>"
352
- if children && !children.empty?
353
- buf << "\n <ul class=\"toc toc-#{n+1}\">\n"
354
- children.each {|child| _render_li(child, buf, n+1) }
355
- buf << " </ul>\n"
356
- buf << " </li>\n"
357
- else
358
- buf << "</li>\n"
359
- end
360
- when "section"
361
- buf << " <li class=\"toc-section\"><a href=\"##{attr[:anchor]}\">#{parse_inline(attr[:label])}</a></li>\n"
362
- end
363
- buf
364
- end
365
-
366
- def handle_book(book, current_chapter)
367
- @_book = book
368
- children = []
369
- book.each_part do |part|
370
- if part.number
371
- children << handle_part(part, current_chapter)
372
- else
373
- part.each_chapter do |chap|
374
- children << handle_chapter(chap, current_chapter)
375
- end
376
- end
377
- end
378
- #
379
- attrs = {
380
- title: book.config['booktitle'],
381
- subtitle: book.config['subtitle'],
382
- }
383
- return ["book", attrs, children]
384
- end
385
-
386
- def handle_part(part, current_chapter)
387
- children = []
388
- part.each_chapter do |chap|
389
- children << handle_chapter(chap, current_chapter)
390
- end
391
- #
392
- attrs = {
393
- number: part.number,
394
- title: part.title,
395
- #label: "#{I18n.t('part_short', part.number)} #{part.title}",
396
- label: "#{I18n.t('part', part.number)} #{part.title}",
397
- }
398
- return ["part", attrs, children]
399
- end
400
-
401
- def handle_chapter(chap, current_chapter)
402
- children = []
403
- if current_chapter.nil? || chap == current_chapter
404
- chap.headline_index.each do |sec|
405
- next if sec.number.present? && sec.number.length >= 2
406
- children << handle_section(sec, chap)
407
- end
408
- end
409
- #
410
- chap_node = TOCParser.chapter_node(chap)
411
- ext = chap.book.config['htmlext'] || 'html'
412
- path = chap.path.sub(/\.re\z/, ".#{ext}")
413
- label = if chap_node.number && chap.on_chaps?
414
- "#{I18n.t('chapter_short', chap.number)} #{chap.title}"
415
- else
416
- chap.title
417
- end
418
- #
419
- attrs = {
420
- number: chap_node.number,
421
- title: chap.title,
422
- label: label,
423
- path: path,
424
- }
425
- return ["chapter", attrs, children]
426
- end
427
-
428
- def handle_section(sec, chap)
429
- if chap.number && sec.number.length > 0
430
- number = [chap.number] + sec.number
431
- label = "#{number.join('.')} #{sec.caption}"
432
- else
433
- number = nil
434
- label = sec.caption
435
- end
436
- attrs = {
437
- number: number,
438
- title: sec.caption,
439
- label: label,
440
- anchor: "h#{number ? number.join('-') : ''}",
441
- }
442
- return ["section", attrs, []]
443
- end
444
-
445
- end
446
-
447
-
448
- end
@@ -1,31 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ##
4
- ## これはreviewstarterが用意したファイル。
5
- ## ユーザ独自のRakeタスクをここに定義する。
6
- ##
7
-
8
-
9
- #
10
- #def render_eruby_files(param) # 要 Ruby >= 2.2
11
- # Dir.glob('**/*.eruby').each do |erubyfile|
12
- # origfile = erubyfile.sub(/\.eruby$/, '')
13
- # sh "erb -T 2 '#{param}' #{erubyfile} > #{origfile}"
14
- # end
15
- #end
16
- #
17
- #
18
- #namespace :setup do
19
- #
20
- # desc "*印刷用に設定 (B5, 10pt, mono)"
21
- # task :printing do
22
- # render_eruby_files('buildmode=printing')
23
- # end
24
- #
25
- # desc "*タブレット用に設定 (A5, 10pt, color)"
26
- # task :tablet do
27
- # render_eruby_files('buildmode=tablet')
28
- # end
29
- #
30
- #end
31
- #
@@ -1,156 +0,0 @@
1
- require 'fileutils'
2
- require 'rake/clean'
3
-
4
- BOOK = 'book'
5
- BOOK_PDF = BOOK + '.pdf'
6
- BOOK_EPUB = BOOK + '.epub'
7
- CONFIG_FILE = 'config.yml'
8
- WEBROOT = 'webroot'
9
-
10
- def build(mode, chapter)
11
- sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp"
12
- mode_ext = { 'html' => 'html', 'latex' => 'tex', 'idgxml' => 'xml' }
13
- FileUtils.mv 'tmp', chapter.gsub(/re\z/, mode_ext[mode])
14
- end
15
-
16
- def build_all(mode)
17
- sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css"
18
- end
19
-
20
- def config_file()
21
- conf = ENV['config']
22
- conf = CONFIG_FILE if conf.nil? || conf.empty?
23
- return conf
24
- end
25
-
26
- def setup_envvars()
27
- {
28
- 'c' => 'STARTER_CHAPTER',
29
- 't' => 'STARTER_TARGET',
30
- 'n' => 'STARTER_COMPILETIMES',
31
- 'd' => 'STARTER_DRAFT',
32
- }.each do |char, name|
33
- v = ENV.delete(char)
34
- ENV[name] = v if v && !v.empty?
35
- end
36
- end
37
-
38
- task default: :html_all
39
-
40
- desc 'build html (Usage: rake build re=target.re)'
41
- task :html => :prepare do
42
- if ENV['re'].nil?
43
- puts 'Usage: rake build re=target.re'
44
- exit
45
- end
46
- build('html', ENV['re'])
47
- end
48
-
49
- desc 'build all html'
50
- task :html_all => :prepare do
51
- build_all('html')
52
- end
53
-
54
- desc 'preproc all'
55
- task :preproc => :prepare do
56
- Dir.glob('*.re').each do |file|
57
- sh "review-preproc --replace #{file}"
58
- end
59
- end
60
-
61
- desc 'generate PDF and EPUB file'
62
- task all: %i[pdf epub]
63
-
64
- desc 'generate PDF file'
65
- task :pdf => :prepare do
66
- require 'review'
67
- #require 'review/pdfmaker'
68
- require './lib/ruby/review-pdfmaker'
69
- #
70
- setup_envvars() # ex: `c=01-install` => ENV['STARTER_CHAPTER']='01-install'
71
- #
72
- FileUtils.rm_rf [BOOK_PDF, BOOK, BOOK + '-pdf']
73
- begin
74
- ReVIEW::PDFMaker.execute(config_file())
75
- rescue RuntimeError => ex
76
- if ex.message =~ /^failed to run command:/
77
- abort "*\n* ERROR (review-pdfmaker):\n* #{ex.message}\n*"
78
- else
79
- raise
80
- end
81
- end
82
- end
83
-
84
- desc 'generate EPUB file'
85
- task :epub => :prepare do
86
- FileUtils.rm_rf [BOOK_EPUB, BOOK, BOOK + '-epub']
87
- #sh "review-epubmaker #{config_file()}"
88
- require 'review'
89
- require './lib/ruby/review-epubmaker'
90
- ReVIEW::EpubMaker.execute(config_file())
91
- end
92
-
93
- desc 'generate stagic HTML file for web'
94
- task :web => :prepare do
95
- FileUtils.rm_rf [WEBROOT]
96
- #sh "review-webmaker #{config_file()}"
97
- require 'review'
98
- #require 'review/webmaker'
99
- require './lib/ruby/review-webmaker'
100
- ReVIEW::WEBMaker.execute(config_file())
101
- end
102
-
103
-
104
- #desc "+ copy *.re files under 'contents/' into here."
105
- task :prepare do
106
- require 'yaml'
107
- config = YAML.load_file(config_file())
108
- PREPARES.each do |x|
109
- case x
110
- when Proc; x.call(config)
111
- else ; __send__(x, config)
112
- end
113
- end
114
- end
115
-
116
- ## 前処理を追加したい場合は、関数名またはProcオブジェクトをこの配列に追加する
117
- PREPARES = [:copy_files_under_contentdir]
118
-
119
- def copy_files_under_contentdir(config)
120
- ## 設定ファイル (config.yml) の「contentdir:」の値を調べる
121
- contdir = config['contentdir']
122
- if contdir && contdir != '.' # '.' はカレントディレクトリを表すので対象外
123
- ## もし contentdir が存在しなければエラー
124
- unless File.directory?(contdir)
125
- abort_with_message <<END
126
- ERROR: Content directory '#{contdir}' not exist.
127
- Please check 'contentdir:' value in config file,
128
- or create '#{contdir}' directory and put *.re files into there.
129
- END
130
- end
131
- ## カレントディレクトリに *.re ファイルがあればエラー
132
- unless Dir.glob('*.re').empty?
133
- re_file = Dir.glob('*.re').sort.first
134
- abort_with_message <<END
135
- ERROR: File '#{re_file}' found in current directory.
136
- When 'contentdir:' specifieid in config file,
137
- you must put all *.re files into that directory.
138
- Please remove *.re files from current directory.
139
- END
140
- end
141
- ## contentdir にある *.re ファイルをカレントディレクトリにコピー
142
- cp Dir.glob(File.join(contdir, '*.re')), '.', :verbose=>false
143
- ## コピーしたファイルをRakeプロセス終了時に削除
144
- at_exit { rm_f Dir.glob('*.re'), :verbose=>false }
145
- end
146
- end
147
-
148
- def abort_with_message(error_msg)
149
- $stderr.puts "***"
150
- $stderr.puts error_msg.gsub(/^/, '*** ')
151
- $stderr.puts "***"
152
- abort()
153
- end
154
-
155
-
156
- CLEAN.include([BOOK, BOOK_PDF, BOOK_EPUB, BOOK + '-pdf', BOOK + '-epub', WEBROOT, 'images/_review_math'])
@@ -1,72 +0,0 @@
1
- require 'fileutils'
2
- require 'rake/clean'
3
-
4
- BOOK = 'book'
5
- BOOK_PDF = BOOK + '.pdf'
6
- BOOK_EPUB = BOOK + '.epub'
7
- CONFIG_FILE = 'config.yml'
8
- WEBROOT = 'webroot'
9
-
10
- def build(mode, chapter)
11
- sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp"
12
- mode_ext = { 'html' => 'html', 'latex' => 'tex', 'idgxml' => 'xml' }
13
- FileUtils.mv 'tmp', chapter.gsub(/re\z/, mode_ext[mode])
14
- end
15
-
16
- def build_all(mode)
17
- sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css"
18
- end
19
-
20
- task default: :html_all
21
-
22
- desc 'build html (Usage: rake build re=target.re)'
23
- task :html do
24
- if ENV['re'].nil?
25
- puts 'Usage: rake build re=target.re'
26
- exit
27
- end
28
- build('html', ENV['re'])
29
- end
30
-
31
- desc 'build all html'
32
- task :html_all do
33
- build_all('html')
34
- end
35
-
36
- desc 'preproc all'
37
- task :preproc do
38
- Dir.glob('*.re').each do |file|
39
- sh "review-preproc --replace #{file}"
40
- end
41
- end
42
-
43
- desc 'generate PDF and EPUB file'
44
- task all: %i[pdf epub]
45
-
46
- desc 'generate PDF file'
47
- task pdf: BOOK_PDF
48
-
49
- desc 'generate stagic HTML file for web'
50
- task web: WEBROOT
51
-
52
- desc 'generate EPUB file'
53
- task epub: BOOK_EPUB
54
-
55
- SRC = FileList['*.re'] + [CONFIG_FILE]
56
-
57
- file BOOK_PDF => SRC do
58
- FileUtils.rm_rf [BOOK_PDF, BOOK, BOOK + '-pdf']
59
- sh "review-pdfmaker #{CONFIG_FILE}"
60
- end
61
-
62
- file BOOK_EPUB => SRC do
63
- FileUtils.rm_rf [BOOK_EPUB, BOOK, BOOK + '-epub']
64
- sh "review-epubmaker #{CONFIG_FILE}"
65
- end
66
-
67
- file WEBROOT => SRC do
68
- FileUtils.rm_rf [WEBROOT]
69
- sh "review-webmaker #{CONFIG_FILE}"
70
- end
71
-
72
- CLEAN.include([BOOK, BOOK_PDF, BOOK_EPUB, BOOK + '-pdf', BOOK + '-epub', WEBROOT, 'images/_review_math'])