Class: Handlebars::Handlebars
- Inherits:
-
Object
- Object
- Handlebars::Handlebars
- Defined in:
- lib/ruby-handlebars.rb
Instance Attribute Summary collapse
-
#escaper ⇒ Object
readonly
Returns the value of attribute escaper.
Instance Method Summary collapse
- #compile(template) ⇒ Object
- #get_as_helper(name) ⇒ Object
- #get_helper(name) ⇒ Object
- #get_partial(name) ⇒ Object
-
#initialize ⇒ Handlebars
constructor
A new instance of Handlebars.
- #register_as_helper(name, &fn) ⇒ Object
- #register_helper(name, &fn) ⇒ Object
- #register_partial(name, content) ⇒ Object
- #set_escaper(escaper = nil) ⇒ Object
Constructor Details
#initialize ⇒ Handlebars
Returns a new instance of Handlebars.
12 13 14 15 16 17 18 |
# File 'lib/ruby-handlebars.rb', line 12 def initialize() @as_helpers = {} @helpers = {} @partials = {} register_default_helpers set_escaper end |
Instance Attribute Details
#escaper ⇒ Object (readonly)
Returns the value of attribute escaper.
10 11 12 |
# File 'lib/ruby-handlebars.rb', line 10 def escaper @escaper end |
Instance Method Details
#compile(template) ⇒ Object
20 21 22 |
# File 'lib/ruby-handlebars.rb', line 20 def compile(template) Template.new(self, template_to_ast(template)) end |
#get_as_helper(name) ⇒ Object
36 37 38 |
# File 'lib/ruby-handlebars.rb', line 36 def get_as_helper(name) @as_helpers[name.to_s] end |
#get_helper(name) ⇒ Object
32 33 34 |
# File 'lib/ruby-handlebars.rb', line 32 def get_helper(name) @helpers[name.to_s] end |
#get_partial(name) ⇒ Object
44 45 46 |
# File 'lib/ruby-handlebars.rb', line 44 def get_partial(name) @partials[name.to_s] end |
#register_as_helper(name, &fn) ⇒ Object
28 29 30 |
# File 'lib/ruby-handlebars.rb', line 28 def register_as_helper(name, &fn) @as_helpers[name.to_s] = Helper.new(self, fn) end |
#register_helper(name, &fn) ⇒ Object
24 25 26 |
# File 'lib/ruby-handlebars.rb', line 24 def register_helper(name, &fn) @helpers[name.to_s] = Helper.new(self, fn) end |
#register_partial(name, content) ⇒ Object
40 41 42 |
# File 'lib/ruby-handlebars.rb', line 40 def register_partial(name, content) @partials[name.to_s] = Template.new(self, template_to_ast(content)) end |
#set_escaper(escaper = nil) ⇒ Object
48 49 50 |
# File 'lib/ruby-handlebars.rb', line 48 def set_escaper(escaper = nil) @escaper = escaper || Escapers::HTMLEscaper end |