review-retrovert 0.9.10 → 0.10.0

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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +1 -1
  3. data/.gitignore +0 -1
  4. data/.pinact.yaml +12 -0
  5. data/.ruby-version +1 -1
  6. data/Dockerfile +2 -1
  7. data/Dockerfile.local +13 -0
  8. data/Gemfile.lock +62 -35
  9. data/Makefile +7 -0
  10. data/README.md +2 -1
  11. data/Rakefile +9 -0
  12. data/aqua.yaml +20 -0
  13. data/hooks/post_push +14 -1
  14. data/lib/review/retrovert/cli.rb +10 -2
  15. data/lib/review/retrovert/converter.rb +106 -20
  16. data/lib/review/retrovert/reviewdef.rb +29 -0
  17. data/lib/review/retrovert/sty/review-utbook.cls +7 -0
  18. data/lib/review/retrovert/version.rb +1 -1
  19. data/lib/review/retrovert/yamlconfig.rb +38 -1
  20. data/review-retrovert.gemspec +18 -4
  21. data/zizmor.yml +5 -0
  22. metadata +54 -121
  23. data/.github/FUNDING.yml +0 -4
  24. data/.github/workflows/release.yml +0 -26
  25. data/.github/workflows/retrovert.yml +0 -76
  26. data/testdata/mybook/.gitignore +0 -9
  27. data/testdata/mybook/.textlintrc +0 -11
  28. data/testdata/mybook/README.md +0 -43
  29. data/testdata/mybook/Rakefile +0 -24
  30. data/testdata/mybook/catalog.yml +0 -60
  31. data/testdata/mybook/config-noretrovert.yml +0 -404
  32. data/testdata/mybook/config-retrovert.yml +0 -16
  33. data/testdata/mybook/config-starter.yml +0 -264
  34. data/testdata/mybook/config.yml +0 -404
  35. data/testdata/mybook/contents/00-preface.re +0 -129
  36. data/testdata/mybook/contents/01-install.re +0 -305
  37. data/testdata/mybook/contents/02-tutorial.re +0 -1228
  38. data/testdata/mybook/contents/03-syntax.re +0 -4610
  39. data/testdata/mybook/contents/04-customize.re +0 -1064
  40. data/testdata/mybook/contents/05-faq.re +0 -606
  41. data/testdata/mybook/contents/06-bestpractice.re +0 -1343
  42. data/testdata/mybook/contents/91-compare.re +0 -418
  43. data/testdata/mybook/contents/92-filelist.re +0 -125
  44. data/testdata/mybook/contents/93-background.re +0 -267
  45. data/testdata/mybook/contents/99-postface.re +0 -39
  46. data/testdata/mybook/contents/r0-inner.re +0 -2
  47. data/testdata/mybook/contents/r0-root.re +0 -31
  48. data/testdata/mybook/contents/table.csv +0 -4
  49. data/testdata/mybook/contents/test.txt +0 -1
  50. data/testdata/mybook/css/normalize.css +0 -349
  51. data/testdata/mybook/css/webstyle.css +0 -692
  52. data/testdata/mybook/data/terms.txt +0 -3
  53. data/testdata/mybook/data/words.txt +0 -15
  54. data/testdata/mybook/images/03-syntax/favicon-16x16.png +0 -0
  55. data/testdata/mybook/images/03-syntax/figure_heretop.png +0 -0
  56. data/testdata/mybook/images/03-syntax/index-page.png +0 -0
  57. data/testdata/mybook/images/03-syntax/order-detail.png +0 -0
  58. data/testdata/mybook/images/03-syntax/tw-icon1.jpg +0 -0
  59. data/testdata/mybook/images/03-syntax/tw-icon2.jpg +0 -0
  60. data/testdata/mybook/images/03-syntax/tw-icon3.jpg +0 -0
  61. data/testdata/mybook/images/03-syntax/tw-icon4.jpg +0 -0
  62. data/testdata/mybook/images/04-customize/caption_pagebreak.png +0 -0
  63. data/testdata/mybook/images/04-customize/chaptitlepage_sample.png +0 -0
  64. data/testdata/mybook/images/04-customize/section_decoration_samples.png +0 -0
  65. data/testdata/mybook/images/05-faq/codeblock_rpadding1.png +0 -0
  66. data/testdata/mybook/images/05-faq/codeblock_rpadding2.png +0 -0
  67. data/testdata/mybook/images/05-faq/dummy-image.png +0 -0
  68. data/testdata/mybook/images/06-bestpractice/figure_heretop.png +0 -0
  69. data/testdata/mybook/images/06-bestpractice/font_beramono.png +0 -0
  70. data/testdata/mybook/images/06-bestpractice/heading_design1.png +0 -0
  71. data/testdata/mybook/images/06-bestpractice/heading_design2.png +0 -0
  72. data/testdata/mybook/images/06-bestpractice/margin_book.png +0 -0
  73. data/testdata/mybook/images/06-bestpractice/multiline-title.png +0 -0
  74. data/testdata/mybook/images/06-bestpractice/preface_numbered.png +0 -0
  75. data/testdata/mybook/images/06-bestpractice/program_border.png +0 -0
  76. data/testdata/mybook/images/06-bestpractice/sechead_design_4.png +0 -0
  77. data/testdata/mybook/images/06-bestpractice/section_title_wlines.png +0 -0
  78. data/testdata/mybook/images/06-bestpractice/titlepage-samples.png +0 -0
  79. data/testdata/mybook/images/93-background/bug913.png +0 -0
  80. data/testdata/mybook/images/93-background/slide2.png +0 -0
  81. data/testdata/mybook/images/avatar-b.png +0 -0
  82. data/testdata/mybook/images/avatar-g.png +0 -0
  83. data/testdata/mybook/images/avatar-r.png +0 -0
  84. data/testdata/mybook/images/caution-icon.png +0 -0
  85. data/testdata/mybook/images/cover_a5.pdf +0 -0
  86. data/testdata/mybook/images/cover_b5.pdf +0 -0
  87. data/testdata/mybook/images/info-icon.png +0 -0
  88. data/testdata/mybook/images/tw-icon.jpg +0 -0
  89. data/testdata/mybook/images/warning-icon.png +0 -0
  90. data/testdata/mybook/layouts/layout.epub.erb +0 -29
  91. data/testdata/mybook/layouts/layout.html5.erb +0 -108
  92. data/testdata/mybook/layouts/layout.tex.erb +0 -432
  93. data/testdata/mybook/layouts/layout.tex.erb.orig +0 -386
  94. data/testdata/mybook/lib/hooks/beforetexcompile.rb +0 -55
  95. data/testdata/mybook/lib/ruby/review-book.rb +0 -64
  96. data/testdata/mybook/lib/ruby/review-builder.rb +0 -1342
  97. data/testdata/mybook/lib/ruby/review-cli.rb +0 -58
  98. data/testdata/mybook/lib/ruby/review-compiler.rb +0 -1176
  99. data/testdata/mybook/lib/ruby/review-epubbuilder.rb +0 -33
  100. data/testdata/mybook/lib/ruby/review-epubmaker.rb +0 -609
  101. data/testdata/mybook/lib/ruby/review-htmlbuilder.rb +0 -949
  102. data/testdata/mybook/lib/ruby/review-latexbuilder.rb +0 -1065
  103. data/testdata/mybook/lib/ruby/review-maker.rb +0 -346
  104. data/testdata/mybook/lib/ruby/review-markdownbuilder.rb +0 -945
  105. data/testdata/mybook/lib/ruby/review-markdownmaker.rb +0 -91
  106. data/testdata/mybook/lib/ruby/review-monkeypatch.rb +0 -93
  107. data/testdata/mybook/lib/ruby/review-pdfmaker.rb +0 -546
  108. data/testdata/mybook/lib/ruby/review-textbuilder.rb +0 -36
  109. data/testdata/mybook/lib/ruby/review-tocparser.rb +0 -285
  110. data/testdata/mybook/lib/ruby/review-webmaker.rb +0 -448
  111. data/testdata/mybook/lib/tasks/mytasks.rake +0 -31
  112. data/testdata/mybook/lib/tasks/review.rake +0 -156
  113. data/testdata/mybook/lib/tasks/review.rake.orig +0 -72
  114. data/testdata/mybook/lib/tasks/starter.rake +0 -470
  115. data/testdata/mybook/locale.yml +0 -6
  116. data/testdata/mybook/review-ext.rb +0 -206
  117. data/testdata/mybook/sty/indexstyle.ist +0 -25
  118. data/testdata/mybook/sty/jumoline.sty +0 -310
  119. data/testdata/mybook/sty/mycolophon.sty +0 -81
  120. data/testdata/mybook/sty/mystyle.sty +0 -8
  121. data/testdata/mybook/sty/mytextsize.sty +0 -90
  122. data/testdata/mybook/sty/mytitlepage.sty +0 -126
  123. data/testdata/mybook/sty/review-base.sty +0 -276
  124. data/testdata/mybook/sty/reviewmacro.sty +0 -60
  125. data/testdata/mybook/sty/starter-codeblock.sty +0 -463
  126. data/testdata/mybook/sty/starter-color.sty +0 -134
  127. data/testdata/mybook/sty/starter-font.sty +0 -112
  128. data/testdata/mybook/sty/starter-heading.sty +0 -561
  129. data/testdata/mybook/sty/starter-misc.sty +0 -894
  130. data/testdata/mybook/sty/starter-note.sty +0 -180
  131. data/testdata/mybook/sty/starter-section.sty +0 -262
  132. data/testdata/mybook/sty/starter-talklist.sty +0 -105
  133. data/testdata/mybook/sty/starter-toc.sty +0 -72
  134. data/testdata/mybook/sty/starter-util.sty +0 -35
  135. data/testdata/mybook/sty/starter.sty +0 -36
  136. data/testdata/mybook/style.css +0 -597
@@ -1,470 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
- WEBSERVER_PORT = 9000
5
-
6
-
7
- ##
8
- ## 生成したファイルを削除
9
- ##
10
- task :clean do
11
- require 'yaml'
12
- config = File.open("config.yml", 'r', encoding: 'utf-8') {|f| YAML.load(f) }
13
- x = config['bookname'] or abort("ERROR: missing 'bookname' in config.yml")
14
- files = [x+".pdf", x+"-pdf", x+".epub", x+"-epub", "webroot"]
15
- files = files.select {|x| File.exist?(x) }
16
- rm_rf files unless files.empty?
17
- end
18
-
19
-
20
-
21
- ##
22
- ## Docker用のタスク。
23
- ##
24
- namespace :docker do
25
-
26
- docker_image = ENV['DOCKER_IMAGE']
27
- docker_image = "kauplan/review2.5" if docker_image.to_s.empty?
28
-
29
- desc "+ pull docker image for building PDF file"
30
- task :setup do
31
- sh "docker pull #{docker_image}"
32
- end
33
-
34
- docker_run = proc do |command, opt=nil|
35
- docker_opts = "--rm -v $PWD:/work -w /work"
36
- docker_opts += ENV.keys().grep(/^STARTER_/).map {|k| " -e #{k}" }.join()
37
- sh "docker run #{docker_opts} #{opt} #{docker_image} #{command}"
38
- end
39
-
40
- desc "+ run 'rake pdf' on docker"
41
- task :pdf do
42
- setup_envvars() # defined in 'review.rake'
43
- docker_run.call('rake pdf')
44
- end
45
-
46
- desc "+ run 'rake pdf:nombre' on docker"
47
- task :'pdf:nombre' do docker_run.call('rake pdf:nombre') end
48
-
49
- desc "+ run 'rake epub' on docker"
50
- task :epub do docker_run.call('rake epub') end
51
-
52
- desc "+ run 'rake web' on docker"
53
- task :web do docker_run.call('rake web') end
54
-
55
- desc "+ run 'rake web:server' on docker"
56
- task :'web:server' do
57
- port = WEBSERVER_PORT
58
- opt = "-it -p #{port}:#{port+1} -e WEBSERVER_PORT=#{port+1}"
59
- docker_run.call('rake web:server', opt)
60
- end
61
-
62
- desc "+ run 'rake markdown' on docker"
63
- task :markdown do docker_run.call('rake markdown') end
64
-
65
- desc "+ run 'rake textlint' on docker"
66
- task :textlint do docker_run.call('rake textlint') end
67
-
68
- desc "+ run 'rake textlint:setup' on docker"
69
- task :'textlint:setup' do docker_run.call('rake textlint:setup') end
70
-
71
- end
72
-
73
-
74
- ##
75
- ## 初期設定
76
- ##
77
- namespace :setup do
78
-
79
- desc "+ install rubygems packages"
80
- task :rubygems do
81
- if ENV['GEM_HOME'].to_s.empty?
82
- ENV['GEM_HOME'] = File.join(Dir.pwd, 'rubygems')
83
- mkdir_p 'rubygems'
84
- end
85
- ruby_version = RUBY_VERSION.split('.').map(&:to_i) # ex: "2.5.0" -> [2, 5, 0]
86
- rubyzip_requires = [2, 4, 0] # rubyzip >= 2.0 requires Ruby >= 2.4
87
- ruby_too_old = (ruby_version <=> rubyzip_requires) < 0
88
- sh "gem install rubyzip --version 1.3" if ruby_too_old
89
- sh "gem install review --version 2.5"
90
- end
91
-
92
- desc "+ download docker image"
93
- task :dockerimage do
94
- sh "docker pull kauplan/review2.5"
95
- end
96
-
97
- end
98
-
99
-
100
- ##
101
- ## Markdownに変換する(主にtextlistを使うため)
102
- ##
103
- desc "+ convert '*.re' files into '*.md'"
104
- task :markdown => :prepare do
105
- require 'review'
106
- require './lib/ruby/review-markdownmaker'
107
- #
108
- setup_envvars() # ex: `c=01-install` => ENV['STARTER_CHAPTER']='01-install'
109
- #
110
- begin
111
- builddir = ReVIEW::MarkdownMaker.execute(config_file())
112
- $_builddir = builddir
113
- rescue RuntimeError => ex
114
- if ex.message =~ /^failed to run command:/
115
- abort "*\n* ERROR (review-pdfmaker):\n* #{ex.message}\n*"
116
- else
117
- raise
118
- end
119
- end
120
- end
121
-
122
-
123
- ##
124
- ## textlintを実行する
125
- ##
126
- task :textlint => :markdown do
127
- builddir = $_builddir
128
- textlint_path = "./node_modules/.bin/textlint"
129
- if File.exist?(textlint_path)
130
- sh "#{textlint_path} #{builddir}/*.md"
131
- else
132
- sh "textlint #{builddir}/*.md"
133
- end
134
- end
135
-
136
-
137
- namespace :textlint do
138
-
139
- ## see:
140
- ## - https://github.com/textlint/textlint
141
- ## - https://github.com/textlint/textlint/wiki/Collection-of-textlint-rule#rule-presets-japanese
142
- task :setup do
143
- require 'json'
144
- rcfile = ".textlintrc"
145
- rcdata = File.open(rcfile, encoding: 'utf-8') {|f| JSON.load(f) }
146
- keys = ['filters', 'rules']
147
- #
148
- failed = false
149
- sh "npm --version" do |ok, _| failed = !ok end
150
- if failed
151
- $stderr.puts <<END
152
- **
153
- ** ERROR: `npm' command not installed.
154
- **
155
- ** Please install Node.js (and npm) at first.
156
- **
157
- END
158
- exit 1
159
- end
160
- #
161
- sh "npm init --yes"
162
- sh "npm install --save-dev textlint"
163
- keys.each do |key|
164
- rcdata[key].each do |name, enabled|
165
- next unless enabled
166
- sh "npm install --save-dev textlint-rule-#{name}"
167
- end if rcdata[key]
168
- end
169
- end
170
-
171
- end
172
-
173
-
174
- ##
175
- ## PDFにノンブルを入れるためのRakeタスク。
176
- ## ノンブルについては「ワンストップ!技術同人誌を書こう」第10章を参照のこと。
177
- ## https://booth.pm/ja/items/708196
178
- ##
179
- namespace :pdf do
180
-
181
- color2rgb = {
182
- 'black' => [0.0, 0.0, 0.0],
183
- 'white' => [1.0, 1.0, 1.0],
184
- 'red' => [1.0, 0.0, 0.0],
185
- 'green' => [0.0, 1.0, 0.0],
186
- 'blue' => [0.0, 0.0, 1.0],
187
- 'cyan' => [0.0, 1.0, 1.0],
188
- 'magenta' => [1.0, 0.0, 1.0],
189
- 'yellow' => [1.0, 1.0, 0.0],
190
- #
191
- 'gray' => [0.50, 0.50, 0.50],
192
- 'darkgray' => [0.25, 0.25, 0.25],
193
- 'lightgray' => [0.75, 0.75, 0.75],
194
- }
195
-
196
- desc "+ add nombre (rake pdf:nombre [file=*.pdf] [out=*.pdf])"
197
- task :nombre do
198
- infile = ENV['file']; infile = nil if infile && infile.empty?
199
- outfile = ENV['out'] ; outfile = nil if outfile && outfile.empty?
200
- #
201
- begin
202
- require 'combine_pdf'
203
- rescue LoadError
204
- abort "ERROR: 'combine_pdf' gem not installed; please run `gem install combine_pdf` at first."
205
- end
206
- #
207
- nombre_opts = proc {
208
- require 'yaml'
209
- conffile = 'config-starter.yml'
210
- confdict = File.open(conffile, encoding: 'utf-8') {|f| YAML.load(f) }
211
- d = confdict['starter']
212
- mm2pt = 72.0 / 25.4 # 1 pt == 1/72 inch, 1 inch == 25.4 mm
213
- {
214
- :start => d['nombre_startnumber'],
215
- :margin_h => d['nombre_bottommargin'].to_f * mm2pt,
216
- :margin_w => d['nombre_sidemargin'].to_f * mm2pt,
217
- :font => nil,
218
- :size => d['nombre_fontsize'].to_i,
219
- :color => color2rgb[d['nombre_fontcolor']],
220
- :binding => nil,
221
- }
222
- }.call()
223
- #
224
- class CombinePDF::PDF
225
- def add_nombre(options={})
226
- start = options[:start] || 1
227
- margin_h = options[:margin_h] || 5
228
- margin_w = options[:margin_w] || 2
229
- font = options[:font] || :Helvetica
230
- size = options[:size] || 6
231
- color = options[:color] || [0.5, 0.5, 0.5] # gray
232
- binding = options[:binding] || :left
233
- digit_w, digit_h = CombinePDF::Fonts.dimensions_of("9", font, size)
234
- box_w = digit_w * 1.2
235
- box_h = digit_h * 1.3
236
- is_left = binding == :left
237
- params = {
238
- x: nil, y: nil, width: box_w, height: box_h,
239
- font: font, font_size: size, font_color: color,
240
- }
241
- self.pages.each.with_index(start) do |page, page_num|
242
- mediabox = page[:CropBox] || page[:MediaBox] or
243
- abort "ERROR: failed to get page size of pdf"
244
- page_w = mediabox[2]
245
- page_h = mediabox[3]
246
- top = page_h - margin_h
247
- bottom = margin_h
248
- left = margin_w
249
- right = page_w - margin_w - box_w
250
- params[:x] = is_left ? left : right
251
- params[:y] = bottom
252
- page_num.to_s.reverse.each_char do |c|
253
- page.textbox(c, params)
254
- params[:y] += box_h
255
- end
256
- is_left = ! is_left
257
- end
258
- self
259
- end
260
- end
261
- #
262
- if infile.nil?
263
- require 'yaml'
264
- config = File.open("config.yml", 'r', encoding: 'utf-8') {|f| YAML.load(f) }
265
- bookname = config['bookname'] or abort("ERROR: missing 'bookname' in config.yml")
266
- infile = bookname + ".pdf"
267
- end
268
- File.file?(infile) or abort("ERROR: #{infile}: pdf file not found.")
269
- if outfile.nil?
270
- #outfile = infile.sub(/\.pdf$/, '_nombre.pdf')
271
- outfile = infile
272
- end
273
- #
274
- #pdf = CombinePDF.parse(File.binread(infile))
275
- #pdf.add_nombre()
276
- #File.binwrite(outfile, pdf.to_pdf())
277
- pdf = CombinePDF.load(infile)
278
- pdf.add_nombre(nombre_opts)
279
- pdf.save(outfile)
280
- end
281
-
282
- end
283
-
284
-
285
- ##
286
- ## プレビュー用のサーバを起動する
287
- ##
288
- namespace :web do
289
-
290
- invoke_web_task = proc do
291
- #sh "rake web"
292
- Process.fork { Rake::Task['web'].invoke() }
293
- Process.wait()
294
- end
295
-
296
- helper_message_when_start_server = <<END
297
- *
298
- * Please open http://localhost:#{WEBSERVER_PORT}/ in browser.
299
- *
300
- END
301
-
302
- helper_message_when_address_already_in_use = <<END
303
- **
304
- ** ERROR: Failed to start web server.
305
- **
306
- ** Other webserver process seems running. Kill it and restart webserver.
307
- **
308
- ** How to:
309
- ** $ ps | head -1; ps | grep web[:]server
310
- ** PID TTY TIME CMD
311
- ** 12345 ttys002 0.00.35 /usr/bin/ruby /usr/bin/rake web:server
312
- ** $ kill -KILL 12345
313
- ** $ rake web:server
314
- **
315
- END
316
-
317
- favicon_base64 = <<END
318
- AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAA
319
- AAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAA
320
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/
321
- /wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//
322
- AAD//wAA//8AAP//AAD//wAA
323
- END
324
-
325
- desc "+ start web server for preview"
326
- task :server do
327
- rebuild_js = (ENV['STARTER_REBUILD_JS'] ||= '/rebuild.js')
328
- invoke_web_task.call()
329
- #
330
- require 'yaml'
331
- config = File.open('config.yml') {|f| YAML.load(f) }
332
- contdir = config['contentdir']
333
- #
334
- require 'webrick'
335
- root = 'webroot/'
336
- host = '0.0.0.0' # don't use '127.0.0.1' to work on Docker
337
- port = ENV['WEBSERVER_PORT'] ? ENV['WEBSERVER_PORT'].to_i : WEBSERVER_PORT
338
- onstart = proc { puts helper_message_when_start_server }
339
- srvconf = {DocumentRoot: root, BindAddress: host, Port: port, StartCallback: onstart}
340
- begin
341
- srv = WEBrick::HTTPServer.new(srvconf)
342
- rescue Errno::EADDRINUSE => ex
343
- at_exit { $stderr.puts helper_message_when_address_already_in_use }
344
- raise
345
- end
346
- #
347
- srv.mount_proc('/favicon.ico') do |req, res|
348
- res.content_type = "image/x-icon"
349
- res['Cache-Control'] = "public, max-age=#{60*60*24}"
350
- res.body = favicon_base64.unpack("m")[0]
351
- end
352
- #
353
- flag_quit = false
354
- interval = 0.8 # seconds
355
- srv.mount_proc(rebuild_js) do |req, res|
356
- file = nil
357
- if req.query_string =~ /\Afile=([^&]*)/
358
- file = $1.strip
359
- file = nil if file.empty?
360
- end
361
- #
362
- errmsg = nil
363
- if file.nil?
364
- # pass
365
- elsif file !~ /\A[-\w]+\.re\z/
366
- errmsg = "invalid file"
367
- else
368
- file = File.join(contdir, file) if contdir
369
- errmsg = "file not found." if ! File.exist?(file)
370
- end
371
- #
372
- if errmsg
373
- body = "alert('ERROR: #{errmsg}');"
374
- else
375
- body = "window.location.reload();"
376
- ## sleep until '*.re' file modified
377
- if file
378
- mtime = File.mtime(file)
379
- sleep interval while !flag_quit && mtime == File.mtime(file)
380
- end
381
- ## generate html file from '*.re'
382
- invoke_web_task.call() unless flag_quit
383
- end
384
- res.content_type = "application/javascript"
385
- msg = "Server seems down. Press OK to reload."
386
- res.body = !flag_quit ? body : "alert('#{msg}');window.location.reload();"
387
- end
388
- #
389
- trap(:INT) { flag_quit = true; srv.shutdown() }
390
- srv.start()
391
- end
392
-
393
- end
394
-
395
-
396
- ##
397
- ## 高解像度用の画像から低解像度の画像を生成するRakeタスク。
398
- ## 詳細は「ワンストップ!技術同人誌を書こう」第8章を参照のこと。
399
- ## https://booth.pm/ja/items/708196
400
- ##
401
- desc "+ convert images (high resolution -> low resolution)"
402
- task :images do
403
- ## macOSならsipsコマンドを使い、それ以外ではImageMagickを使う
404
- has_sips = File.exist?("/usr/bin/sips")
405
- if ! has_sips
406
- ok = system("convert --version >/dev/null")
407
- if ! ok
408
- abort "ERROR: 'convert' command not found; please install ImageMagick."
409
- end
410
- end
411
- ## 高解像度の画像をもとに低解像度の画像を作成する
412
- for src in Dir.glob("images_highres/**/*.{png,jpg,jpeg}")
413
- ## 低解像度の画像を作成済みなら残りの処理をスキップ
414
- dest = src.sub("images_highres/", "images_lowres/")
415
- next if File.exist?(dest) && File.mtime(src) == File.mtime(dest)
416
- ## 必要ならフォルダを作成
417
- dir = File.dirname(dest)
418
- mkdir_p dir if ! File.directory?(dir)
419
- ## 高解像度の画像のDPIを変更(72dpi→360dpi)
420
- if has_sips
421
- sh "sips -s dpiHeight 360 -s dpiWidth 360 #{src}"
422
- else
423
- sh "convert -density 360 -units PixelsPerInch #{src} #{src}"
424
- end
425
- ## 低解像度の画像を作成(72dpi、横幅1/5)
426
- if has_sips
427
- `sips -g pixelWidth #{src}` =~ /pixelWidth: (\d+)/
428
- option = "-s dpiHeight 72 -s dpiWidth 72 --resampleWidth #{$1.to_i / 5}"
429
- sh "sips #{option} --out #{dest} #{src}"
430
- else
431
- sh "convert -density 72 -units PixelsPerInch -resize 20% #{src} #{dest}"
432
- end
433
- ## 低解像度の画像のタイムスタンプを、高解像度の画像と同じにする
434
- ## (=画像のタイムスタンプが違ったら、画像が更新されたと見なす)
435
- File.utime(File.atime(dest), File.mtime(src), dest)
436
- end
437
- ## 高解像度の画像が消されたら、低解像度の画像も消す
438
- for dest in Dir.glob("images_lowres/**/*").sort().reverse()
439
- src = dest.sub("images_lowres/", "images_highres/")
440
- rm_r dest if ! File.exist?(src)
441
- end
442
- end
443
-
444
-
445
- ##
446
- ## 低解像度と高解像度を切り替えるRakeタスク。
447
- ## 詳細は「ワンストップ!技術同人誌を書こう」第8章を参照のこと。
448
- ## https://booth.pm/ja/items/708196
449
- ##
450
- namespace "images" do
451
-
452
- desc "+ toggle image directories ('images_{lowres,highres}')"
453
- task :toggle do
454
- if ! File.symlink?("images")
455
- msg = "ERROR: 'images' directory should be a symbolic link.\n"
456
- msg << " rename it and create symbolic link, for example:\n"
457
- msg << " $ mv images images_highres\n"
458
- msg << " $ ln -s images_highres images\n"
459
- abort msg
460
- end
461
- link = File.readlink("images")
462
- rm "images"
463
- if link == "images_lowres"
464
- ln_s "images_highres", "images"
465
- else
466
- ln_s "images_lowres", "images"
467
- end
468
- end
469
-
470
- end
@@ -1,6 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- locale: ja
3
- #chapter_postfix: " "
4
- chapter_postfix: ""
5
-
6
- equation: 式
@@ -1,206 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ##
4
- ## Re:VIEWを拡張し、インライン命令とブロック命令を追加する
5
- ##
6
-
7
-
8
- require_relative './lib/ruby/review-monkeypatch' ## 諸々の修正(モンキーパッチ)
9
-
10
-
11
- module ReVIEW
12
-
13
- ## インライン命令「@<clearpage>{}」を宣言
14
- Compiler.definline :clearpage ## 改ページ
15
- Compiler.definline :B ## @<strong>{}のショートカット
16
- Compiler.definline :hearts ## ハートマーク
17
- Compiler.definline :TeX ## TeX のロゴマーク
18
- Compiler.definline :LaTeX ## LaTeX のロゴマーク
19
-
20
- ## ブロック命令「//textleft{ ... //}」等を宣言
21
- ## (ここでは第2引数が「0」なので、引数なしのブロック命令になる。
22
- ## もし第2引数が「1..3」なら、//listのように必須引数が1つで
23
- ## 非必須引数が2という意味になる。)
24
- Compiler.defblock :textleft, 0 ## 左寄せ
25
- Compiler.defblock :textright, 0 ## 右寄せ
26
- Compiler.defblock :textcenter, 0 ## 中央揃え
27
- Compiler.defsingle :clearpage, 0 ## 改ページ (\clearpage)
28
- Compiler.defsingle :sampleoutputbegin, 0..1 ## (出力結果開始部、Starterドキュメントで使用)
29
- Compiler.defsingle :sampleoutputend, 0 ## (出力結果終了部、Starterドキュメントで使用)
30
-
31
-
32
- ## LaTeX用の定義
33
- class LATEXBuilder
34
-
35
- ## 改ページ(インライン命令)
36
- def inline_clearpage(str)
37
- '\clearpage'
38
- end
39
-
40
- ## 改ページ(ブロック命令)
41
- def clearpage()
42
- puts ''
43
- puts '\\clearpage'
44
- puts ''
45
- end
46
-
47
- ## @<strong>{} のショートカット
48
- def inline_B(str)
49
- inline_strong(str)
50
- end
51
- def on_inline_B(&b) # nestable
52
- on_inline_strong(&b)
53
- end
54
-
55
- ## ハートマーク
56
- def inline_hearts(str)
57
- '$\heartsuit$'
58
- end
59
-
60
- ## TeXのロゴマーク
61
- def inline_TeX(str)
62
- '\TeX{}'
63
- end
64
-
65
- ## LaTeXのロゴマーク
66
- def inline_LaTeX(str)
67
- '\LaTeX{}'
68
- end
69
-
70
- ## 左寄せ
71
- def textleft(lines)
72
- puts '\begin{flushleft}'
73
- puts lines
74
- puts '\end{flushleft}'
75
- end
76
-
77
- ## 右寄せ
78
- ## (注:Re:VIEWにはすでに //flushright{ ... //} があったので、今後はそちらを推奨)
79
- def textright(lines)
80
- puts '\begin{flushright}'
81
- puts lines
82
- puts '\end{flushright}'
83
- end
84
-
85
- ## 中央揃え
86
- ## (注:Re:VIEWにはすでに //centering{ ... //} があったので、今後はそちらを推奨)
87
- def textcenter(lines)
88
- puts '\begin{center}'
89
- puts lines
90
- puts '\end{center}'
91
- end
92
-
93
- ## 出力結果の開始部と終了部(Starterのドキュメントで使用)
94
- ## (Re:VIEWではブロックの入れ子も「===[xxx]」の入れ子もできないため)
95
- def sampleoutputbegin(caption=nil)
96
- #puts "\\begin{startersampleoutput}" # error in note block
97
- s = caption ? compile_inline(caption) : nil
98
- puts "\\startersampleoutput{#{s}}"
99
- end
100
- def sampleoutputend()
101
- #puts "\\end{startersampleoutput}" # error in note block
102
- puts "\\endstartersampleoutput"
103
- end
104
-
105
- end
106
-
107
-
108
- ## HTML(ePub)用の定義
109
- class HTMLBuilder
110
-
111
- ## 改ページはHTMLにはない
112
- def inline_clearpage(str) # インライン命令
113
- puts '<p></p>'
114
- puts '<hr />'
115
- puts '<p></p>'
116
- end
117
-
118
- def clearpage() # ブロック命令
119
- puts '<p></p>'
120
- puts '<hr />'
121
- puts '<p></p>'
122
- end
123
-
124
- ## @<strong>{} のショートカット
125
- def inline_B(str)
126
- inline_strong(str)
127
- end
128
- def on_inline_B(&b) # nestable
129
- on_inline_strong(&b)
130
- end
131
-
132
- ## ハートマーク
133
- def inline_hearts(str)
134
- #'&hearts;'
135
- '&#9829;'
136
- end
137
-
138
- ## TeXのロゴマーク
139
- def inline_TeX(str)
140
- 'TeX'
141
- end
142
-
143
- ## LaTeXのロゴマーク
144
- def inline_LaTeX(str)
145
- 'LaTeX'
146
- end
147
-
148
- ## 左寄せ
149
- def textleft(lines)
150
- puts '<div style="text-align:left">'
151
- puts lines
152
- puts '</div>'
153
- end
154
-
155
- ## 右寄せ
156
- def textright(lines)
157
- puts '<div style="text-align:right">'
158
- puts lines
159
- puts '</div>'
160
- end
161
-
162
- ## 中央揃え
163
- def textcenter(lines)
164
- puts '<div style="text-align:center">'
165
- puts lines
166
- puts '</div>'
167
- end
168
-
169
- ## 出力結果の開始部と終了部(Starterのドキュメントで使用)
170
- ## (Re:VIEWではブロックの入れ子も「===[xxx]」の入れ子もできないため)
171
- def sampleoutputbegin(caption=nil)
172
- puts "<div class=\"sampleoutput\">"
173
- if caption
174
- s = compile_inline(caption)
175
- puts "<span class=\"caption\">#{caption}</span>"
176
- end
177
- puts "<div class=\"sampleoutput-inner\">"
178
- end
179
- def sampleoutputend()
180
- puts "</div></div>"
181
- end
182
-
183
- end
184
-
185
-
186
- class TEXTBuilder
187
-
188
- ## TeXのロゴマーク
189
- def inline_TeX(str)
190
- 'TeX'
191
- end
192
-
193
- ## LaTeXのロゴマーク
194
- def inline_LaTeX(str)
195
- 'LaTeX'
196
- end
197
-
198
- ## ハートマーク
199
- def inline_hearts(str)
200
- '&hearts;'
201
- end
202
-
203
- end
204
-
205
-
206
- end
@@ -1,25 +0,0 @@
1
- ##
2
- ## LaTeXでの索引生成コマンド mendex (upmendex) の設定
3
- ##
4
-
5
- ## 用語とページ番号との間をピリオドで埋める
6
- delim_0 "\\quad\\dotfill ~"
7
- delim_1 "\\quad\\dotfill ~"
8
- delim_2 "\\quad\\dotfill ~"
9
-
10
- ## 用語とページ番号との間を空白で埋める
11
- #delim_0 "\\quad\\hfill"
12
- #delim_1 "\\quad\\hfill"
13
- #delim_2 "\\quad\\hfill"
14
-
15
- ## 索引に見出しをつける
16
- ## (mendex のデフォルトでは見出しが「あ い う え お か ...」になる。
17
- ## これを「あ か さ た な は ...」にするには、config.yml の
18
- ## `makeindex_options:` オプションに「-g」を含める。)
19
- heading_flag 1
20
- letter_head 2
21
-
22
- ## 見出しを囲うLaTeXコマンド
23
- #heading_prefix "{\\bfseries\\gtfamily\\sffamily ■"
24
- heading_prefix "\\starterindexgroup{"
25
- heading_suffix "}"