rabbit 3.0.0 → 3.0.2

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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -1
  3. data/data/locale/en/LC_MESSAGES/rabbit.mo +0 -0
  4. data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
  5. data/doc/_config.yml +2 -2
  6. data/doc/_layouts/skeleton.html +0 -7
  7. data/doc/en/faq.rd +4 -2
  8. data/doc/en/install/homebrew.rd +8 -13
  9. data/doc/en/news.rd +158 -0
  10. data/doc/en/sample/hiki/rabbit.hiki +0 -4
  11. data/doc/en/sample/rd/rabbit.rd +0 -4
  12. data/doc/en/usage/rabbit-slide.rd +3 -3
  13. data/doc/images/screenshots/en/blue-circle-raw.png +0 -0
  14. data/doc/images/screenshots/en/blue-circle.png +0 -0
  15. data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
  16. data/doc/images/screenshots/en/clear-blue.png +0 -0
  17. data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
  18. data/doc/images/screenshots/en/cozmixng.png +0 -0
  19. data/doc/images/screenshots/en/dark-gradation-raw.png +0 -0
  20. data/doc/images/screenshots/en/dark-gradation.png +0 -0
  21. data/doc/images/screenshots/en/day-white-raw.png +0 -0
  22. data/doc/images/screenshots/en/day-white.png +0 -0
  23. data/doc/images/screenshots/en/debian-raw.png +0 -0
  24. data/doc/images/screenshots/en/debian.png +0 -0
  25. data/doc/images/screenshots/en/green-circle-raw.png +0 -0
  26. data/doc/images/screenshots/en/green-circle.png +0 -0
  27. data/doc/images/screenshots/en/night-black-raw.png +0 -0
  28. data/doc/images/screenshots/en/night-black.png +0 -0
  29. data/doc/images/screenshots/en/rabbit-raw.png +0 -0
  30. data/doc/images/screenshots/en/rabbit.png +0 -0
  31. data/doc/images/screenshots/en/ranguba-raw.png +0 -0
  32. data/doc/images/screenshots/en/ranguba.png +0 -0
  33. data/doc/images/screenshots/en/red-frame-raw.png +0 -0
  34. data/doc/images/screenshots/en/red-frame.png +0 -0
  35. data/doc/images/screenshots/en/ruby-gnome2-raw.png +0 -0
  36. data/doc/images/screenshots/en/ruby-gnome2.png +0 -0
  37. data/doc/images/screenshots/en/rubykaigi2011-raw.png +0 -0
  38. data/doc/images/screenshots/en/rubykaigi2011.png +0 -0
  39. data/doc/images/screenshots/ja/blue-circle-raw.png +0 -0
  40. data/doc/images/screenshots/ja/blue-circle.png +0 -0
  41. data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
  42. data/doc/images/screenshots/ja/clear-blue.png +0 -0
  43. data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
  44. data/doc/images/screenshots/ja/cozmixng.png +0 -0
  45. data/doc/images/screenshots/ja/dark-gradation-raw.png +0 -0
  46. data/doc/images/screenshots/ja/dark-gradation.png +0 -0
  47. data/doc/images/screenshots/ja/day-white-raw.png +0 -0
  48. data/doc/images/screenshots/ja/day-white.png +0 -0
  49. data/doc/images/screenshots/ja/debian-raw.png +0 -0
  50. data/doc/images/screenshots/ja/debian.png +0 -0
  51. data/doc/images/screenshots/ja/green-circle-raw.png +0 -0
  52. data/doc/images/screenshots/ja/green-circle.png +0 -0
  53. data/doc/images/screenshots/ja/night-black-raw.png +0 -0
  54. data/doc/images/screenshots/ja/night-black.png +0 -0
  55. data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
  56. data/doc/images/screenshots/ja/rabbit.png +0 -0
  57. data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
  58. data/doc/images/screenshots/ja/ranguba.png +0 -0
  59. data/doc/images/screenshots/ja/red-frame-raw.png +0 -0
  60. data/doc/images/screenshots/ja/red-frame.png +0 -0
  61. data/doc/images/screenshots/ja/ruby-gnome2-raw.png +0 -0
  62. data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
  63. data/doc/images/screenshots/ja/rubykaigi2011-raw.png +0 -0
  64. data/doc/images/screenshots/ja/rubykaigi2011.png +0 -0
  65. data/doc/index.html.en +1 -1
  66. data/doc/ja/faq.rd +2 -0
  67. data/doc/ja/install/homebrew.rd +8 -12
  68. data/doc/ja/news.rd +157 -0
  69. data/doc/ja/sample/hiki/rabbit.hiki +0 -4
  70. data/doc/ja/sample/rd/rabbit.rd +0 -4
  71. data/doc/ja/usage/rabbit-slide.rd +3 -3
  72. data/doc/ja/users.rd +7 -0
  73. data/lib/rabbit/action/toggle.rb +7 -0
  74. data/lib/rabbit/author-configuration.rb +3 -4
  75. data/lib/rabbit/canvas.rb +18 -6
  76. data/lib/rabbit/command/rabbit-slide.rb +59 -1
  77. data/lib/rabbit/command/rabbit-slide.ui +127 -49
  78. data/lib/rabbit/command/rabbit.rb +5 -9
  79. data/lib/rabbit/element/base.rb +1 -5
  80. data/lib/rabbit/element/image.rb +139 -89
  81. data/lib/rabbit/element/video.rb +3 -11
  82. data/lib/rabbit/error.rb +9 -3
  83. data/lib/rabbit/formatter.rb +1 -1
  84. data/lib/rabbit/frame.rb +102 -4
  85. data/lib/rabbit/gem-pusher.rb +29 -6
  86. data/lib/rabbit/image/base.rb +163 -28
  87. data/lib/rabbit/image/dia.rb +21 -14
  88. data/lib/rabbit/image/mermaid.rb +73 -0
  89. data/lib/rabbit/image/pdf.rb +22 -9
  90. data/lib/rabbit/image/svg.rb +1 -4
  91. data/lib/rabbit/image.rb +6 -6
  92. data/lib/rabbit/info-window.rb +106 -80
  93. data/lib/rabbit/keys.rb +6 -0
  94. data/lib/rabbit/menu.rb +2 -0
  95. data/lib/rabbit/parser/base.rb +2 -1
  96. data/lib/rabbit/parser/ext/blockdiag.rb +16 -14
  97. data/lib/rabbit/parser/ext/charty.rb +58 -0
  98. data/lib/rabbit/parser/ext/image.rb +38 -10
  99. data/lib/rabbit/parser/markdown/converter.rb +36 -30
  100. data/lib/rabbit/parser/rd/ext/block-verbatim.rb +33 -35
  101. data/lib/rabbit/parser/rd/ext/image.rb +23 -4
  102. data/lib/rabbit/parser/rd/rd2rabbit-lib.rb +3 -1
  103. data/lib/rabbit/parser/rd.rb +1 -1
  104. data/lib/rabbit/parser/wiki/output.rb +9 -9
  105. data/lib/rabbit/parser.rb +2 -2
  106. data/lib/rabbit/progress.rb +1 -1
  107. data/lib/rabbit/properties.rb +154 -0
  108. data/lib/rabbit/rabbit.rb +3 -1
  109. data/lib/rabbit/relative-size.rb +28 -0
  110. data/lib/rabbit/renderer/base.rb +6 -0
  111. data/lib/rabbit/renderer/display/drawing-area-base.rb +1 -2
  112. data/lib/rabbit/renderer/display/drawing-area-primitive.rb +1 -0
  113. data/lib/rabbit/renderer/display/info.rb +6 -1
  114. data/lib/rabbit/renderer/display/key-handler.rb +27 -2
  115. data/lib/rabbit/renderer/engine/cairo.rb +24 -3
  116. data/lib/rabbit/renderer/screen.rb +0 -1
  117. data/lib/rabbit/slide-configuration.rb +16 -8
  118. data/lib/rabbit/task/slide.rb +6 -33
  119. data/lib/rabbit/theme/background-image-toolkit/background-image-toolkit.rb +38 -0
  120. data/lib/rabbit/theme/clear-blue/clear-blue.rb +4 -2
  121. data/lib/rabbit/theme/edge-info-toolkit/edge-info-toolkit.rb +12 -2
  122. data/lib/rabbit/theme/image/image.rb +3 -0
  123. data/lib/rabbit/theme/image-slide-number/image-slide-number.rb +8 -3
  124. data/lib/rabbit/theme/image-timer/image-timer.rb +8 -3
  125. data/lib/rabbit/theme/pdf/pdf.rb +1 -1
  126. data/lib/rabbit/theme/slide-footer-info/slide-footer-info.rb +2 -0
  127. data/lib/rabbit/theme/tag/tag.rb +9 -2
  128. data/lib/rabbit/theme-configuration.rb +3 -4
  129. data/lib/rabbit/utils.rb +25 -2
  130. data/lib/rabbit/version.rb +2 -2
  131. data/lib/rabbit/video-window.rb +14 -3
  132. data/{test/test-slideshare.rb → lib/rabbit/yaml-loader.rb} +20 -15
  133. data/po/en/rabbit.edit.po +123 -121
  134. data/po/en/rabbit.po +28 -26
  135. data/po/fr/rabbit.edit.po +122 -120
  136. data/po/fr/rabbit.po +27 -25
  137. data/po/ja/rabbit.edit.po +156 -125
  138. data/po/ja/rabbit.po +34 -30
  139. data/rabbit.gemspec +0 -1
  140. data/sample/can_rabbit.rd +0 -24
  141. data/sample/rabbit-en.hiki +0 -4
  142. data/sample/rabbit-en.md +13 -0
  143. data/sample/rabbit-en.rd +10 -4
  144. data/sample/rabbit.hiki +0 -4
  145. data/sample/rabbit.md +21 -0
  146. data/sample/rabbit.rd +20 -4
  147. data/test/command/test-rabbit.rb +1 -0
  148. data/test/parser/test-markdown.rb +2 -2
  149. data/test/test-slide-configuration.rb +4 -2
  150. metadata +30 -46
  151. data/doc/css/jquery-ui/themes/ui-lightness.css +0 -573
  152. data/doc/javascripts/jquery-ui.js +0 -11544
  153. data/doc/javascripts/jquery.js +0 -7179
  154. data/lib/rabbit/slideshare.rb +0 -192
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2007-2018 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2007-2022 Sutou Kouhei <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -27,31 +27,58 @@ module Rabbit
27
27
  module Ext
28
28
  module Image
29
29
  module_function
30
- def make_image(canvas, uri_str, prop={})
30
+ def make_image(canvas, uri_str, prop={}, body: nil)
31
31
  path = Private.uri_string_to_image_filename(canvas, uri_str)
32
32
  begin
33
- Element::Image.new(path, prop)
33
+ image = Element::Image.new(path, prop, canvas: canvas)
34
34
  rescue Error
35
35
  canvas.logger.warn($!.message)
36
36
  nil
37
+ else
38
+ if prop["align"] == "right" and body
39
+ if body["background-image"]
40
+ raise ParseError,
41
+ _("multiple right aligns aren't supported.")
42
+ end
43
+ prop.each do |name, value|
44
+ name = name.gsub(/_/, "-")
45
+ next if name == "src"
46
+ property_name = "background-image-#{name}"
47
+ body[property_name] = value
48
+ end
49
+ body["background-image"] = uri_str
50
+ :no_element
51
+ else
52
+ image
53
+ end
37
54
  end
38
55
  end
39
56
 
40
- def make_image_from_file(canvas, source)
41
- src_file = Tempfile.new("rabbit-image-source")
57
+ def make_image_from_file(canvas, source, extension: nil, **options)
58
+ src_basename = "rabbit-image-source"
59
+ src_basename = [src_basename, extension] if extension
60
+ src_file = Tempfile.new(src_basename)
42
61
  src_file.open
43
62
  src_file.print(source)
44
63
  src_file.close
45
64
  image_file = prop = nil
46
65
  begin
47
- image_file, prop = yield(src_file.path)
66
+ image_file, prop = yield(src_file)
48
67
  rescue ImageLoadError
49
68
  canvas.logger.warn($!.message)
50
69
  end
51
70
  return nil if image_file.nil?
52
- image = make_image(canvas, %Q[file://#{image_file.path}], prop)
53
- return nil if image.nil?
54
- image["_src"] = image_file # for protecting from GC
71
+ image = make_image(canvas,
72
+ "file://#{image_file.path}",
73
+ prop,
74
+ **options)
75
+ # Protect image from GC
76
+ case image
77
+ when Element::Image
78
+ image["_src"] = image_file
79
+ when :no_element
80
+ options[:body]["_background-image-src"] = image_file
81
+ end
55
82
  image
56
83
  end
57
84
 
@@ -108,8 +135,9 @@ module Rabbit
108
135
  end
109
136
 
110
137
  def setup_image_file(canvas, uri, filename)
138
+ return if File.exist?(filename)
111
139
  begin
112
- open(uri, "rb") do |in_file|
140
+ URI.open(uri, "rb") do |in_file|
113
141
  File.open(filename, "wb") do |out|
114
142
  out.print(in_file.read)
115
143
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2017 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2012-2022 Sutou Kouhei <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -20,8 +20,8 @@ require "rabbit/gettext"
20
20
  require "rabbit/parser/pause-support"
21
21
  require "rabbit/parser/ext/blockdiag"
22
22
  require "rabbit/parser/ext/escape"
23
- require "rabbit/parser/ext/inline"
24
23
  require "rabbit/parser/ext/image"
24
+ require "rabbit/parser/ext/inline"
25
25
  require "rabbit/parser/ext/rouge"
26
26
  require "rabbit/parser/ext/tex"
27
27
 
@@ -165,9 +165,15 @@ module Rabbit
165
165
  if child_types == [:img]
166
166
  convert_container(element)[0]
167
167
  else
168
- if child_types.include?(:img)
168
+ if child_types.count(:img) > 1
169
169
  raise ParseError,
170
- _("multiple ![alt]{image} in a paragraph isn't supported.")
170
+ _("multiple ![alt]{image}s in a paragraph isn't supported.")
171
+ end
172
+ if child_types.include?(:img)
173
+ message =
174
+ _("![alt]{image} and other contents in a paragraph " \
175
+ "isn't supported: %{types}")
176
+ raise ParseError, message % {types: child_types}
171
177
  end
172
178
  if element.options[:transparent] and child_types == [:text]
173
179
  element.children.first.value.chomp!
@@ -325,12 +331,14 @@ module Rabbit
325
331
  def convert_codeblock_language(element, language, content)
326
332
  case language
327
333
  when "blockdiag"
328
- args = [@canvas, content]
329
- Ext::Image.make_image_from_file(*args) do |src_file_path|
330
- [
331
- Ext::BlockDiag.make_image(src_file_path, element.attr, @canvas),
332
- element.attr,
333
- ]
334
+ make_image_from_file(element, content) do |src_file, prop|
335
+ Ext::BlockDiag.make_image(src_file.path, prop, @canvas)
336
+ end
337
+ when "mermaid"
338
+ make_image_from_file(element,
339
+ content,
340
+ extension: ".mmd") do |src_file, prop|
341
+ src_file
334
342
  end
335
343
  else
336
344
  logger = @canvas.logger
@@ -349,23 +357,11 @@ module Rabbit
349
357
  alt = options.delete("alt")
350
358
  caption = title || alt
351
359
  options["caption"] ||= caption if caption
352
- if options["align"] == "right"
353
- body = @slides.last.body
354
- if body["background-image"]
355
- raise ParseError,
356
- _("multiple ![]('XXX.png'){:align='right'} " + \
357
- "isn't supported.")
358
- end
359
- body["background-image"] = uri
360
- options.each do |name, value|
361
- name = name.to_s.gsub(/_/, "-")
362
- body["background-image-#{name}"] = value
363
- end
364
- :no_element
365
- else
366
- image = Ext::Image.make_image(@canvas, uri, options)
367
- image || text(alt || src)
368
- end
360
+ image = Ext::Image.make_image(@canvas,
361
+ uri,
362
+ options,
363
+ body: @slides.last.body)
364
+ image || text(alt || src)
369
365
  end
370
366
 
371
367
  def convert_em(element)
@@ -376,10 +372,20 @@ module Rabbit
376
372
  Emphasis.new(Emphasis.new(convert_container(element)))
377
373
  end
378
374
 
375
+ def make_image_from_file(element, source, **options)
376
+ Ext::Image.make_image_from_file(@canvas,
377
+ source,
378
+ body: @slides.last.body,
379
+ **options) do |src_file|
380
+ prop = element.attr
381
+ image = yield(src_file, prop)
382
+ [image, prop]
383
+ end
384
+ end
385
+
379
386
  def convert_math(element)
380
- args = [@canvas, element.value]
381
- Ext::Image.make_image_from_file(*args) do |src_file_path|
382
- [Ext::TeX.make_image_by_LaTeX(src_file_path, {}, @canvas), {}]
387
+ make_image_from_file(element, element.value) do |src_file, prop|
388
+ Ext::TeX.make_image_by_LaTeX(src_file.path, prop, @canvas)
383
389
  end
384
390
  end
385
391
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2004-2017 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2004-2022 Sutou Kouhei <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -22,13 +22,14 @@ require "rabbit/parser/rd/rt/rt2rabbit-lib"
22
22
  require "rabbit/parser/rd/ext/base"
23
23
  require "rabbit/parser/rd/ext/image"
24
24
  require "rabbit/parser/rd/ext/video"
25
- require "rabbit/parser/ext/enscript"
26
- require "rabbit/parser/ext/tex"
27
25
  require "rabbit/parser/ext/aafigure"
28
26
  require "rabbit/parser/ext/blockdiag"
27
+ require "rabbit/parser/ext/charty"
29
28
  require "rabbit/parser/ext/coderay"
30
29
  require "rabbit/parser/ext/emacs"
30
+ require "rabbit/parser/ext/enscript"
31
31
  require "rabbit/parser/ext/rouge"
32
+ require "rabbit/parser/ext/tex"
32
33
 
33
34
  module Rabbit
34
35
  module Parser
@@ -54,26 +55,7 @@ module Rabbit
54
55
  return nil unless /\A(?:image|img)\z/i =~ label
55
56
  src, prop = parse_source(source)
56
57
  return nil if prop["src"].nil?
57
-
58
- if prop["align"] == "right"
59
- body = visitor.current_body
60
- if body["background-image"]
61
- raise ParseError,
62
- _("multiple 'align = right' isn't supported.")
63
- end
64
- prop.each do |name, value|
65
- name = name.gsub(/_/, "-")
66
- if name == "src"
67
- property_name = "background-image"
68
- else
69
- property_name = "background-image-#{name}"
70
- end
71
- body[property_name] = value
72
- end
73
- :no_element
74
- else
75
- make_image(visitor, prop["src"], prop)
76
- end
58
+ make_image(visitor, prop["src"], prop, body: visitor.current_body)
77
59
  end
78
60
 
79
61
  def ext_block_verb_video(label, source, content, visitor)
@@ -86,7 +68,7 @@ module Rabbit
86
68
 
87
69
  def ext_block_verb_enscript(label, source, content, visitor)
88
70
  return nil unless /\Aenscript (\w+)\z/i =~ label
89
- lang = $1.downcase.untaint
71
+ lang = $1.downcase
90
72
 
91
73
  src, prop = parse_source(source)
92
74
  logger = visitor.logger
@@ -100,36 +82,36 @@ module Rabbit
100
82
 
101
83
  def ext_block_verb_LaTeX(label, source, content, visitor)
102
84
  return nil unless /\ALaTeX\z/i =~ label
103
- make_image_from_file(source, visitor) do |src_file_path, prop|
104
- Parser::Ext::TeX.make_image_by_LaTeX(src_file_path, prop, visitor)
85
+ make_image_from_file(source, visitor) do |src_file, prop|
86
+ Parser::Ext::TeX.make_image_by_LaTeX(src_file.path, prop, visitor)
105
87
  end
106
88
  end
107
89
 
108
90
  def ext_block_verb_mimeTeX(label, source, content, visitor)
109
91
  return nil unless /\AmimeTeX\z/i =~ label
110
- make_image_from_file(source, visitor) do |src_file_path, prop|
111
- Parser::Ext::TeX.make_image_by_mimeTeX(src_file_path, prop,
92
+ make_image_from_file(source, visitor) do |src_file, prop|
93
+ Parser::Ext::TeX.make_image_by_mimeTeX(src_file.path, prop,
112
94
  visitor)
113
95
  end
114
96
  end
115
97
 
116
98
  def ext_block_verb_aafigure(label, source, content, visitor)
117
99
  return nil unless /\Aaafigure\z/i =~ label
118
- make_image_from_file(source, visitor) do |src_file_path, prop|
119
- Parser::Ext::AAFigure.make_image(src_file_path, prop, visitor)
100
+ make_image_from_file(source, visitor) do |src_file, prop|
101
+ Parser::Ext::AAFigure.make_image(src_file.path, prop, visitor)
120
102
  end
121
103
  end
122
104
 
123
105
  def ext_block_verb_blockdiag(label, source, content, visitor)
124
106
  return nil unless /\Ablockdiag\z/i =~ label
125
- make_image_from_file(source, visitor) do |src_file_path, prop|
126
- Parser::Ext::BlockDiag.make_image(src_file_path, prop, visitor)
107
+ make_image_from_file(source, visitor) do |src_file, prop|
108
+ Parser::Ext::BlockDiag.make_image(src_file.path, prop, visitor)
127
109
  end
128
110
  end
129
111
 
130
112
  def ext_block_verb_coderay(label, source, content, visitor)
131
113
  return nil unless /\Acoderay (\w+)\z/i =~ label
132
- lang = $1.downcase.untaint
114
+ lang = $1.downcase
133
115
 
134
116
  src, prop = parse_source(source)
135
117
  logger = visitor.logger
@@ -140,7 +122,7 @@ module Rabbit
140
122
 
141
123
  def ext_block_verb_emacs(label, source, content, visitor)
142
124
  return nil unless /\Aemacs(?:\s+(.+))?\z/i =~ label
143
- mode_line = $1.untaint
125
+ mode_line = $1
144
126
 
145
127
  src, prop = parse_source(source)
146
128
  logger = visitor.logger
@@ -193,7 +175,7 @@ module Rabbit
193
175
 
194
176
  def ext_block_verb_rouge(label, source, content, visitor)
195
177
  return nil unless /\Arouge (\w+)\z/i =~ label
196
- lang = $1.downcase.untaint
178
+ lang = $1.downcase
197
179
 
198
180
  src, prop = parse_source(source)
199
181
  logger = visitor.logger
@@ -201,6 +183,22 @@ module Rabbit
201
183
  result = Parser::Ext::Rouge.highlight(lang, src, logger)
202
184
  result || default_ext_block_verbatim(label, src, src, visitor)
203
185
  end
186
+
187
+ def ext_block_verb_charty(label, source, content, visitor)
188
+ return nil unless /\Acharty\z/i =~ label
189
+ make_image_from_file(source, visitor) do |src_file, prop|
190
+ Parser::Ext::Charty.make_image(src_file.path, prop, visitor)
191
+ end
192
+ end
193
+
194
+ def ext_block_verb_mermaid(label, source, content, visitor)
195
+ return nil unless /\Amermaid\z/i =~ label
196
+ make_image_from_file(source,
197
+ visitor,
198
+ extension: ".mmd") do |src_file, prop|
199
+ src_file
200
+ end
201
+ end
204
202
  end
205
203
  end
206
204
  end
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2004-2022 Sutou Kouhei <kou@cozmixng.org>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require 'rabbit/element'
2
18
  require 'rabbit/parser/ext/image'
3
19
 
@@ -11,13 +27,16 @@ module Rabbit
11
27
  def img(label, content, visitor)
12
28
  label = label.to_s
13
29
  return nil unless /^img:\s*(.+)$/ =~ label
14
- make_image(visitor.canvas, $1)
30
+ make_image(visitor.canvas, $1, body: visitor.current_body)
15
31
  end
16
32
 
17
- def make_image_from_file(source, visitor)
33
+ def make_image_from_file(source, visitor, **options)
18
34
  src, prop = parse_source(source)
19
- super(visitor.canvas, src) do |src_file_path|
20
- [yield(src_file_path, prop), prop]
35
+ super(visitor.canvas,
36
+ src,
37
+ body: visitor.current_body,
38
+ **options) do |src_file|
39
+ [yield(src_file, prop), prop]
21
40
  end
22
41
  end
23
42
  end
@@ -56,8 +56,10 @@ module Rabbit
56
56
  def_delegators(:@canvas, :logger, :full_path, :tmp_dir_name)
57
57
 
58
58
  attr_reader :canvas
59
- def initialize(canvas)
59
+ attr_reader :progress
60
+ def initialize(canvas, progress)
60
61
  @canvas = canvas
62
+ @progress = progress
61
63
 
62
64
  @slides = []
63
65
  @slide = nil
@@ -38,7 +38,7 @@ module Rabbit
38
38
  source = @source.read.gsub(/\r\n/, "\n")
39
39
  source = "=begin\n#{source}\n=end\n"
40
40
  tree = ::RD::RDTree.new(source)
41
- visitor = RD2RabbitVisitor.new(@canvas)
41
+ visitor = RD2RabbitVisitor.new(@canvas, @progress)
42
42
  visitor.visit(tree)
43
43
  rescue Racc::ParseError
44
44
  message = format_parse_error_message($!.message, source)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2007-2017 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2007-2022 Sutou Kouhei <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -489,9 +489,9 @@ module Rabbit
489
489
 
490
490
  def LaTeX(source, props={})
491
491
  args = [@output.canvas, source]
492
- Ext::Image.make_image_from_file(*args) do |src_file_path|
492
+ Ext::Image.make_image_from_file(*args) do |src_file|
493
493
  props = Utils.stringify_hash_key(props)
494
- args = [src_file_path, props, @output.canvas]
494
+ args = [src_file.path, props, @output.canvas]
495
495
  [Ext::TeX.make_image_by_LaTeX(*args), props]
496
496
  end
497
497
  end
@@ -499,9 +499,9 @@ module Rabbit
499
499
 
500
500
  def mimeTeX(source, props={})
501
501
  args = [@output.canvas, source]
502
- Ext::Image.make_image_from_file(*args) do |src_file_path|
502
+ Ext::Image.make_image_from_file(*args) do |src_file|
503
503
  props = Utils.stringify_hash_key(props)
504
- args = [src_file_path, props, @output.canvas]
504
+ args = [src_file.path, props, @output.canvas]
505
505
  [Ext::TeX.make_image_by_mimeTeX(*args), props]
506
506
  end
507
507
  end
@@ -509,18 +509,18 @@ module Rabbit
509
509
 
510
510
  def aafigure(source, props={})
511
511
  args = [@output.canvas, source]
512
- Ext::Image.make_image_from_file(*args) do |src_file_path|
512
+ Ext::Image.make_image_from_file(*args) do |src_file|
513
513
  props = Utils.stringify_hash_key(props)
514
- args = [src_file_path, props, @output.canvas]
514
+ args = [src_file.path, props, @output.canvas]
515
515
  [Ext::AAFigure.make_image(*args), props]
516
516
  end
517
517
  end
518
518
 
519
519
  def blockdiag(source, props={})
520
520
  args = [@output.canvas, source]
521
- Ext::Image.make_image_from_file(*args) do |src_file_path|
521
+ Ext::Image.make_image_from_file(*args) do |src_file|
522
522
  props = Utils.stringify_hash_key(props)
523
- args = [src_file_path, props, @output.canvas]
523
+ args = [src_file.path, props, @output.canvas]
524
524
  [Ext::BlockDiag.make_image(*args), props]
525
525
  end
526
526
  end
data/lib/rabbit/parser.rb CHANGED
@@ -25,7 +25,7 @@ module Rabbit
25
25
  include GetText
26
26
 
27
27
  module_function
28
- def parse(canvas, source)
28
+ def parse(canvas, source, **options)
29
29
  parser = Base.find_loader(source)
30
30
  if parser.nil?
31
31
  format = _("unsupported format. (supported: %s)")
@@ -35,7 +35,7 @@ module Rabbit
35
35
  message = format % "[#{format_names.join(', ')}]"
36
36
  raise UnsupportedFormatError.new(message)
37
37
  end
38
- parser.new(canvas, source).parse
38
+ parser.new(canvas, source, **options).parse
39
39
  end
40
40
 
41
41
  def normalize_property_name(name)
@@ -92,7 +92,7 @@ trough {
92
92
  provider = Gtk::CssProvider.new
93
93
  provider.load(:data => css)
94
94
  @bar.style_context.add_provider(provider,
95
- Gtk::StyleProvider::PRIORITY_USER)
95
+ Gtk::StyleProvider::PRIORITY_USER)
96
96
  end
97
97
  end
98
98
  end
@@ -0,0 +1,154 @@
1
+ # Copyright (C) 2020-2021 Sutou Kouhei <kou@cozmixng.org>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ require "rabbit/relative-size"
18
+ require "rabbit/yaml-loader"
19
+
20
+ module Rabbit
21
+ class Properties
22
+ include Enumerable
23
+
24
+ def initialize(data)
25
+ @data = normalize(data)
26
+ end
27
+
28
+ def [](key)
29
+ @data[normalize_key(key)]
30
+ end
31
+
32
+ def []=(key, value)
33
+ @data[normalize_key(key)] = value
34
+ end
35
+
36
+ def each(&block)
37
+ @data.each(&block)
38
+ end
39
+
40
+ def get_boolean(key, default=nil)
41
+ value = self[key]
42
+ return default if value.nil?
43
+ true_value?(value)
44
+ end
45
+
46
+ def get_integer(key, default=nil)
47
+ integer_value(self[key] || default)
48
+ end
49
+
50
+ def get_float(key, default=nil)
51
+ float_value(self[key] || default)
52
+ end
53
+
54
+ def get_size(key, filename, default=nil)
55
+ size_value(self[key] || default, filename, key)
56
+ end
57
+
58
+ def get_relative_size(key, filename, default=nil)
59
+ relative_size_value(self[key] || default,
60
+ filename,
61
+ key)
62
+ end
63
+
64
+ def draws
65
+ targets = @data.select do |key, _|
66
+ /\Adraw\d+\z/.match?(key)
67
+ end
68
+ targets = targets.sort_by do |key, _|
69
+ Integer(key[/\d+/], 10)
70
+ end
71
+ targets.collect do |_, value|
72
+ YAMLLoader.load(value)
73
+ end
74
+ end
75
+
76
+ def respond_to_missing?(name, include_private)
77
+ @data.key?(normalize_key(name.to_s.gsub(/\?\z/, "")))
78
+ end
79
+
80
+ def method_missing(name, *args, &block)
81
+ case args.size
82
+ when 0
83
+ key = name.to_s
84
+ if key.end_with?("?")
85
+ key = key[0..-2]
86
+ is_predict = true
87
+ else
88
+ is_predict = false
89
+ end
90
+ key = normalize_key(key)
91
+ return super unless @data.key?(key)
92
+ value = @data[key]
93
+ if is_predict
94
+ true_value?(value)
95
+ else
96
+ value
97
+ end
98
+ when 1
99
+ key = name.to_s
100
+ return super unless key.end_with?("=")
101
+ key = key[0..-2]
102
+ @data[normalize_key(key)] = args[0]
103
+ else
104
+ super
105
+ end
106
+ end
107
+
108
+ private
109
+ def normalize(data)
110
+ normalized_data = {}
111
+ (data || {}).each do |key, value|
112
+ normalized_data[normalize_key(key)] = value
113
+ end
114
+ normalized_data
115
+ end
116
+
117
+ def normalize_key(key)
118
+ key.to_s.gsub(/-/, "_")
119
+ end
120
+
121
+ def true_value?(value)
122
+ value == true or value == "true"
123
+ end
124
+
125
+ def integer_value(value)
126
+ return nil if value.nil?
127
+ Integer(value, 10)
128
+ end
129
+
130
+ def float_value(value)
131
+ return nil if value.nil?
132
+ Float(value)
133
+ end
134
+
135
+ def size_value(value, filename, name)
136
+ return nil if value.nil?
137
+ begin
138
+ Integer(value, 10)
139
+ rescue ArgumentError
140
+ raise InvalidSizeError.new(filename, name, value)
141
+ end
142
+ end
143
+
144
+ def relative_size_value(value, filename, name)
145
+ return nil if value.nil?
146
+ begin
147
+ value = Float(value)
148
+ rescue ArgumentError
149
+ raise InvalidSizeError.new(filename, name, value)
150
+ end
151
+ RelativeSize.new(value)
152
+ end
153
+ end
154
+ end
data/lib/rabbit/rabbit.rb CHANGED
@@ -32,7 +32,9 @@ module Rabbit
32
32
 
33
33
  class << self
34
34
  def application
35
- @@application ||= Gtk::Application.new(nil, :handles_command_line)
35
+ @@application ||=
36
+ Gtk::Application.new("org.rabbit-shocker.Rabbit",
37
+ [:non_unique, :handles_command_line])
36
38
  end
37
39
  end
38
40
  end
@@ -0,0 +1,28 @@
1
+ # Copyright (C) 2020 Sutou Kouhei <kou@cozmixng.org>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ module Rabbit
18
+ class RelativeSize
19
+ def initialize(size)
20
+ @size = size
21
+ end
22
+
23
+ def resolve(base_size)
24
+ return nil if base_size.nil?
25
+ ((@size / 100.0) * base_size).ceil
26
+ end
27
+ end
28
+ end