Module: BrowserIO
- Includes:
- Methods
- Defined in:
- lib/browserio.rb,
lib/browserio/dom.rb,
lib/browserio/html.rb,
lib/browserio/opal.rb,
lib/browserio/config.rb,
lib/browserio/events.rb,
lib/browserio/version.rb,
lib/browserio/component.rb,
lib/browserio/plugins/form.rb,
lib/browserio/plugins/pjax.rb,
lib/browserio/utilis/methods.rb,
lib/browserio/plugins/history.rb,
lib/browserio/plugins/validations.rb,
lib/browserio/utilis/indifferent_hash.rb
Defined Under Namespace
Modules: HTML, Methods, Plugins Classes: Component, Config, DOM, Events, IndifferentHash
Constant Summary collapse
Class Method Summary collapse
-
.[](name, *args) ⇒ BrowserIO::Component#method
Used to call a component.
- .components ⇒ Object
- .get_requires(requires, reqs = [], from_get = false) ⇒ Object
-
.javascript(name = 'browserio', options = {}, promise = false) ⇒ Object
Return the opal javascript.
- .opts ⇒ Object
-
.setup {|Config| ... } ⇒ Object
Used to setup the component with default options.
Instance Method Summary collapse
-
#append_paths ⇒ Array
Append the correct paths to opal.
-
#build(path = 'browserio', options = {}) ⇒ String, Opal::Builder#build
Returns the build object for opal.
-
#source_map(path = 'browserio', options = {}) ⇒ Object
Source maps for the javascript.
Methods included from Methods
Class Method Details
.[](name, *args) ⇒ BrowserIO::Component#method
Used to call a component.
31 32 33 34 35 |
# File 'lib/browserio.rb', line 31 def [](name, *args) component = components[name.to_sym] component.klass.new(*args) end |
.components ⇒ Object
37 38 39 |
# File 'lib/browserio.rb', line 37 def components @components ||= OpenStruct.new end |
.get_requires(requires, reqs = [], from_get = false) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/browserio.rb', line 116 def get_requires requires, reqs = [], from_get = false promises = [] requires.each do |r| if r[:requires].any? promises << (promise = ::Opal::Promise.new) a = [] c = [] get_requires(r[:requires], a, true) a.each do |re| c << -> do p = ::Opal::Promise.new path_name = re.delete(:path_name) BrowserIO.javascript(path_name, re.reject { |k, v| k.to_s == 'requires'}, p) p end end ::Opal::Promise.when(*c.map!(&:call)).then do |*args| path_name = r.delete(:path_name) BrowserIO.javascript(path_name, r.reject { |k, v| k.to_s == 'requires'}, promise) end else reqs << r if !from_get promises << (promise = ::Opal::Promise.new) path_name = r.delete(:path_name) BrowserIO.javascript(path_name, r.reject { |k, v| k.to_s == 'requires'}, promise) end end end promises end |
.javascript(name = 'browserio', options = {}, promise = false) ⇒ Object
Return the opal javascript.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/browserio.rb', line 69 def javascript(name = 'browserio', = {}, promise = false) if server? if name == 'browserio' @bio_javascript ||= build(name, ).javascript else js = build(name, ).javascript comp_name = components.to_h.select { |k, v| v.path_name == name }.first.last.name comp = BrowserIO[comp_name] = comp.client_bio_opts compiled_opts = Base64.encode64 .to_json js << Opal.compile("BrowserIO.components[:#{comp_name}].klass.instance_variable_set(:@bio_config, BrowserIO::Config.new(BrowserIO.components[:#{comp_name}].klass.bio_config.opts_dup.merge(JSON.parse(Base64.decode64('#{compiled_opts}')))))") js end else opts.loaded ||= {} if !opts.loaded.keys.include? name opts.loaded[name] = false assets_url = [:assets_url] `$.getScript("/" + assets_url + "/" + name + ".js").done(function(){` BrowserIO.opts.loaded[name] = true method_called = .delete(:method_called) method_args = .delete(:method_args) name = .delete(:name) comp = BrowserIO[name, ] requires = comp.bio_opts.requires if requires.present? && requires.first.is_a?(Hash) comps = [] ::Opal::Promise.when(*get_requires(requires, comps)).then do comp.send(method_called, *method_args) if method_called comp.bio_trigger :browser_events end else comp.send(method_called, *method_args) if method_called comp.bio_trigger :browser_events end promise.resolve true if promise `}).fail(function(jqxhr, settings, exception){ window.console.log(exception); });` end end end |
.opts ⇒ Object
185 186 187 |
# File 'lib/browserio.rb', line 185 def opts config.opts end |
.setup {|Config| ... } ⇒ Object
Used to setup the component with default options.
167 168 169 170 |
# File 'lib/browserio.rb', line 167 def setup(&block) javascript # This pre-compiles the core and store it in mem block.call config end |
Instance Method Details
#append_paths ⇒ Array
Append the correct paths to opal.
59 60 61 62 63 64 65 |
# File 'lib/browserio.rb', line 59 def append_paths @append_paths ||= begin file = method(:components).source_location.first.sub('/browserio.rb', '') BrowserIO::Opal.append_path file BrowserIO::Opal.append_path Dir.pwd end end |
#build(path = 'browserio', options = {}) ⇒ String, Opal::Builder#build
Returns the build object for opal.
46 47 48 49 |
# File 'lib/browserio.rb', line 46 def build(path = 'browserio', = {}) append_paths Opal::Builder.build(path, ) end |
#source_map(path = 'browserio', options = {}) ⇒ Object
Source maps for the javascript
52 53 54 |
# File 'lib/browserio.rb', line 52 def source_map(path = 'browserio', = {}) build(path, ).source_map end |