Class: Handlebars::Context

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.


6
7
8
9
10
11
12
# File 'lib/handlebars/context.rb', line 6

def initialize
  @js = V8::Context.new
  @js['global'] = {} # there may be a more appropriate object to be used here @MHW
  @js.load(Handlebars::Source.bundled_path)

  @partials = handlebars.partials = Handlebars::Partials.new
end

Class Attribute Details

.currentObject

Returns the value of attribute current


59
60
61
# File 'lib/handlebars/context.rb', line 59

def current
  @current
end

Instance Method Details

#[](key) ⇒ Object


54
55
56
# File 'lib/handlebars/context.rb', line 54

def [](key)
  data[key]
end

#[]=(key, value) ⇒ Object


50
51
52
# File 'lib/handlebars/context.rb', line 50

def []=(key, value)
  data[key] = value
end

#compile(*args) ⇒ Object


14
15
16
# File 'lib/handlebars/context.rb', line 14

def compile(*args)
  ::Handlebars::Template.new(self, handlebars.compile(*args))
end

#create_frame(data) ⇒ Object


38
39
40
# File 'lib/handlebars/context.rb', line 38

def create_frame(data)
  handlebars.createFrame(data)
end

#handlebarsObject


46
47
48
# File 'lib/handlebars/context.rb', line 46

def handlebars
  @js.eval('Handlebars')
end

#load_helper(path) ⇒ Object


22
23
24
# File 'lib/handlebars/context.rb', line 22

def load_helper(path)
  @js.load(path)
end

#load_helpers(helpers_pattern) ⇒ Object


18
19
20
# File 'lib/handlebars/context.rb', line 18

def load_helpers(helpers_pattern)
  Dir[helpers_pattern].each{ |path| load_helper(path) }
end

#partial_missing(&fn) ⇒ Object


42
43
44
# File 'lib/handlebars/context.rb', line 42

def partial_missing(&fn)
  @partials.partial_missing = fn
end

#precompile(*args) ⇒ Object


26
27
28
# File 'lib/handlebars/context.rb', line 26

def precompile(*args)
  handlebars.precompile(*args)
end

#register_helper(name, &fn) ⇒ Object


30
31
32
# File 'lib/handlebars/context.rb', line 30

def register_helper(name, &fn)
  handlebars.registerHelper(name, fn)
end

#register_partial(name, content) ⇒ Object


34
35
36
# File 'lib/handlebars/context.rb', line 34

def register_partial(name, content)
  handlebars.registerPartial(name, content)
end