Class: Wedge
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Methods
- Defined in:
- lib/wedge.rb,
lib/wedge/dom.rb,
lib/wedge/html.rb,
lib/wedge/opal.rb,
lib/wedge/store.rb,
lib/wedge/config.rb,
lib/wedge/events.rb,
lib/wedge/railtie.rb,
lib/wedge/version.rb,
lib/wedge/component.rb,
lib/wedge/middleware.rb,
lib/wedge/plugins/form.rb,
lib/wedge/plugins/pjax.rb,
lib/wedge/plugins/render.rb,
lib/wedge/utilis/methods.rb,
lib/wedge/plugins/factory.rb,
lib/wedge/plugins/history.rb,
lib/wedge/plugins/uploader.rb,
lib/wedge/plugins/form_backup.rb,
lib/wedge/plugins/ability_list.rb,
lib/wedge/plugins/current_user.rb,
lib/wedge/utilis/indifferent_hash.rb,
lib/wedge/plugins/form/validations.rb
Defined Under Namespace
Modules: HTML, Methods, Plugins, Store
Classes: Component, Config, DOM, Events, IndifferentHash, Middleware, Railtie
Constant Summary
collapse
- ATTR_ACCESSORS =
%i{scope store config events method_called}
- Opal =
Create our own opal instance.
::Opal.dup
- VERSION =
'0.1.43'
- Form =
Wedge::Plugins::Form
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Methods
#client?, included, #server?
Class Method Details
Used to call a component.
162
163
164
|
# File 'lib/wedge.rb', line 162
def [](*args, &block)
config.component_class[args.shift].wedge_new self, *args, &block
end
|
.assets_url ⇒ Object
64
65
66
67
|
# File 'lib/wedge.rb', line 64
def assets_url
url = config.assets_url.gsub(%r{^(http(|s)://[^\/]*\/|\/)}, '/')
"#{url}#{config.cache_assets ? "/#{config.assets_key}" : ''}"
end
|
.assets_url_regex ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/wedge.rb', line 69
def assets_url_regex
@assets_url_regex ||= begin
assets_url = ::Wedge.assets_url.gsub(%r{^\/}, '')
%r{(?:#{assets_url}|#{assets_url.sub("#{::Wedge.config.assets_key}/", '')})/(.*)\.(.*)$}
end
end
|
.assets_url_with_host ⇒ Object
78
79
80
|
# File 'lib/wedge.rb', line 78
def assets_url_with_host
"#{config.assets_url}#{config.cache_assets ? "/#{config.assets_key}" : ''}"
end
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/wedge.rb', line 265
def config
@config ||= begin
args = { component_class: IndifferentHash.new }
unless RUBY_ENGINE == 'opal'
args[:path] = method(:assets_url).source_location.first.sub('/wedge.rb', '')
args[:assets_key] = begin
if defined?(PlatformAPI) && ENV['HEROKU_TOKEN'] && ENV['HEROKU_APP']
heroku = PlatformAPI.connect_oauth(ENV['HEROKU_TOKEN'], default_headers: {'Range' => 'version ..; order=desc'})
slug_id = heroku.release.list(ENV['HEROKU_APP']).first["slug"]["id"]
heroku.slug.info(ENV['HEROKU_APP'], slug_id)["commit"]
else
`git rev-parse HEAD 2>/dev/null`.to_s.strip
end
end
end
Config.new(args)
end
end
|
151
152
153
|
# File 'lib/wedge.rb', line 151
def events
@events ||= Events.new
end
|
.html!(scope = false, &block) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/wedge.rb', line 82
def html!(scope = false, &block)
if !block_given?
html = HTML::DSL.html(&scope).to_html
else
html = HTML::DSL.scope!(scope).html(&block).to_html
end
DOM.new html
end
|
.javascript(path_name = 'wedge', options = {}) ⇒ Object
Return the opal javascript.
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/wedge.rb', line 204
def javascript(path_name = 'wedge', options = {})
path_name = path_name.to_s
if server?
javascript_cache[path_name] ||= begin
build(path_name, options).to_s
end
else
cache = options[:cache_assets]
if !Wedge.config.debug
url = "#{Wedge.assets_url_with_host}/#{options[:path]}.js"
`jQuery.ajax({ url: url, dataType: "script", cache: cache }).done(function() {`
trigger_javascript_loaded path_name, options
`}).fail(function(jqxhr, settings, exception){ window.console.log(exception); })`
else
url = "#{Wedge.assets_url_with_host}/wedge/list_assets.call"
payload = { path_name: path_name}
= {
'X-CSRF-TOKEN' => Element.find('meta[name=_csrf]').attr('content'),
}
HTTP.post(url, dataType: 'json', headers: , payload: payload) do |response|
res = JSON.from_object(`response`)
res[:body][:urls].each do |url|
`jQuery.ajax({url: url, dataType: "script", cache: cache, async: false})`
end
code = res[:body][:code]
`jQuery.globalEval(code);`
trigger_javascript_loaded path_name, options
end
end
end
end
|
.load_settings(settings) ⇒ Object
.trigger(wedge_name, event_name, *args) ⇒ Object
147
148
149
|
# File 'lib/wedge.rb', line 147
def trigger(wedge_name, event_name, *args)
events.trigger wedge_name, event_name, *args
end
|
.trigger_javascript_loaded(path_name, options) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/wedge.rb', line 244
def trigger_javascript_loaded path_name, options
Wedge.config.component_class[options[:name]].config.store = options[:store].indifferent
if initialize_args = options.delete(:initialize_args)
comp = Wedge[options[:name], *initialize_args]
else
comp = Wedge[options[:name]]
end
if options[:method_args].any?
comp.send(options[:method_called], options[:method_args])
else
comp.send(options[:method_called])
end
Wedge.trigger_browser_events
end
|
80
81
82
|
# File 'lib/wedge/opal.rb', line 80
def self.version
Wedge::VERSION
end
|
Instance Method Details
#append_paths ⇒ Array
Append the correct paths to opal.
195
196
197
198
199
200
|
# File 'lib/wedge.rb', line 195
def append_paths
@append_paths ||= begin
Wedge::Opal.append_path method(:assets_url).source_location.first.sub('/wedge.rb', '')
Wedge::Opal.append_path "#{Dir.pwd}/#{config.app_dir}"
end
end
|
Returns the build object for opal.
183
184
185
|
# File 'lib/wedge.rb', line 183
def build(path = 'wedge', options = {})
Opal::Builder.build(path, options) if append_paths
end
|
#get_asset_urls(name) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/wedge.rb', line 113
def get_asset_urls name
sprockets = Wedge.config.opal[:server].sprockets
prefix = Wedge.assets_url_with_host
asset = sprockets[name]
raise "Cannot find asset: #{name}" if asset.nil?
urls = []
if Wedge.config.opal[:server].debug
asset.to_a.map do |dependency|
urls << %{#{prefix}/#{dependency.logical_path}?body=1}
end
else
urls << %{#{prefix}/#{name}.js}
end
urls
end
|
#javascript_cache ⇒ Object
131
132
133
|
# File 'lib/wedge.rb', line 131
def javascript_cache
@javascript_cache ||= IndifferentHash.new
end
|
#script_tag(name = 'wedge') ⇒ Object
def script_tag
"<script src='#{assets_url_with_host}/wedge.js#{Wedge.config.debug ? '?body=1' : ''}' type='text/javascript'></script>"
end
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/wedge.rb', line 98
def script_tag name = 'wedge'
sprockets = Wedge.config.opal[:server].sprockets
asset = sprockets[name]
raise "Cannot find asset: #{name}" if asset.nil?
scripts = []
get_asset_urls(name).each do |url|
scripts << %{<script src="#{url}"></script>}
end
scripts << %{<script>#{Wedge::Opal::Processor.load_asset_code(sprockets, name)}</script>}
scripts.join "\n"
end
|
#source_map(path = 'wedge', options = {}) ⇒ Object
Source maps for the javascript
188
189
190
|
# File 'lib/wedge.rb', line 188
def source_map(path = 'wedge', options = {})
build(path, options).source_map
end
|
#trigger_browser_events ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/wedge.rb', line 137
def trigger_browser_events
config.component_class.each do |k, klass|
next if klass.config.triggered_browser_events
klass.config.triggered_browser_events = true
Wedge.trigger klass.config.name, :browser_events
end
end
|