Class: Handlebars::Handlebars

Inherits:
Object
  • Object
show all
Includes:
Context
Defined in:
lib/ruby-handlebars.rb

Instance Method Summary collapse

Methods included from Context

#add_item, #get

Constructor Details

#initializeHandlebars

Returns a new instance of Handlebars.



10
11
12
13
14
# File 'lib/ruby-handlebars.rb', line 10

def initialize
  @helpers = {}
  @partials = {}
  register_default_helpers
end

Instance Method Details

#compile(template) ⇒ Object



16
17
18
# File 'lib/ruby-handlebars.rb', line 16

def compile(template)
  Template.new(self, template_to_ast(template))
end

#get_helper(name) ⇒ Object



24
25
26
# File 'lib/ruby-handlebars.rb', line 24

def get_helper(name)
  @helpers[name.to_s]
end

#get_partial(name) ⇒ Object



32
33
34
# File 'lib/ruby-handlebars.rb', line 32

def get_partial(name)
  @partials[name.to_s]
end

#register_helper(name, &fn) ⇒ Object



20
21
22
# File 'lib/ruby-handlebars.rb', line 20

def register_helper(name, &fn)
  @helpers[name.to_s] = Helper.new(self, fn)
end

#register_partial(name, content) ⇒ Object



28
29
30
# File 'lib/ruby-handlebars.rb', line 28

def register_partial(name, content)
  @partials[name.to_s] = Template.new(self, template_to_ast(content))
end

#set_context(ctx) ⇒ Object



36
37
38
# File 'lib/ruby-handlebars.rb', line 36

def set_context(ctx)
  @data = ctx
end