class Handlebars::Handlebars

Constants

PARSER
TRANSFORM

Attributes

escaper[R]

Public Class Methods

new() click to toggle source
# File lib/ruby-handlebars.rb, line 14
def initialize
  @as_helpers = {}
  @helpers = {}
  @partials = {}

  register_default_helpers
  set_escaper
end

Public Instance Methods

compile(template) click to toggle source
# File lib/ruby-handlebars.rb, line 23
def compile(template)
  Template.new(self, template_to_ast(template))
end
get_as_helper(name) click to toggle source
# File lib/ruby-handlebars.rb, line 39
def get_as_helper(name)
  @as_helpers[name.to_s]
end
get_helper(name) click to toggle source
# File lib/ruby-handlebars.rb, line 35
def get_helper(name)
  @helpers[name.to_s]
end
get_partial(name) click to toggle source
# File lib/ruby-handlebars.rb, line 47
def get_partial(name)
  @partials[name.to_s]
end
register_as_helper(name, &fn) click to toggle source
# File lib/ruby-handlebars.rb, line 31
def register_as_helper(name, &fn)
  @as_helpers[name.to_s] = Helper.new(self, fn)
end
register_helper(name, &fn) click to toggle source
# File lib/ruby-handlebars.rb, line 27
def register_helper(name, &fn)
  @helpers[name.to_s] = Helper.new(self, fn)
end
register_partial(name, content) click to toggle source
# File lib/ruby-handlebars.rb, line 43
def register_partial(name, content)
  @partials[name.to_s] = Template.new(self, template_to_ast(content))
end
set_escaper(escaper = nil) click to toggle source
# File lib/ruby-handlebars.rb, line 51
def set_escaper(escaper = nil)
  @escaper = escaper || Escapers::HTMLEscaper
end

Private Instance Methods

register_default_helpers() click to toggle source
# File lib/ruby-handlebars.rb, line 64
def register_default_helpers
  Helpers.register_default_helpers(self)
end
template_to_ast(content) click to toggle source
# File lib/ruby-handlebars.rb, line 60
def template_to_ast(content)
  TRANSFORM.apply(PARSER.parse(content))
end