Class: Nanoc::Erector::Filter

Inherits:
Filter
  • Object
show all
Defined in:
lib/nanoc/erector/filter.rb

Defined Under Namespace

Classes: OutsideLayoutError

Instance Method Summary collapse

Instance Method Details

#run(content, params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nanoc/erector/filter.rb', line 19

def run(content, params={})
  if @assigns[:layout].nil?
    raise OutsideLayoutError
  end

  class_name = params.fetch(:class, 'ErectorTemplate').to_sym
  options = params.fetch(:erector, {})

  begin
    klass = Object.const_get(class_name)
    Object.send(:remove_const, class_name)
  rescue NameError
  end

  eval(@assigns[:layout].content.string, TOPLEVEL_BINDING, filename)
  Object.const_get(class_name).new(assigns).to_html(options)
end