module Padrino::Helpers::OutputHelpers
def self.handlers
- Private: -
def self.handlers @_template_handlers ||= [] end
def self.included(base) # @private
- Private: -
def self.included(base) # @private base.send(:include, SinatraCurrentEngine) unless base.method_defined?(:current_engine) end
def self.register(handler)
- Private: -
def self.register(handler) handlers << handler end
def block_is_template?(block)
- Api: - semipublic
Returns:
-
(Boolean)
- True if the block is a template; false otherwise.
Parameters:
-
block
(Block
) --
def block_is_template?(block) handler = find_proper_handler block && handler && handler.block_is_type?(block) end
def capture_html(*args, &block)
- Api: - semipublic
Returns:
-
(String)
- Captured html resulting from the block
Parameters:
-
&block
(Proc
) -- -
*args
(Object
) --
def capture_html(*args, &block) handler = find_proper_handler captured_html = "" if handler && handler.is_type? && handler.block_is_type?(block) captured_html = handler.capture_from_template(*args, &block) end # invoking the block directly if there was no template captured_html = block_given? && block.call(*args) if captured_html.blank? captured_html end
def concat_content(text="")
- Api: - semipublic
Parameters:
-
text
(String
) --
def concat_content(text="") handler = find_proper_handler if handler && handler.is_type? handler.concat_to_template(text) else # theres no template to concat, return the text directly text end end
def content_blocks
content_blocks[:name] => ['...', '...']
@example
Retrieves content_blocks stored by content_for or within yield_content
#
def content_blocks @content_blocks ||= Hash.new { |h,k| h[k] = [] } end
def content_for(key, content = nil, &block)
- Api: - public
Parameters:
-
block
(Proc
) -- Block to be stored as content for this key. -
key
(Symbol
) -- Name of your key for the content yield. -
content
(String
) -- Text to be stored for this key. -
key
(Symbol
) -- Name of your key for the content yield.
Overloads:
-
content_for(key, &block)
-
content_for(key, content)
def content_for(key, content = nil, &block) content_blocks[key.to_sym] << (block_given? ? block : Proc.new { content }) end
def content_for?(key)
- Api: - public
Returns:
-
(TrueClass, FalseClass)
- Result html for the given +key+
Parameters:
-
key
(Symbol
) --
def content_for?(key) content_blocks[key.to_sym].present? end
def find_proper_handler
find_proper_handler =>
@example
Can handle any output related to capturing or concating in a given template.
Retrieves the template handler for the given output context.
#
def find_proper_handler OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(current_engine) && h.is_type? } end
def yield_content(key, *args)
- Api: - public
Returns:
-
(String)
- Result html for the given +key+
Parameters:
-
*args
() --
-
key
(Symbol
) --
def yield_content(key, *args) blocks = content_blocks[key.to_sym] return nil if blocks.empty? blocks.map { |content| capture_html(*args, &content) }.join end