rabbit 2.0.2 → 2.0.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 (104) hide show
  1. data/README +1 -1
  2. data/Rakefile +1 -1
  3. data/data/account.kou.gpg +0 -0
  4. data/data/locale/en/LC_MESSAGES/rabbit.mo +0 -0
  5. data/data/locale/fr/LC_MESSAGES/rabbit.mo +0 -0
  6. data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
  7. data/doc/_config.yml +2 -2
  8. data/doc/_includes/en.menu.html +1 -1
  9. data/doc/_includes/ja.menu.html +1 -1
  10. data/doc/_layouts/skeleton.html +2 -2
  11. data/doc/en/development.rd +2 -2
  12. data/doc/en/install/homebrew.rd +11 -158
  13. data/doc/en/install/index.rd +1 -16
  14. data/doc/en/install/windows.rd +1 -1
  15. data/doc/en/news.rd +70 -1
  16. data/doc/en/usage/rabbit.rd +1 -1
  17. data/doc/en/users.rd +8 -8
  18. data/doc/images/screenshots/en/blue-circle.png +0 -0
  19. data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
  20. data/doc/images/screenshots/en/clear-blue.png +0 -0
  21. data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
  22. data/doc/images/screenshots/en/cozmixng.png +0 -0
  23. data/doc/images/screenshots/en/dark-gradation-raw.png +0 -0
  24. data/doc/images/screenshots/en/dark-gradation.png +0 -0
  25. data/doc/images/screenshots/en/day-white.png +0 -0
  26. data/doc/images/screenshots/en/debian-raw.png +0 -0
  27. data/doc/images/screenshots/en/debian.png +0 -0
  28. data/doc/images/screenshots/en/green-circle.png +0 -0
  29. data/doc/images/screenshots/en/night-black.png +0 -0
  30. data/doc/images/screenshots/en/rabbit-raw.png +0 -0
  31. data/doc/images/screenshots/en/rabbit.png +0 -0
  32. data/doc/images/screenshots/en/ranguba-raw.png +0 -0
  33. data/doc/images/screenshots/en/ranguba.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.png +0 -0
  40. data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
  41. data/doc/images/screenshots/ja/clear-blue.png +0 -0
  42. data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
  43. data/doc/images/screenshots/ja/cozmixng.png +0 -0
  44. data/doc/images/screenshots/ja/dark-gradation-raw.png +0 -0
  45. data/doc/images/screenshots/ja/dark-gradation.png +0 -0
  46. data/doc/images/screenshots/ja/day-white.png +0 -0
  47. data/doc/images/screenshots/ja/debian-raw.png +0 -0
  48. data/doc/images/screenshots/ja/debian.png +0 -0
  49. data/doc/images/screenshots/ja/green-circle.png +0 -0
  50. data/doc/images/screenshots/ja/night-black.png +0 -0
  51. data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
  52. data/doc/images/screenshots/ja/rabbit.png +0 -0
  53. data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
  54. data/doc/images/screenshots/ja/ranguba.png +0 -0
  55. data/doc/images/screenshots/ja/red-frame.png +0 -0
  56. data/doc/images/screenshots/ja/ruby-gnome2-raw.png +0 -0
  57. data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
  58. data/doc/images/screenshots/ja/rubykaigi2011-raw.png +0 -0
  59. data/doc/images/screenshots/ja/rubykaigi2011.png +0 -0
  60. data/doc/index.html.en +1 -1
  61. data/doc/index.html.ja +1 -1
  62. data/doc/ja/development.rd +6 -7
  63. data/doc/ja/install/homebrew.rd +10 -156
  64. data/doc/ja/install/index.rd +1 -15
  65. data/doc/ja/install/macports.rd +1 -1
  66. data/doc/ja/news.rd +69 -1
  67. data/doc/ja/usage/rabbit-slide.rd +5 -5
  68. data/doc/ja/usage/rabbit-theme.rd +2 -2
  69. data/doc/ja/usage/rabbit.rd +1 -1
  70. data/doc/ja/users.rd +10 -10
  71. data/lib/rabbit/author-configuration.rb +18 -12
  72. data/lib/rabbit/command/rabbit-slide.rb +1 -1
  73. data/lib/rabbit/command/rabbit.rb +3 -3
  74. data/lib/rabbit/element/block.rb +2 -2
  75. data/lib/rabbit/element/text-renderer.rb +3 -1
  76. data/lib/rabbit/html/template.erb +1 -1
  77. data/lib/rabbit/image/dia.rb +19 -20
  78. data/lib/rabbit/image/eps.rb +1 -1
  79. data/lib/rabbit/parser/image.rb +14 -6
  80. data/lib/rabbit/renderer/engine/cairo.rb +27 -12
  81. data/lib/rabbit/renderer/print/cairo.rb +10 -2
  82. data/lib/rabbit/slide-configuration.rb +27 -14
  83. data/lib/rabbit/soap/base.rb +1 -1
  84. data/lib/rabbit/task/slide.rb +71 -33
  85. data/lib/rabbit/task/theme.rb +61 -19
  86. data/lib/rabbit/theme/clear-blue/clear-blue.rb +17 -0
  87. data/lib/rabbit/theme/color-circle-block-quote/color-circle-block-quote.rb +2 -0
  88. data/lib/rabbit/theme/default-block-quote/default-block-quote.rb +162 -75
  89. data/lib/rabbit/theme/image/image.rb +3 -1
  90. data/lib/rabbit/theme/rabbit-block-quote/rabbit-block-quote.rb +2 -0
  91. data/lib/rabbit/theme/title-on-image-toolkit/title-on-image-toolkit.rb +25 -13
  92. data/lib/rabbit/utils.rb +16 -3
  93. data/lib/rabbit/version.rb +1 -1
  94. data/po/en/rabbit.po +182 -180
  95. data/po/fr/rabbit.po +182 -180
  96. data/po/ja/rabbit.po +184 -169
  97. data/po/rabbit.pot +176 -164
  98. data/rabbit.gemspec +63 -0
  99. data/test/image/test-dia.rb +54 -0
  100. data/test/image/test-eps.rb +41 -0
  101. data/test/rabbit-test-utils.rb +22 -20
  102. data/test/run-test.rb +20 -6
  103. data/test/test-slide-configuration.rb +2 -0
  104. metadata +8 -3
@@ -1,6 +1,6 @@
1
1
  module Rabbit
2
2
  module SOAP
3
- NS = "http://rabbit-shockers.org/ns/rabbit/0.0.1/"
3
+ NS = "http://rabbit-shocker.org/ns/rabbit/0.0.1/"
4
4
 
5
5
  module_function
6
6
  def element_name(name)
@@ -80,24 +80,39 @@ module Rabbit
80
80
  def define
81
81
  task :default => :run
82
82
 
83
- options_file = ".rabbit"
84
- file options_file do
85
- format = _("To run rabbit, create '%{options_file}'!")
86
- raise(format % {:options_file => options_file})
83
+ define_run_task
84
+ define_gem_task
85
+ define_pdf_task
86
+ define_publish_task
87
+ end
88
+
89
+ def define_run_task
90
+ file options_path do
91
+ format = _("To run rabbit, create '%{options_path}'!")
92
+ raise(format % {:options_path => options_path})
87
93
  end
88
94
 
89
95
  desc(_("Show slide"))
90
- task :run => options_file do
96
+ task :run => options_path do
91
97
  rabbit
92
98
  end
99
+ end
93
100
 
101
+ def define_gem_task
102
+ define_gem_create_task
103
+ define_gem_validate_task
104
+ end
105
+
106
+ def define_gem_create_task
94
107
  desc(_("Create gem: %{gem_path}") % {:gem_path => gem_path})
95
108
  task :gem => ["gem:validate", :pdf] do
96
109
  mkdir_p(@package_dir)
97
110
  Gem::Builder.new(spec).build
98
111
  mv(File.basename(spec.cache_file), gem_path)
99
112
  end
113
+ end
100
114
 
115
+ def define_gem_validate_task
101
116
  namespace :gem do
102
117
  task :validate do
103
118
  errors = []
@@ -118,8 +133,10 @@ module Rabbit
118
133
  end
119
134
  end
120
135
  end
136
+ end
121
137
 
122
- file pdf_path => [options_file, *(spec.files - [pdf_path])] do
138
+ def define_pdf_task
139
+ file pdf_path => [options_path, *(spec.files - [pdf_path])] do
123
140
  mkdir_p(@pdf_dir)
124
141
  rabbit("--print",
125
142
  "--output-filename", pdf_path)
@@ -127,53 +144,74 @@ module Rabbit
127
144
 
128
145
  desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
129
146
  task :pdf => pdf_path
147
+ end
130
148
 
149
+ def define_publish_task
131
150
  desc(_("Publish the slide to all available targets"))
132
151
  task :publish
133
152
 
134
153
  publish_tasks = []
135
154
  namespace :publish do
136
155
  if @slide.author.rubygems_user
137
- desc(_("Publish the slide to %s" % "RubyGems.org"))
138
- task :rubygems => :gem do
139
- ruby("-S", "gem", "push", "--verbose", gem_path)
140
- end
156
+ define_publish_rubygems_task
141
157
  publish_tasks << :rubygems
142
158
  end
143
159
 
144
160
  slideshare_user = @slide.author.slideshare_user
145
161
  if slideshare_user
146
- desc(_("Publish the slide to %s" % "SlideShare"))
147
- task :slideshare => [:pdf, "gem:validate"] do
148
- require "rabbit/slideshare"
149
- slideshare = SlideShare.new(@logger)
150
- slideshare.user = slideshare_user
151
- slideshare.pdf_path = pdf_path
152
- slideshare.title = spec.summary
153
- slideshare.description = spec.description
154
- slideshare.tags = @tags if @tags
155
- id = slideshare.upload
156
- if id
157
- url = "http://www.slideshare.net/#{slideshare_user}/ss-#{id}"
158
- @logger.info(_("Uploaded successfully!"))
159
- @logger.info(_("See %s") % url)
160
- Gtk.show_uri(url) if Gtk.respond_to?(:show_uri)
161
- end
162
- end
162
+ define_publish_slideshare_task
163
163
  publish_tasks << :slideshare
164
164
  end
165
165
 
166
166
  if @slide.author.speaker_deck_user
167
- desc(_("Publish the slide to %s" % "Spearker Deck"))
168
- task :speaker_deck => :pdf do
169
- raise "Not implemented yet."
170
- end
167
+ define_publish_speaker_deck_task
171
168
  publish_tasks << :speaker_deck
172
169
  end
173
170
  end
174
171
  task :publish => publish_tasks.collect {|task| "publish:#{task}"}
175
172
  end
176
173
 
174
+ def define_publish_rubygems_task
175
+ desc(_("Publish the slide to %s" % "RubyGems.org"))
176
+ task :rubygems => :gem do
177
+ ruby("-S", "gem", "push", gem_path)
178
+ end
179
+ end
180
+
181
+ def define_publish_slideshare_task
182
+ desc(_("Publish the slide to %s" % "SlideShare"))
183
+ task :slideshare => [:pdf, "gem:validate"] do
184
+ require "rabbit/slideshare"
185
+ slideshare = SlideShare.new(@logger)
186
+ slideshare.user = slideshare_user
187
+ slideshare.pdf_path = pdf_path
188
+ slideshare.title = spec.summary
189
+ slideshare.description = spec.description
190
+ slideshare.tags = @tags if @tags
191
+ id = slideshare.upload
192
+ if id
193
+ url = "http://www.slideshare.net/#{slideshare_user}/#{id}"
194
+ @logger.info(_("Uploaded successfully!"))
195
+ @logger.info(_("See %s") % url)
196
+ Gtk.show_uri(url) if Gtk.respond_to?(:show_uri)
197
+
198
+ @slide.slideshare_id = id
199
+ @slide.save(".")
200
+ end
201
+ end
202
+ end
203
+
204
+ def define_publish_speaker_deck_task
205
+ desc(_("Publish the slide to %s" % "Spearker Deck"))
206
+ task :speaker_deck => :pdf do
207
+ puts "Not implemented yet."
208
+ end
209
+ end
210
+
211
+ def options_path
212
+ ".rabbit"
213
+ end
214
+
177
215
  def gem_path
178
216
  File.join(@package_dir, "#{spec.name}-#{spec.version}.gem")
179
217
  end
@@ -183,12 +221,12 @@ module Rabbit
183
221
  end
184
222
 
185
223
  def pdf_base_path
186
- "#{@slide.id}.pdf"
224
+ "#{@slide.id}-#{@slide.base_name}.pdf"
187
225
  end
188
226
 
189
227
  def homepage
190
228
  rubygems_user = @slide.author.rubygems_user
191
- "http://slide.rabbit-shockers.org/#{rubygems_user}/\#{@slide.id}/"
229
+ "http://slide.rabbit-shocker.org/authors/#{rubygems_user}/#{@slide.id}/"
192
230
  end
193
231
 
194
232
  def rabbit(*arguments)
@@ -28,12 +28,11 @@ module Rabbit
28
28
  include Rake::DSL
29
29
  include GetText
30
30
 
31
- attr_reader :spec
32
31
  attr_accessor :package_dir, :pdf_dir, :required_rabbit_version
33
32
  def initialize
34
33
  @logger = Logger.default
35
34
  @theme = load_theme_configuration
36
- @spec = create_spec
35
+ @spec = nil
37
36
  @package_dir = "pkg"
38
37
  @pdf_dir = "pdf"
39
38
  @required_rabbit_version = ">= 2.0.2"
@@ -41,6 +40,10 @@ module Rabbit
41
40
  define
42
41
  end
43
42
 
43
+ def spec
44
+ @spec ||= create_spec
45
+ end
46
+
44
47
  private
45
48
  def load_theme_configuration
46
49
  theme_conf = ThemeConfiguration.new(@logger)
@@ -68,6 +71,9 @@ module Rabbit
68
71
  spec.files += Dir.glob("data/**/*.{svg,png,jpg,jpeg,gif,eps,pdf}")
69
72
  spec.files += Dir.glob("locale/**/*.mo")
70
73
  spec.files += Dir.glob("po/*/*.po")
74
+ theme_benchmark_locales.each do |locale|
75
+ spec.files += [theme_benchmark_pdf_path(locale)]
76
+ end
71
77
 
72
78
  spec.add_runtime_dependency("rabbit", @required_rabbit_version)
73
79
  end
@@ -76,18 +82,34 @@ module Rabbit
76
82
  def define
77
83
  task :default => :run
78
84
 
85
+ define_run_task
86
+ define_gem_task
87
+ define_pdf_task
88
+ define_publish_task
89
+ end
90
+
91
+ def define_run_task
79
92
  desc(_("Show theme benchmark slide with this theme"))
80
93
  task :run do
81
94
  rabbit("--theme", ".", _("rabbit-theme-benchmark-en.gem"))
82
95
  end
96
+ end
97
+
98
+ def define_gem_task
99
+ define_gem_create_task
100
+ define_gem_validate_task
101
+ end
83
102
 
103
+ def define_gem_create_task
84
104
  desc(_("Create gem: %{gem_path}") % {:gem_path => gem_path})
85
105
  task :gem => "gem:validate" do
86
106
  mkdir_p(@package_dir)
87
- Gem::Builder.new(@spec).build
88
- mv(File.basename(@spec.cache_file), gem_path)
107
+ Gem::Builder.new(spec).build
108
+ mv(File.basename(spec.cache_file), gem_path)
89
109
  end
110
+ end
90
111
 
112
+ def define_gem_validate_task
91
113
  namespace :gem do
92
114
  task :validate do
93
115
  errors = []
@@ -96,7 +118,7 @@ module Rabbit
96
118
  :where => Dir.glob("README*")[0],
97
119
  }
98
120
  [:summary, :description].each do |item|
99
- content = @spec.send(item)
121
+ content = spec.send(item)
100
122
  if /TODO|FIXME/ =~ content
101
123
  data[:item] = item
102
124
  data[:content] = content
@@ -108,19 +130,35 @@ module Rabbit
108
130
  end
109
131
  end
110
132
  end
133
+ end
111
134
 
112
- pdf_path = File.join(@pdf_dir, pdf_base_path)
113
- file pdf_path => [*@spec.files] do
114
- mkdir_p(@pdf_dir)
115
- rabbit("--theme", ".",
116
- "--print",
117
- "--output-filename", pdf_path,
118
- _("rabbit-theme-benchmark-en.gem"))
135
+ def define_pdf_task
136
+ desc(_("Generate all PDFs"))
137
+ task :pdf
138
+ theme_benchmark_locales.each do |locale|
139
+ task :pdf => "pdf:#{locale}"
119
140
  end
120
141
 
121
- desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
122
- task :pdf => pdf_path
142
+ namespace :pdf do
143
+ theme_benchmark_locales.each do |locale|
144
+ pdf_path = theme_benchmark_pdf_path(locale)
145
+ files_without_pdf = spec.files - Dir.glob("#{@pdf_dir}/*/*.pdf")
146
+ file pdf_path => files_without_pdf do
147
+ mkdir_p(@pdf_dir)
148
+ rabbit("--theme", ".",
149
+ "--print",
150
+ "--output-filename", pdf_path,
151
+ "rabbit-theme-benchmark-#{locale}.gem")
152
+ end
123
153
 
154
+ desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
155
+ task locale => pdf_path do
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ def define_publish_task
124
162
  desc(_("Publish the theme to all available targets"))
125
163
  task :publish
126
164
 
@@ -129,7 +167,7 @@ module Rabbit
129
167
  if @theme.author.rubygems_user
130
168
  desc(_("Publish the theme to %s") % "RubyGems.org")
131
169
  task :rubygems => :gem do
132
- ruby("-S", "gem", "push", "--verbose", gem_path)
170
+ ruby("-S", "gem", "push", gem_path)
133
171
  end
134
172
  publish_tasks << :rubygems
135
173
  end
@@ -138,15 +176,19 @@ module Rabbit
138
176
  end
139
177
 
140
178
  def gem_path
141
- File.join(@package_dir, "#{@spec.name}-#{@spec.version}.gem")
179
+ File.join(@package_dir, "#{spec.name}-#{spec.version}.gem")
180
+ end
181
+
182
+ def theme_benchmark_pdf_path(locale)
183
+ File.join(@pdf_dir, "theme-benchmark-#{locale}.pdf")
142
184
  end
143
185
 
144
- def pdf_base_path
145
- "#{@theme.id}.pdf"
186
+ def theme_benchmark_locales
187
+ ["en", "ja"]
146
188
  end
147
189
 
148
190
  def homepage
149
- "http://theme.rabbit-shockers.org/#{@theme.id}/"
191
+ "http://theme.rabbit-shocker.org/themes/#{@theme.id}/"
150
192
  end
151
193
 
152
194
  def rabbit(*arguments)
@@ -45,6 +45,15 @@ add_image_path("rabbit-images")
45
45
  @block_quote_open_quote_image = "open-quote-blue.png"
46
46
  @block_quote_close_quote_image = "close-quote-blue.png"
47
47
 
48
+ @block_quote_frame_width = 0
49
+ @block_quote_fill_color = "#fff0"
50
+ @block_quote_padding_left = 0
51
+ @block_quote_padding_right = 0
52
+ @block_quote_padding_top = 0
53
+ @block_quote_padding_bottom = 0
54
+ @block_quote_image_background_alpha = 0.3
55
+ @block_quote_image_frame = true
56
+
48
57
  @margin_bottom = canvas.height * 0.05
49
58
 
50
59
  include_theme("default")
@@ -77,6 +86,14 @@ match(Slide, Body) do |bodies|
77
86
  end
78
87
  end
79
88
 
89
+ match("**", BlockQuote) do |quotes|
90
+ quotes.each do |quote|
91
+ first_element = quote.elements.first
92
+ next unless first_element.is_a?(Paragraph)
93
+ first_element.indent = first_element.prop_get("size")
94
+ end
95
+ end
96
+
80
97
  @slide_logo_image ||= "clear-blue-headline-background.png"
81
98
  include_theme("slide-logo")
82
99
 
@@ -5,6 +5,8 @@
5
5
  @block_quote_open_quote_image = @color_circle_open_quote_image
6
6
  @block_quote_close_quote_image = @color_circle_close_quote_image
7
7
 
8
+ @block_quote_image_frame = true
9
+
8
10
  include_theme("default-block-quote")
9
11
 
10
12
  block_quote = [Slide, Body, BlockQuote]
@@ -3,20 +3,149 @@
3
3
  @block_quote_fill_color ||= "#fcfae2"
4
4
 
5
5
  @block_quote_title_color ||= "#666"
6
- @block_quote_title_font_size ||= @x_small_font_size
6
+ @block_quote_title_font_size ||= @xx_small_font_size
7
7
 
8
8
  @block_quote_padding_left ||= screen_x(5)
9
9
  @block_quote_padding_right ||= screen_x(5)
10
10
  @block_quote_padding_top ||= screen_y(2)
11
11
  @block_quote_padding_bottom ||= screen_y(2)
12
12
 
13
- @block_quote_margin_left ||= screen_x(3)
14
- @block_quote_margin_right ||= screen_x(3)
13
+ @block_quote_margin_left ||= screen_x(1)
14
+ @block_quote_margin_right ||= screen_x(1)
15
15
 
16
16
  @block_quote_open_quote_image ||= nil
17
17
  @block_quote_close_quote_image ||= nil
18
- @block_quote_image_max_width ||= canvas.width * 0.1
18
+ @block_quote_image_max_width ||= nil # deprecated
19
+ @block_quote_image_width ||= @block_quote_image_max_width
20
+ @block_quote_image_width ||= canvas.width * 0.1
19
21
  @block_quote_image_background_alpha ||= nil
22
+ @block_quote_image_frame ||= nil
23
+
24
+ load_quote = lambda do |file|
25
+ return nil if file.nil?
26
+ quote = ImageLoader.new(find_file(file))
27
+ quote.keep_ratio = true
28
+ quote.resize(@block_quote_image_width, nil)
29
+ quote
30
+ end
31
+
32
+ compute_padding = lambda do |open_quote, close_quote|
33
+ padding = {
34
+ :left => @block_quote_padding_left,
35
+ :right => @block_quote_padding_right,
36
+ :top => @block_quote_padding_top,
37
+ :bottom => @block_quote_padding_bottom,
38
+ }
39
+ return padding if @block_quote_image_frame
40
+
41
+ unless @block_quote_image_background_alpha
42
+ padding[:left] += @block_quote_image_width if open_quote
43
+ padding[:right] += @block_quote_image_width if close_quote
44
+ end
45
+ padding
46
+ end
47
+
48
+ compute_margin = lambda do |open_quote, close_quote|
49
+ margin = {
50
+ :left => @block_quote_margin_left,
51
+ :right => @block_quote_margin_right,
52
+ :bottom => @space,
53
+ }
54
+ if @block_quote_image_frame
55
+ if open_quote
56
+ margin[:left] += open_quote.width / 2
57
+ margin[:top] = open_quote.height / 2
58
+ end
59
+ if close_quote
60
+ margin[:right] += close_quote.width / 2
61
+ margin[:bottom] = close_quote.height / 2
62
+ end
63
+ end
64
+ margin
65
+ end
66
+
67
+ render_open_quote = lambda do |open_quote, block, canvas, x, y, w, h|
68
+ return unless open_quote
69
+ quote_x = x
70
+ quote_y = y
71
+ if @block_quote_image_frame
72
+ quote_x -= block.padding_left
73
+ quote_x -= open_quote.width / 2
74
+ quote_y -= block.padding_top
75
+ quote_y -= open_quote.height / 2
76
+ else
77
+ quote_x -= block.padding_left / 2
78
+ unless @block_quote_image_background_alpha
79
+ quote_x -= open_quote.width / 2
80
+ end
81
+ quote_y -= block.padding_top / 2
82
+ end
83
+ open_quote.draw(canvas, quote_x, quote_y,
84
+ :alpha => @block_quote_image_background_alpha)
85
+ end
86
+
87
+ render_close_quote = lambda do |close_quote, block, canvas, x, y, w, h|
88
+ return unless close_quote
89
+ quote_x = x + w
90
+ quote_y = y + block.height
91
+ if @block_quote_image_frame
92
+ quote_x += block.padding_right
93
+ quote_x -= close_quote.width / 2
94
+ quote_y -= block.padding_bottom
95
+ quote_y -= close_quote.height / 2
96
+ else
97
+ quote_x -= (block.padding_right - close_quote.width) / 2
98
+ if @block_quote_image_background_alpha
99
+ quote_x -= close_quote.width
100
+ else
101
+ quote_x += close_quote.width / 2
102
+ end
103
+ quote_y -= close_quote.height
104
+ quote_y -= block.padding_bottom
105
+ quote_y -= block.padding_bottom / 2
106
+ end
107
+ close_quote.draw(canvas, quote_x, quote_y,
108
+ :alpha => @block_quote_image_background_alpha)
109
+ end
110
+
111
+ create_title_layout = lambda do |close_quote, block, canvas, x, y, w, h|
112
+ title = Text.new(_("[cited from `%s']") % block.title)
113
+ title.font(:size => @block_quote_title_font_size,
114
+ :style => "italic")
115
+ title.align = Pango::Layout::ALIGN_RIGHT
116
+ set_font_family(title)
117
+ title_w = w + block.padding_left + block.padding_right
118
+ if @block_quote_image_frame
119
+ title_w -= close_quote.width / 2 if close_quote
120
+ end
121
+ title.compile(canvas, x, y, title_w, h)
122
+ block.margin_bottom += title.height + @block_quote_frame_width
123
+ title.layout
124
+ end
125
+
126
+ render_title_layout = lambda do |layout, block, canvas, x, y, w, h|
127
+ base_x = (block.ox || x) - block.padding_left
128
+ base_y = y + block.padding_bottom
129
+ unless @block_quote_image_frame
130
+ base_y += @block_quote_frame_width
131
+ end
132
+ canvas.draw_layout(layout, base_x, base_y, @block_quote_title_color)
133
+
134
+ end
135
+
136
+ load_avatar = lambda do |path|
137
+ return nil if path.nil?
138
+ image_element(path,
139
+ "width" => @block_quote_image_width,
140
+ "keep_ratio" => true)
141
+ end
142
+
143
+ render_avatar = lambda do |avatar, block, canvas, x, y, w, h|
144
+ avatar.image_draw(canvas,
145
+ x - block.padding_left - block.margin_left,
146
+ y - block.padding_bottom)
147
+ end
148
+
20
149
 
21
150
  match("**", BlockQuote) do
22
151
  name = "block-quote"
@@ -25,77 +154,29 @@ match("**", BlockQuote) do
25
154
 
26
155
  params = {
27
156
  :proc_name => name,
28
- :frame_color => @block_quote_frame_color,
29
- :frame_width => @block_quote_frame_width,
30
157
  :fill_color => @block_quote_fill_color,
31
158
  }
32
-
159
+ unless @block_quote_image_frame
160
+ params[:frame_color] = @block_quote_frame_color
161
+ params[:frame_width] = @block_quote_frame_width
162
+ end
33
163
  draw_frame(params)
34
164
 
35
165
  each do |block|
36
166
  name = "block-quote-image"
37
167
 
38
- padding_left = @block_quote_padding_left
39
- padding_right = @block_quote_padding_right
40
-
41
- open_quote = nil
42
- close_quote = nil
43
- if @block_quote_open_quote_image
44
- open_quote = ImageLoader.new(find_file(@block_quote_open_quote_image))
45
- if open_quote.width > @block_quote_image_max_width
46
- open_quote.resize(@block_quote_image_max_width, nil)
47
- end
48
- unless @block_quote_image_background_alpha
49
- padding_left += open_quote.width
50
- end
51
- end
52
- if @block_quote_close_quote_image
53
- close_quote = ImageLoader.new(find_file(@block_quote_close_quote_image))
54
- if close_quote.width > @block_quote_image_max_width
55
- close_quote.resize(@block_quote_image_max_width, nil)
56
- end
57
- unless @block_quote_image_background_alpha
58
- padding_right += close_quote.width
59
- end
60
- end
168
+ open_quote = load_quote.call(@block_quote_open_quote_image)
169
+ close_quote = load_quote.call(@block_quote_close_quote_image)
61
170
 
62
- block.padding_with(:left => padding_left,
63
- :right => padding_right,
64
- :top => @block_quote_padding_top,
65
- :bottom => @block_quote_padding_bottom)
66
- block.margin_with(:left => @block_quote_margin_left,
67
- :right => @block_quote_margin_right,
68
- :bottom => @space)
171
+ block.padding_with(compute_padding.call(open_quote, close_quote))
172
+ block.margin_with(compute_margin.call(open_quote, close_quote))
69
173
 
70
174
  block.delete_pre_draw_proc_by_name(name)
71
175
  if open_quote or close_quote
72
176
  block.add_pre_draw_proc(name) do |canvas, x, y, w, h, simulation|
73
177
  unless simulation
74
- if open_quote
75
- adjust_open_quote_x = @block_quote_padding_left / 2
76
- adjust_open_quote_y = @block_quote_padding_top / 2
77
- unless @block_quote_image_background_alpha
78
- adjust_open_quote_x += open_quote.width
79
- end
80
- open_quote.draw(canvas,
81
- x - adjust_open_quote_x,
82
- y - adjust_open_quote_y,
83
- :alpha => @block_quote_image_background_alpha)
84
- end
85
- if close_quote
86
- adjust_close_quote_x = -@block_quote_padding_right / 2
87
- if @block_quote_image_background_alpha
88
- adjust_close_quote_x += close_quote.width
89
- end
90
- adjust_close_quote_y = block.height
91
- adjust_close_quote_y -= close_quote.height
92
- adjust_close_quote_y -= @block_quote_padding_bottom / 2
93
- adjust_close_quote_y -= block.padding_bottom
94
- close_quote.draw(canvas,
95
- x + w - adjust_close_quote_x,
96
- y + adjust_close_quote_y,
97
- :alpha => @block_quote_image_background_alpha)
98
- end
178
+ render_open_quote.call(open_quote, block, canvas, x, y, w, h)
179
+ render_close_quote.call(close_quote, block, canvas, x, y, w, h)
99
180
  end
100
181
  [x, y, w, h]
101
182
  end
@@ -107,24 +188,30 @@ match("**", BlockQuote) do
107
188
  if block.title
108
189
  layout = nil
109
190
  block.add_post_draw_proc(name) do |canvas, x, y, w, h, simulation|
110
- if layout.nil?
111
- title = Text.new(_("[cited from `%s']") % block.title)
112
- title.font(:size => @block_quote_title_font_size,
113
- :style => "italic")
114
- title.align = Pango::Layout::ALIGN_RIGHT
115
- set_font_family(title)
116
- title_w = w + block.padding_left + block.padding_right
117
- title.compile(canvas, x, y, title_w, h)
118
- layout = title.layout
119
- block.margin_bottom += title.height + @block_quote_frame_width
191
+ layout ||= create_title_layout.call(close_quote,
192
+ block, canvas, x, y, w, h)
193
+ unless simulation
194
+ render_title_layout.call(layout, block, canvas, x, y, w, h)
120
195
  end
196
+ [x, y, w, h]
197
+ end
198
+ end
199
+
200
+ name = "block-quote-avatar"
201
+ block.delete_post_draw_proc_by_name(name)
202
+
203
+ avatar = load_avatar.call(block.avatar)
204
+ if avatar
205
+ block.add_post_draw_proc(name) do |canvas, x, y, w, h, simulation|
121
206
  unless simulation
122
- base_x = (block.ox || x) - block.padding_left
123
- base_y = y + block.padding_bottom + @block_quote_frame_width
124
- canvas.draw_layout(layout, base_x, base_y, @block_quote_title_color)
207
+ render_avatar.call(avatar, block, canvas, x, y, w, h)
125
208
  end
126
209
  [x, y, w, h]
127
210
  end
128
211
  end
129
212
  end
130
213
  end
214
+
215
+ match("**", BlockQuote, TextContainerElement) do |texts|
216
+ texts.justify = true
217
+ end