Class: Petroglyph::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/petroglyph/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Engine

Returns a new instance of Engine.



4
5
6
# File 'lib/petroglyph/engine.rb', line 4

def initialize(data = nil)
  @data = data
end

Instance Method Details

#render(context = Object.new, locals = {}, file = nil, &block) ⇒ Object



8
9
10
# File 'lib/petroglyph/engine.rb', line 8

def render(context = Object.new, locals = {}, file = nil, &block)
  to_hash(locals, file, context, &block).to_json
end

#to_hash(locals = {}, file = nil, context = Object.new, &block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/petroglyph/engine.rb', line 12

def to_hash(locals = {}, file = nil, context = Object.new, &block)
  scope = Scope.new(context, locals, file)

  scope.instance_eval(@data) if @data
  scope.instance_eval(&block) if block_given?

  scope.value
end