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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81d9d3b46ec76a90a0f536aabdf166b59fce2d49
4
- data.tar.gz: 5bf2dd78b7858241ae9fb4c699d84bcf185a376a
3
+ metadata.gz: 1db2e59efa1f2538a86201b136fc8c575100b6df
4
+ data.tar.gz: 0849658743dddb48715249e9aa1c52503cef28c3
5
5
  SHA512:
6
- metadata.gz: 3af80de1ff07b0d78e954dc6d90c6ac27d492f78382fd1d634fb587e43af3da1232d0c48888fdc552989adfbc6dba3ea8fcc402bfbb26f8401d1a1b4df517424
7
- data.tar.gz: e171ba68e1479ce1ccffaa90840394fa282756e22eb742a73f5b4040b75325710a3bff92577d3a0c66b9b848ae14da8699217101333d7b581fb0ad5b6cca6438
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 = "<%= AMD::Engine.amd_dir %>/" + url
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
- modules_to_inject = []
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, modules_to_inject)
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 = to_module_path(module_name)
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
- m = fetch_js path, ->
67
- console.log('Module "' + module_name +"' loaded")
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
@@ -1,4 +1,6 @@
1
+
1
2
  require 'amd/engine'
3
+ require 'amd/controller_helper'
2
4
 
3
5
  module AMD
4
6
  # Your code goes here...
@@ -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
- "#{controller.controller_path}/amd/#{controller.controller_name}/#{controller.action_name}"
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
@@ -1,3 +1,3 @@
1
1
  module AMD
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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.3
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-17 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails