Module: Tiny::ErubisTemplating
Overview
Provides support for using Tiny helpers within an Erubis template.
Instance Method Summary collapse
-
#capture_erb(*args) {|*args| ... } ⇒ String
Capture a section of an ERB template.
-
#erb_block?(block) ⇒ Boolean
Was the block defined within an ERB template?.
-
#with_buffer(*args) {|*args| ... } ⇒ String
Extracts a section of a ERB template or buffers a block not originated from an ERB template.
Methods included from Markup
#cdata, #comment, #doctype, #html_tag
Methods included from Buffering
Instance Method Details
#capture_erb(*args) {|*args| ... } ⇒ String
Capture a section of an ERB template.
311 312 313 314 315 316 317 318 |
# File 'lib/tiny.rb', line 311 def capture_erb(*args, &block) output_buffer = eval('_buf', block.binding) buffer = output_buffer.dup output_buffer.clear and yield(*args) return output_buffer.dup ensure output_buffer.replace buffer end |
#erb_block?(block) ⇒ Boolean
Was the block defined within an ERB template?
324 325 326 |
# File 'lib/tiny.rb', line 324 def erb_block?(block) block && eval('defined?(__in_erb_template)', block.binding) end |
#with_buffer(*args) {|*args| ... } ⇒ String
Extracts a section of a ERB template or buffers a block not originated from an ERB template. Akin to Rails capture method.
301 302 303 |
# File 'lib/tiny.rb', line 301 def with_buffer(*args, &block) erb_block?(block) ? capture_erb(*args, &block) : super end |