Class: Hanami::View::ERB::Filters::Block Private
- Defined in:
- lib/hanami/view/erb/filters/block.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implicitly captures and outputs the content inside blocks opened in ERB expression tags, such as ‘<%= form_for(:post) do %>`.
Inspired by Slim’s Slim::Controls::Filter#on_slim_output.
Constant Summary collapse
- END_LINE_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\bend\b/
Instance Method Summary collapse
Instance Method Details
#on_erb_block(escape, code, content) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hanami/view/erb/filters/block.rb', line 17 def on_erb_block(escape, code, content) tmp = unique_name # Remove the last `end` :code sexp, since this is technically "outside" the block # contents, which we want to capture separately below. This `end` is added back after # capturing the content below. case content.last in [:code, c] if c =~ END_LINE_RE content.pop end [:multi, # Capture the result of the code in a variable. We can't do `[:dynamic, code]` because # it's probably not a complete expression (which is a requirement for Temple). [:code, "#{tmp} = #{code}"], # Capture the content of a block in a separate buffer. This means that `yield` will # not output the content to the current buffer, but rather return the output. [:capture, unique_name, compile(content)], [:code, "end"], # Output the content. [:escape, escape, [:dynamic, tmp]] ] end |