Class: MapLayers::JsClass
- Inherits:
-
Object
- Object
- MapLayers::JsClass
- Includes:
- JsWrapper
- Defined in:
- lib/map_layers/js_wrapper.rb
Overview
Minimal Wrapper around a Javascript class
Instance Attribute Summary
Attributes included from JsWrapper
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(*args) ⇒ JsClass
constructor
A new instance of JsClass.
Methods included from JsWrapper
#[], #assign_to, #declare, #declare_random, #declared?, escape_javascript, #get_property, javascriptify_method, #javascriptify_method_call, javascriptify_variable, #method_missing, #set_property, #to_javascript, #to_json
Constructor Details
#initialize(*args) ⇒ JsClass
Returns a new instance of JsClass.
153 154 155 |
# File 'lib/map_layers/js_wrapper.rb', line 153 def initialize(*args) @args = args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MapLayers::JsWrapper
Class Method Details
.const_missing(sym) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/map_layers/js_wrapper.rb', line 145 def self.const_missing(sym) if self.const_defined?(sym) k = self.const_get(sym) else k = self.const_set(sym, Class.new(JsClass)) end end |
Instance Method Details
#create ⇒ Object
157 158 159 160 161 162 |
# File 'lib/map_layers/js_wrapper.rb', line 157 def create jsclass = self.class.to_s.split(/::/)[1..-1] jsclass.insert(0, 'OpenLayers') unless jsclass[0] == 'OpenLayers' args = @args.collect{ |arg| JsWrapper.javascriptify_variable(arg) } JsExpr.new("new #{jsclass.join('.')}(#{args.join(',')})") end |