Module: Tiny::ErubisTemplating

Includes:
Buffering, Markup
Included in:
Helpers
Defined in:
lib/tiny.rb

Overview

Provides support for using Tiny helpers within an Erubis template.

Instance Method Summary collapse

Methods included from Markup

#cdata, #comment, #doctype, #html_tag

Methods included from Buffering

#append, #append!, #raw

Instance Method Details

#capture_erb(*args) {|*args| ... } ⇒ String

Capture a section of an ERB template.

Parameters:

  • args (any)

    n number of arguments to be passed to block evaluation

Yields:

  • (*args)

Returns:



310
311
312
313
314
315
316
317
# File 'lib/tiny.rb', line 310

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?

Parameters:

  • block (Proc)

    a Proc object

Returns:

  • (Boolean)


323
324
325
# File 'lib/tiny.rb', line 323

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.

Parameters:

  • args (any)

    n number of arguments to be passed to block evaluation.

Yields:

  • (*args)

    ERB block or content block.

Returns:

See Also:



300
301
302
# File 'lib/tiny.rb', line 300

def with_buffer *args, &block
  erb_block?(block) ? capture_erb(*args, &block) : super
end