Class: Padrino::Helpers::OutputHelpers::AbstractHandler
- Defined in:
- padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
readonly
Returns the value of attribute output_buffer.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#capture_from_template(*args, &block) ⇒ Object
Captures the html from a block of template code for this handler.
-
#concat_to_template(text = "", context = nil) ⇒ Object
Outputs the given text to the template.
-
#engine_matches?(block) ⇒ Boolean
Returns true if the block given is of the handler’s template type; false otherwise.
-
#initialize(template) ⇒ AbstractHandler
constructor
A new instance of AbstractHandler.
Constructor Details
#initialize(template) ⇒ AbstractHandler
Returns a new instance of AbstractHandler.
7 8 9 10 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 7 def initialize(template) @template = template @output_buffer = template.instance_variable_get(:@_out_buf) end |
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
5 6 7 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 5 def output_buffer @output_buffer end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 5 def template @template end |
Instance Method Details
#capture_from_template(*args, &block) ⇒ Object
Captures the html from a block of template code for this handler.
This method is called to capture content of a block-loving helpers in templates. Haml has a special method to do this, for Erb and Slim we save original buffer, call the block and then restore the buffer.
31 32 33 34 35 36 37 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 31 def capture_from_template(*args, &block) self.output_buffer, _buf_was = SafeBuffer.new, self.output_buffer raw = yield(*args) captured = template.instance_variable_get(:@_out_buf) self.output_buffer = _buf_was engine_matches?(block) && !captured.empty? ? captured : raw.to_s end |
#concat_to_template(text = "", context = nil) ⇒ Object
Outputs the given text to the template.
This method is called when template uses block-aware helpers. For Slim and Haml such helpers just return output to use with ‘=`. For Erb this method is implemented in ErbHandler by concatenating given text to output buffer.
49 50 51 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 49 def concat_to_template(text="", context=nil) text end |
#engine_matches?(block) ⇒ Boolean
Returns true if the block given is of the handler’s template type; false otherwise.
18 19 |
# File 'padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb', line 18 def engine_matches?(block) end |