Class: ERBook::Template::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/erbook/template.rb

Overview

Environment for template evaluation.

Instance Method Summary collapse

Instance Method Details

#__block_content__(*block_args) ⇒ Object

Returns an array of things that the given block wants to append to the buffer. If the given block does not want to append to the buffer, then returns the result of invoking the given block inside an array.

Raises:

  • (ArgumentError)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/erbook/template.rb', line 100

def __block_content__ *block_args
  raise ArgumentError, 'block must be given' unless block_given?

  original = @buffer

  begin
    block_content = @buffer = []
    return_value  = yield(*block_args) # this appends content to @buffer
  ensure
    @buffer = original
  end

  if block_content.empty?
    [return_value]
  else
    block_content
  end
end