Class: Jsimple::Builder
- Inherits:
-
Object
- Object
- Jsimple::Builder
- Defined in:
- lib/jsimple/builder.rb
Defined Under Namespace
Classes: App
Class Method Summary collapse
-
._path_join(path, file_name) ⇒ Object
private.
- .app_factory(name, props, id) ⇒ Object
- .init_js(name, props, id) ⇒ Object
-
.js_development_path(name, host, port) ⇒ Object
Path for JS in development.
- .js_path(name) ⇒ Object
-
.js_production_path(name) ⇒ Object
Path for JS bundle in production.
Class Method Details
._path_join(path, file_name) ⇒ Object
private
44 45 46 |
# File 'lib/jsimple/builder.rb', line 44 def self._path_join(path, file_name) [path, file_name].reject(&:empty?).join('/') end |
.app_factory(name, props, id) ⇒ Object
10 11 12 |
# File 'lib/jsimple/builder.rb', line 10 def self.app_factory(name, props, id) App.new(init_js(name, props, id), js_path(name)) end |
.init_js(name, props, id) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/jsimple/builder.rb', line 22 def self.init_js(name, props, id) dom_element = "document.getElementById('#{id || name}')" js_object = "JSON.parse('#{JSON.dump(props)}')" # <script> # ExampleName.start(document.getElementById('ExampleName'), JSON.parse('{}')); # </script> "<script>#{name}.#{Jsimple.js_start_command}(#{dom_element}, #{js_object});</script>" end |
.js_development_path(name, host, port) ⇒ Object
Path for JS in development
37 38 39 40 |
# File 'lib/jsimple/builder.rb', line 37 def self.js_development_path(name, host, port) path = _path_join(Jsimple.js_dev_path_prefix, "#{name}.js") "http://#{host}:#{port}/#{path}" end |
.js_path(name) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/jsimple/builder.rb', line 14 def self.js_path(name) if Jsimple.development js_development_path(name, Jsimple.host, Jsimple.port) else js_production_path(name) end end |
.js_production_path(name) ⇒ Object
Path for JS bundle in production
32 33 34 |
# File 'lib/jsimple/builder.rb', line 32 def self.js_production_path(name) _path_join(Jsimple.js_path_prefix, "#{name}.min.js") end |