Sha256: 29ad55fd6c6bf26e7e36e957cdc62ef54660e680decfdcf305d05912e07a55fb
Contents?: true
Size: 1.06 KB
Versions: 4
Compression:
Stored size: 1.06 KB
Contents
require 'json' module Jsimple class Builder # Data holder for the JS app path and initializer App = Struct.new(:init, :path) class App end def self.app_factory(name, props, id) App.new(init_js(name, props, id), js_path(name)) end def self.js_path(name) if Jsimple.development js_development_path(name, Jsimple.host, Jsimple.port) else js_production_path(name) end end 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 # Path for JS bundle in production def self.js_production_path(name) "jsimple/#{name}.min.js" end # Path for JS in development def self.js_development_path(name, host, port) "http://#{host}:#{port}/#{name}.js" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
jsimple-0.4.0 | lib/jsimple/builder.rb |
jsimple-0.3.0 | lib/jsimple/builder.rb |
jsimple-0.2.0 | lib/jsimple/builder.rb |
jsimple-0.1.0 | lib/jsimple/builder.rb |