Class: Jadeite::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/jadeite/environment.rb

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



6
7
8
9
10
11
12
13
# File 'lib/jadeite/environment.rb', line 6

def initialize
  context = V8::Context.new
  context.eval("var process = {env: {}}")
  context.load(File.expand_path(File.join('../../../', 'node_modules/jade/runtime.js'), __FILE__))

  node_env = NodeJS::Environment.new(context, File.expand_path('../../', __FILE__))
  @jade = node_env.require('jade')
end

Instance Method Details

#compile(template_str, opts = {}) ⇒ Object



15
16
17
# File 'lib/jadeite/environment.rb', line 15

def compile(template_str, opts={})
  Template.new(@jade.compile(template_str.strip, opts))
end

#compile_file(file, opts = {}) ⇒ Object



23
24
25
26
# File 'lib/jadeite/environment.rb', line 23

def compile_file(file, opts = {})
  opts.merge!(:filename => File.expand_path(file))
  compile(File.read(file), opts)
end

#render(template_str, data = {}, opts = {}) ⇒ Object



19
20
21
# File 'lib/jadeite/environment.rb', line 19

def render(template_str, data={}, opts={})
  compile(template_str, opts).render(data)
end

#render_file(file, data = {}, opts = {}) ⇒ Object



28
29
30
# File 'lib/jadeite/environment.rb', line 28

def render_file(file, data={}, opts = {})
  compile_file(file, opts).render(data)
end