Class: Less::JavaScript::V8Context
- Inherits:
-
Object
- Object
- Less::JavaScript::V8Context
show all
- Defined in:
- lib/less/java_script/v8_context.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(globals = nil) ⇒ V8Context
Returns a new instance of V8Context.
18
19
20
21
22
23
|
# File 'lib/less/java_script/v8_context.rb', line 18
def initialize(globals = nil)
lock do
@v8_context = V8::Context.new
globals.each { |key, val| @v8_context[key] = val } if globals
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/less/java_script/v8_context.rb', line 49
def method_missing(symbol, *args)
if @v8_context.respond_to?(symbol)
@v8_context.send(symbol, *args)
else
super
end
end
|
Class Method Details
.instance ⇒ Object
14
15
16
|
# File 'lib/less/java_script/v8_context.rb', line 14
def self.instance
return new
end
|
Instance Method Details
#call(properties, *args) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/less/java_script/v8_context.rb', line 41
def call(properties, *args)
args.last.is_a?(::Hash) ? args.pop : nil
lock do
@v8_context.eval(properties).call(*args)
end
end
|
#eval(source, options = nil) ⇒ Object
passing options not supported
33
34
35
36
37
38
39
|
# File 'lib/less/java_script/v8_context.rb', line 33
def eval(source, options = nil) source = source.encode('UTF-8') if source.respond_to?(:encode)
lock do
@v8_context.eval("(#{source})")
end
end
|
#exec(&block) ⇒ Object
29
30
31
|
# File 'lib/less/java_script/v8_context.rb', line 29
def exec(&block)
lock(&block)
end
|
#unwrap ⇒ Object
25
26
27
|
# File 'lib/less/java_script/v8_context.rb', line 25
def unwrap
@v8_context
end
|