Class: Less::JavaScript::RhinoContext
- Inherits:
-
Object
- Object
- Less::JavaScript::RhinoContext
show all
- Defined in:
- lib/less/java_script/rhino_context.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(globals = nil) ⇒ RhinoContext
Returns a new instance of RhinoContext.
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/less/java_script/rhino_context.rb', line 21
def initialize(globals = nil)
@rhino_context = Rhino::Context.new :java => true
if @rhino_context.respond_to?(:version)
@rhino_context.version = '1.8'
apply_1_8_compatibility! if @rhino_context.version.to_s != '1.8'
else
apply_1_8_compatibility!
end
globals.each { |key, val| @rhino_context[key] = val } if globals
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/less/java_script/rhino_context.rb', line 62
def method_missing(symbol, *args)
if @rhino_context.respond_to?(symbol)
@rhino_context.send(symbol, *args)
else
super
end
end
|
Class Method Details
.instance ⇒ Object
17
18
19
|
# File 'lib/less/java_script/rhino_context.rb', line 17
def self.instance
return new end
|
Instance Method Details
#call(properties, *args) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/less/java_script/rhino_context.rb', line 52
def call(properties, *args)
options = args.last.is_a?(::Hash) ? args.pop : {}
source_name = options[:source_name] || "<eval>"
line_number = options[:line_number] || 1
@rhino_context.eval(properties, source_name, line_number).call(*args)
rescue Rhino::JSError => e
handle_js_error(e)
end
|
#eval(source, options = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/less/java_script/rhino_context.rb', line 42
def eval(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source_name = options[:source_name] || "<eval>"
line_number = options[:line_number] || 1
@rhino_context.eval("(#{source})", source_name, line_number)
rescue Rhino::JSError => e
handle_js_error(e)
end
|
#exec(&block) ⇒ Object
36
37
38
39
40
|
# File 'lib/less/java_script/rhino_context.rb', line 36
def exec(&block)
@rhino_context.open(&block)
rescue Rhino::JSError => e
handle_js_error(e)
end
|
#unwrap ⇒ Object
32
33
34
|
# File 'lib/less/java_script/rhino_context.rb', line 32
def unwrap
@rhino_context
end
|