diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb
index 4f72a9a..dce741a 100644
--- a/app/helpers/boxes_helper.rb
+++ b/app/helpers/boxes_helper.rb
@@ -41,27 +41,30 @@ module BoxesHelper
def display_block(block, main_content = nil)
content = block.main? ? main_content : block.content
- result =
- case content
- when Hash
- content_tag('iframe', '', :src => url_for(content))
- when String
- if content =~ /^https?:\/\//
- content_tag('iframe', '', :src => content)
- else
- content
- end
- when Proc
- self.instance_eval(&content)
- else
- raise "Unsupported content for block (#{content.class})"
- end
+ result = extract_block_content(content)
classes = ['block', block.css_class_name ].uniq.join(' ')
box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_edit_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block)
end
+ def extract_block_content(content)
+ case content
+ when Hash
+ content_tag('iframe', '', :src => url_for(content))
+ when String
+ if content =~ /^https?:\/\//
+ content_tag('iframe', '', :src => content)
+ else
+ content
+ end
+ when Proc
+ self.instance_eval(&content)
+ else
+ raise "Unsupported content for block (#{content.class})"
+ end
+ end
+
module DontMoveBlocks
# does nothing
def self.block_target(box, block = nil)
diff --git a/app/models/block.rb b/app/models/block.rb
index 9273947..5f53a9d 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -16,8 +16,16 @@ class Block < ActiveRecord::Base
_('A dummy block.')
end
- # TODO: must have some way to have access to request information (mainly the
- # current user)
+ # Returns the content to be used for this block.
+ #
+ # This method can return several types of objects:
+ #
+ # * String: if the string starts with http:// or https://, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML.
+ # * Hash: the hash is used to build an URL that is used as the address for a IFRAME.
+ # * Proc: the Proc is evaluated in the scope of BoxesHelper. The
+ # block can then use render, link_to, etc.
+ #
+ # See BoxesHelper#extract_block_content for implementation details.
def content
"This is block number %d" % self.id
end
--
libgit2 0.21.2