Class: Less::JavaScript::NashornContext
- Inherits:
-
Object
- Object
- Less::JavaScript::NashornContext
show all
- Defined in:
- lib/nashorn/rhino/less.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(globals = nil) ⇒ NashornContext
Returns a new instance of NashornContext.
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/nashorn/rhino/less.rb', line 18
def initialize(globals = nil)
@context = Nashorn::Context.new :java => true
globals.each { |key, val| @context[key] = val } if globals
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/nashorn/rhino/less.rb', line 53
def method_missing(symbol, *args)
if @context.respond_to?(symbol)
@context.send(symbol, *args)
else
super
end
end
|
Class Method Details
.instance ⇒ Object
14
15
16
|
# File 'lib/nashorn/rhino/less.rb', line 14
def self.instance
return new end
|
Instance Method Details
#call(properties, *args) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/nashorn/rhino/less.rb', line 46
def call(properties, *args)
args.last.is_a?(::Hash) ? args.pop : {} @context.eval(properties).call(*args)
rescue Nashorn::JSError => e
handle_js_error(e)
end
|
#eval(source, options = nil) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/nashorn/rhino/less.rb', line 39
def eval(source, options = nil)
source = source.encode('UTF-8') if source.respond_to?(:encode)
@context.eval("(#{source})")
rescue Nashorn::JSError => e
handle_js_error(e)
end
|
#exec(&block) ⇒ Object
33
34
35
36
37
|
# File 'lib/nashorn/rhino/less.rb', line 33
def exec(&block)
@context.open(&block)
rescue Nashorn::JSError => e
handle_js_error(e)
end
|
#unwrap ⇒ Object
29
30
31
|
# File 'lib/nashorn/rhino/less.rb', line 29
def unwrap
@context
end
|