Class: Slippers::Engine

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

Constant Summary collapse

DEFAULT_STRING =
''
MISSING_HANDLER =
lambda { return "" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, params = {}) ⇒ Engine

Returns a new instance of Engine.



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

def initialize(template, params={})
  @main_template = Slippers::Template.new(template)
  @template_group = params[:template_group]
end

Instance Attribute Details

#main_templateObject (readonly)

Returns the value of attribute main_template.



11
12
13
# File 'lib/engine/engine.rb', line 11

def main_template
  @main_template
end

#template_groupObject (readonly)

Returns the value of attribute template_group.



11
12
13
# File 'lib/engine/engine.rb', line 11

def template_group
  @template_group
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/engine/engine.rb', line 20

def eql?(other)
  @main_template.eql?(other.main_template) && @template_group.eql?(other.template_group)
end

#hashObject



24
25
26
# File 'lib/engine/engine.rb', line 24

def hash
  @main_template.hash + @template_group.hash*23
end

#render(object_to_render = nil) ⇒ Object



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

def render(object_to_render=nil)
  parser = SlippersParser.new
  parse_tree = parser.parse(@main_template.template)
  return '' unless parse_tree
  parse_tree.eval(object_to_render, @template_group) 
end