Class: Handlebars::Handlebars
- Inherits:
-
Object
- Object
- Handlebars::Handlebars
show all
- Includes:
- Context
- Defined in:
- lib/ruby-handlebars.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Context
#add_item, #add_items, #get, #with_temporary_context
Constructor Details
Returns a new instance of Handlebars.
13
14
15
16
17
18
19
|
# File 'lib/ruby-handlebars.rb', line 13
def initialize()
@as_helpers = {}
@helpers = {}
@partials = {}
register_default_helpers
set_escaper
end
|
Instance Attribute Details
#escaper ⇒ Object
Returns the value of attribute escaper.
11
12
13
|
# File 'lib/ruby-handlebars.rb', line 11
def escaper
@escaper
end
|
Instance Method Details
#compile(template) ⇒ Object
21
22
23
|
# File 'lib/ruby-handlebars.rb', line 21
def compile(template)
Template.new(self, template_to_ast(template))
end
|
#get_as_helper(name) ⇒ Object
37
38
39
|
# File 'lib/ruby-handlebars.rb', line 37
def get_as_helper(name)
@as_helpers[name.to_s]
end
|
#get_helper(name) ⇒ Object
33
34
35
|
# File 'lib/ruby-handlebars.rb', line 33
def get_helper(name)
@helpers[name.to_s]
end
|
#get_partial(name) ⇒ Object
45
46
47
|
# File 'lib/ruby-handlebars.rb', line 45
def get_partial(name)
@partials[name.to_s]
end
|
#register_as_helper(name, &fn) ⇒ Object
29
30
31
|
# File 'lib/ruby-handlebars.rb', line 29
def register_as_helper(name, &fn)
@as_helpers[name.to_s] = Helper.new(self, fn)
end
|
#register_helper(name, &fn) ⇒ Object
25
26
27
|
# File 'lib/ruby-handlebars.rb', line 25
def register_helper(name, &fn)
@helpers[name.to_s] = Helper.new(self, fn)
end
|
#register_partial(name, content) ⇒ Object
41
42
43
|
# File 'lib/ruby-handlebars.rb', line 41
def register_partial(name, content)
@partials[name.to_s] = Template.new(self, template_to_ast(content))
end
|
#set_context(ctx) ⇒ Object
49
50
51
|
# File 'lib/ruby-handlebars.rb', line 49
def set_context(ctx)
@data = ctx
end
|
#set_escaper(escaper = nil) ⇒ Object
53
54
55
|
# File 'lib/ruby-handlebars.rb', line 53
def set_escaper(escaper = nil)
@escaper = escaper || Escapers::HTMLEscaper
end
|