Commit 9780bfaccdd482b2142bdece601d838486527a43
1 parent
4dae1207
Exists in
master
and in
22 other branches
Blocks can returns a block of code to be evaluated
(ActionItem3031)
Showing
2 changed files
with
14 additions
and
6 deletions
Show diff stats
app/helpers/boxes_helper.rb
... | ... | @@ -220,14 +220,13 @@ module BoxesHelper |
220 | 220 | end |
221 | 221 | |
222 | 222 | if block.embedable? |
223 | - url = url_for :controller => 'embed', :action => 'index', :id => block.id, :only_path => false; | |
224 | - | |
223 | + embed_code = block.embed_code | |
224 | + embed_code = instance_eval(&embed_code) if embed_code.respond_to?(:call) | |
225 | 225 | html = content_tag('div', |
226 | 226 | content_tag('h2', _('Embed block code')) + |
227 | 227 | content_tag('div', _('Below, you''ll see a field containing embed code for the block. Just copy the code and paste it into your website or blogging software.'), :style => 'margin-bottom: 1em;') + |
228 | - content_tag('textarea', block.embed_code(url), :style => 'margin-bottom: 1em; width:100%; height:40%;', :readonly => 'readonly') + | |
228 | + content_tag('textarea', embed_code, :style => 'margin-bottom: 1em; width:100%; height:40%;', :readonly => 'readonly') + | |
229 | 229 | thickbox_close_button(_('Close')), :style => 'display: none;', :id => "embed-code-box-#{block.id}") |
230 | - | |
231 | 230 | buttons << thickbox_inline_popup_icon(:embed, _('Embed code'), {}, "embed-code-box-#{block.id}") << html |
232 | 231 | end |
233 | 232 | ... | ... |
app/models/block.rb
... | ... | @@ -20,8 +20,17 @@ class Block < ActiveRecord::Base |
20 | 20 | false |
21 | 21 | end |
22 | 22 | |
23 | - def embed_code(url) | |
24 | - html = "<iframe src='#{url}' frameborder='0' width='1024' height='768' class='embed block #{self.class.name.to_css_class}'></iframe>" | |
23 | + def embed_code | |
24 | + me = self | |
25 | + lambda do | |
26 | + content_tag('iframe', '', | |
27 | + :src => url_for(:controller => 'embed', :action => 'index', :id => me.id, :only_path => false), | |
28 | + :frameborder => 0, | |
29 | + :width => 1024, | |
30 | + :height => 768, | |
31 | + :class => "embed block #{me.class.name.to_css_class}" | |
32 | + ) | |
33 | + end | |
25 | 34 | end |
26 | 35 | |
27 | 36 | # Determines whether a given block must be visible. Optionally a | ... | ... |