amd 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/amd/amd.js.coffee.erb +48 -11
- data/lib/amd.rb +2 -0
- data/lib/amd/engine.rb +3 -2
- data/lib/amd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db2e59efa1f2538a86201b136fc8c575100b6df
|
4
|
+
data.tar.gz: 0849658743dddb48715249e9aa1c52503cef28c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056b367c07e907de24feab815421565d597818f148362272fc4f80747a2df573c08871315cc5a5ba76e8548bd53369b1837e86ee2fe28675902028251cfa310c
|
7
|
+
data.tar.gz: 823a90c77f55805050914d6de102b012304aa7dcc9ae3b11050dd9bd5fa55f58047b0b3ae24a557324a04da91345f933a4e051bc329e4077dfd08cbd743a9fae
|
@@ -1,5 +1,6 @@
|
|
1
|
-
window.__amd_table__
|
2
|
-
window.modules
|
1
|
+
window.__amd_table__ = {}
|
2
|
+
window.modules = {}
|
3
|
+
window.mod_to_load_count = 0
|
3
4
|
|
4
5
|
# Guess the js module to load from the action name
|
5
6
|
window.guess_module = ->
|
@@ -24,7 +25,7 @@ window.fetch_js = (url, callback) ->
|
|
24
25
|
body = document.getElementsByTagName('body')[0]
|
25
26
|
script = document.createElement 'script'
|
26
27
|
script.type = 'text/javascript'
|
27
|
-
script.src = "
|
28
|
+
script.src = "/<%= AMD::Engine.amd_dir %>/" + url
|
28
29
|
|
29
30
|
# Then bind the event to the callback function.
|
30
31
|
# There are several events for cross browser compatibility.
|
@@ -35,10 +36,13 @@ window.fetch_js = (url, callback) ->
|
|
35
36
|
body.appendChild script
|
36
37
|
|
37
38
|
|
39
|
+
# Define an AMD module as the given name with an array containing
|
40
|
+
# the name of its dependencies and with a given function as its
|
41
|
+
# actual body.
|
38
42
|
window.define = (name, deps, fn) ->
|
39
43
|
console.group('Define ' + name)
|
40
44
|
|
41
|
-
|
45
|
+
|
42
46
|
window.modules[name] = {
|
43
47
|
name: name,
|
44
48
|
deps: deps,
|
@@ -53,21 +57,54 @@ window.define = (name, deps, fn) ->
|
|
53
57
|
if m == undefined
|
54
58
|
m = require(dep)
|
55
59
|
|
56
|
-
modules_to_inject.push m if m != undefined
|
57
|
-
# end each
|
60
|
+
# modules_to_inject.push m if m != undefined
|
61
|
+
# # end each
|
62
|
+
|
63
|
+
# modules_to_inject.reverse().each (x) ->
|
64
|
+
# gmod = window.modules[x]
|
65
|
+
# if gmod != undefined
|
66
|
+
# fetched_modules = gmod.fn
|
67
|
+
window.mod_to_load_count = window.mod_to_load_count - 1
|
68
|
+
|
69
|
+
if window.mod_to_load_count == 0
|
70
|
+
$('body').trigger('dependencies_loaded')
|
58
71
|
|
59
72
|
console.groupEnd('Define ' + name);
|
60
|
-
fn.apply(fn,
|
73
|
+
#return fn.apply(fn, fetched_modules)
|
61
74
|
|
75
|
+
# Require the module file by it's name
|
62
76
|
window.require = (module_name) ->
|
63
|
-
path
|
77
|
+
path = to_module_path(module_name)
|
78
|
+
window.mod_to_load_count = window.mod_to_load_count + 1
|
79
|
+
|
80
|
+
if window.mod_to_load_count == 1
|
81
|
+
# We are at the main module require block
|
82
|
+
$('body').on 'dependencies_loaded', ->
|
83
|
+
window.run_module module_name
|
84
|
+
|
64
85
|
|
65
86
|
if path != undefined
|
66
|
-
|
67
|
-
console.log('Module "' +
|
87
|
+
fetch_js path, ->
|
88
|
+
console.log('Module "' +module_name+ "' loaded")
|
89
|
+
|
90
|
+
return module_name
|
68
91
|
|
69
|
-
return m
|
70
92
|
return undefined
|
71
93
|
|
94
|
+
# Call the function of the given module name by it's name
|
95
|
+
window.run_module = (name) ->
|
96
|
+
mod = window.modules[name]
|
97
|
+
fn_to_inject = []
|
98
|
+
|
99
|
+
if mod == undefined
|
100
|
+
throw 'No module found for "' +name+ '".'
|
101
|
+
|
102
|
+
if mod.deps.length != 0
|
103
|
+
mod.deps.each (dep) ->
|
104
|
+
fn_to_inject.push window.run_module(dep)
|
105
|
+
|
106
|
+
return mod.fn.apply(mod.fn, fn_to_inject)
|
107
|
+
|
108
|
+
|
72
109
|
$ ->
|
73
110
|
guess_module()
|
data/lib/amd.rb
CHANGED
data/lib/amd/engine.rb
CHANGED
@@ -3,7 +3,7 @@ module AMD
|
|
3
3
|
isolate_namespace AMD
|
4
4
|
|
5
5
|
initializer 'amd.configuration.assets' do |app|
|
6
|
-
app.config.assets.precompile = %w( *.amd.js* amd.js.coffee ) + app.config.assets.precompile
|
6
|
+
app.config.assets.precompile = %w( *.amd.js* *.amd.js.coffee ) + app.config.assets.precompile
|
7
7
|
end
|
8
8
|
|
9
9
|
def setup
|
@@ -14,7 +14,8 @@ module AMD
|
|
14
14
|
@@amd_dir = 'amd'
|
15
15
|
|
16
16
|
def self.amd_module(controller)
|
17
|
-
|
17
|
+
mod_path = controller.controller_path.split('/')[0..-2].join('/')
|
18
|
+
"#{mod_path}/#{controller.controller_name}/#{controller.action_name}"
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/amd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Rahmani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|