modularity-rails 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/lib/modularity-rails/version.rb +1 -1
- data/spec/javascripts/mixins/closable_spec.coffee +8 -8
- data/spec/javascripts/modularity_spec.coffee +26 -25
- data/spec/javascripts/modules/button_spec.coffee +3 -3
- data/spec/javascripts/modules/counter_button_spec.coffee +4 -4
- data/spec/javascripts/tools/ajax_loader_spec.coffee +18 -18
- data/spec/javascripts/tools/cache_spec.coffee +1 -1
- data/vendor/assets/javascripts/mixins/clickable.coffee +2 -2
- data/vendor/assets/javascripts/mixins/closable.coffee +1 -1
- data/vendor/assets/javascripts/modularity.js.coffee +31 -29
- data/vendor/assets/javascripts/modules/button.coffee +2 -2
- data/vendor/assets/javascripts/modules/counter_button.coffee +1 -1
- data/vendor/assets/javascripts/tools/ajax_loader.coffee +16 -11
- metadata +13 -13
data/.travis.yml
CHANGED
@@ -7,8 +7,8 @@ describe 'test environment setup', ->
|
|
7
7
|
loadCS "/vendor/assets/javascripts/mixins/closable.coffee"
|
8
8
|
|
9
9
|
# A standard closable module.
|
10
|
-
class window.ClosableModule1 extends Module
|
11
|
-
@mixin closable
|
10
|
+
class window.ClosableModule1 extends modularity.Module
|
11
|
+
@mixin modularity.closable
|
12
12
|
|
13
13
|
|
14
14
|
describe 'Closable', ->
|
@@ -37,8 +37,8 @@ describe 'Closable', ->
|
|
37
37
|
it "calls the closable_closing hook on the object if it exists", ->
|
38
38
|
|
39
39
|
# A closable module with the 'closing' hook.
|
40
|
-
class ClosableModule extends Module
|
41
|
-
@mixin closable
|
40
|
+
class ClosableModule extends modularity.Module
|
41
|
+
@mixin modularity.closable
|
42
42
|
|
43
43
|
constructor: ->
|
44
44
|
super
|
@@ -55,8 +55,8 @@ describe 'Closable', ->
|
|
55
55
|
it "calls the closable_closed hook on the object if it exists", ->
|
56
56
|
|
57
57
|
# A closable module with the 'closed' hook.
|
58
|
-
class ClosableModule extends Module
|
59
|
-
@mixin closable
|
58
|
+
class ClosableModule extends modularity.Module
|
59
|
+
@mixin modularity.closable
|
60
60
|
|
61
61
|
constructor: ->
|
62
62
|
super
|
@@ -72,8 +72,8 @@ describe 'Closable', ->
|
|
72
72
|
|
73
73
|
it "aborts the close operation if the closable_closing method returns false", ->
|
74
74
|
|
75
|
-
class ClosableModuleWithHookThatReturnsFalse extends Module
|
76
|
-
@mixin closable
|
75
|
+
class ClosableModuleWithHookThatReturnsFalse extends modularity.Module
|
76
|
+
@mixin modularity.closable
|
77
77
|
closable_closing: -> false
|
78
78
|
|
79
79
|
module = new ClosableModuleWithHookThatReturnsFalse('#test #closable1')
|
@@ -7,7 +7,7 @@ describe 'setting up test environment', ->
|
|
7
7
|
|
8
8
|
it 'defining test classes', ->
|
9
9
|
|
10
|
-
class window.TestModule extends Module
|
10
|
+
class window.TestModule extends modularity.Module
|
11
11
|
constructor: (container) ->
|
12
12
|
super
|
13
13
|
|
@@ -22,7 +22,7 @@ describe 'modularity', ->
|
|
22
22
|
spyOn window, 'alert'
|
23
23
|
|
24
24
|
it "is defined on the 'window' object", ->
|
25
|
-
expect(
|
25
|
+
expect(modularity.Module).not.toBeUndefined()
|
26
26
|
|
27
27
|
it 'shows an error if no container is given', ->
|
28
28
|
new TestModule()
|
@@ -55,34 +55,34 @@ describe 'modularity', ->
|
|
55
55
|
spyOn window, 'alert'
|
56
56
|
|
57
57
|
it 'shows an alert with the given message if the given condition is false', ->
|
58
|
-
|
58
|
+
modularity.assert false, 'Message'
|
59
59
|
expect(alert).toHaveBeenCalledWith("Message")
|
60
60
|
|
61
61
|
it 'fails when the condition is null', ->
|
62
|
-
|
62
|
+
modularity.assert null, 'Message'
|
63
63
|
expect(alert).toHaveBeenCalledWith("Message")
|
64
64
|
|
65
65
|
it 'fails when the condition is undefined', ->
|
66
|
-
|
66
|
+
modularity.assert undefined, 'Message'
|
67
67
|
expect(alert).toHaveBeenCalledWith("Message")
|
68
68
|
|
69
69
|
it 'fails when the condition is an empty array', ->
|
70
|
-
|
70
|
+
modularity.assert [], 'Message'
|
71
71
|
expect(alert).toHaveBeenCalledWith("Message")
|
72
72
|
|
73
73
|
it 'fails when the condition is an empty string', ->
|
74
|
-
|
74
|
+
modularity.assert '', 'Message'
|
75
75
|
expect(alert).toHaveBeenCalledWith("Message")
|
76
76
|
|
77
77
|
it 'passes when the condition is a string', ->
|
78
|
-
|
78
|
+
modularity.assert '123', 'Message'
|
79
79
|
expect(alert).not.toHaveBeenCalled()
|
80
80
|
|
81
81
|
it "returns false if the condition doesn't pass", ->
|
82
|
-
expect(
|
82
|
+
expect(modularity.assert(false)).toBeFalsy()
|
83
83
|
|
84
84
|
it "returns true if the condition passes", ->
|
85
|
-
expect(
|
85
|
+
expect(modularity.assert('123')).toBeTruthy()
|
86
86
|
|
87
87
|
|
88
88
|
describe 'jQuery Integration', ->
|
@@ -95,7 +95,7 @@ describe 'modularity', ->
|
|
95
95
|
expect(alert).not.toHaveBeenCalled()
|
96
96
|
|
97
97
|
it 'returns the created instance', ->
|
98
|
-
result = $('#test #module_container').module(Module)
|
98
|
+
result = $('#test #module_container').module(modularity.Module)
|
99
99
|
expect(result).toBeDefined()
|
100
100
|
expect(typeof result).toEqual('object')
|
101
101
|
|
@@ -104,7 +104,7 @@ describe 'modularity', ->
|
|
104
104
|
expect(alert).toHaveBeenCalled()
|
105
105
|
|
106
106
|
it 'returns an error if the jQuery object is empty.', ->
|
107
|
-
$('#test #zonk').module(Module)
|
107
|
+
$('#test #zonk').module(modularity.Module)
|
108
108
|
expect(alert).toHaveBeenCalled()
|
109
109
|
|
110
110
|
|
@@ -195,7 +195,7 @@ describe 'modularity', ->
|
|
195
195
|
|
196
196
|
beforeEach ->
|
197
197
|
mockGlobalContainer = $('#test #module_container')
|
198
|
-
spyOn(
|
198
|
+
spyOn(modularity, 'global_event_container').andReturn(mockGlobalContainer)
|
199
199
|
|
200
200
|
describe 'bind_global_event', ->
|
201
201
|
|
@@ -204,31 +204,31 @@ describe 'modularity', ->
|
|
204
204
|
|
205
205
|
it 'binds the given event type and callback method to the global event container', ->
|
206
206
|
callback = ->
|
207
|
-
|
207
|
+
modularity.bind_global_event '123', callback
|
208
208
|
expect(mockGlobalContainer.bind).toHaveBeenCalledWith('123', callback)
|
209
209
|
|
210
210
|
it "throws an error if no parameters are given", ->
|
211
|
-
|
211
|
+
modularity.bind_global_event()
|
212
212
|
expect(window.alert).toHaveBeenCalled()
|
213
213
|
expect(mockGlobalContainer.bind).not.toHaveBeenCalled()
|
214
214
|
|
215
215
|
it "throws an error if the given event type doesn't exist", ->
|
216
|
-
|
216
|
+
modularity.bind_global_event undefined, ->
|
217
217
|
expect(window.alert).toHaveBeenCalled()
|
218
218
|
expect(mockGlobalContainer.bind).not.toHaveBeenCalled()
|
219
219
|
|
220
220
|
it 'throws an error if the given event type is not a string', ->
|
221
|
-
|
221
|
+
modularity.bind_global_event {}, ->
|
222
222
|
expect(window.alert).toHaveBeenCalled()
|
223
223
|
expect(mockGlobalContainer.bind).not.toHaveBeenCalled()
|
224
224
|
|
225
225
|
it "throws an error if the given callback doesn't exist", ->
|
226
|
-
|
226
|
+
modularity.bind_global_event '123'
|
227
227
|
expect(window.alert).toHaveBeenCalled()
|
228
228
|
expect(mockGlobalContainer.bind).not.toHaveBeenCalled()
|
229
229
|
|
230
230
|
it 'throws an error if the given callback is not a function', ->
|
231
|
-
|
231
|
+
modularity.bind_global_event '123', {}
|
232
232
|
expect(window.alert).toHaveBeenCalled()
|
233
233
|
expect(mockGlobalContainer.bind).not.toHaveBeenCalled()
|
234
234
|
|
@@ -239,30 +239,31 @@ describe 'modularity', ->
|
|
239
239
|
spyOn mockGlobalContainer, 'trigger'
|
240
240
|
|
241
241
|
it 'triggers a custom jQuery event with the given event type on the global event container object', ->
|
242
|
-
|
242
|
+
modularity.fire_global_event 'event type', 'event data'
|
243
243
|
expect(mockGlobalContainer.trigger).toHaveBeenCalledWith('event type', 'event data')
|
244
244
|
|
245
245
|
describe 'when no payload is given', ->
|
246
246
|
it 'provides an empty object as payload', ->
|
247
|
-
|
247
|
+
modularity.fire_global_event 'event type'
|
248
248
|
expect(mockGlobalContainer.trigger).toHaveBeenCalled()
|
249
249
|
expect(mockGlobalContainer.trigger.argsForCall[0][1]).toEqual({})
|
250
250
|
|
251
251
|
it "doesn't change the original payload variable", ->
|
252
252
|
data = undefined
|
253
|
-
|
253
|
+
modularity.fire_global_event 'event type', data
|
254
254
|
expect(data).toBeUndefined
|
255
255
|
|
256
256
|
it 'provides 0 as payload if 0 is given', ->
|
257
|
-
|
257
|
+
modularity.fire_global_event 'event type', 0
|
258
258
|
expect(mockGlobalContainer.trigger).toHaveBeenCalled()
|
259
259
|
expect(mockGlobalContainer.trigger.argsForCall[0][1]).toEqual(0)
|
260
260
|
|
261
261
|
it 'throws an error if the given event type is not a string', ->
|
262
|
-
|
262
|
+
modularity.fire_global_event {}
|
263
263
|
expect(mockGlobalContainer.trigger).not.toHaveBeenCalled()
|
264
264
|
expect(window.alert).toHaveBeenCalled()
|
265
265
|
|
266
|
+
|
266
267
|
describe 'mixins', ->
|
267
268
|
|
268
269
|
myMixin = instance = recordedSelf = Test = null
|
@@ -272,7 +273,7 @@ describe 'modularity', ->
|
|
272
273
|
method2: ->
|
273
274
|
|
274
275
|
beforeEach ->
|
275
|
-
class Test extends Module
|
276
|
+
class Test extends modularity.Module
|
276
277
|
@mixin myMixin
|
277
278
|
|
278
279
|
|
@@ -14,7 +14,7 @@ describe 'Button', ->
|
|
14
14
|
describe 'manual clicks', ->
|
15
15
|
|
16
16
|
it 'fires when clicking on the container directly', ->
|
17
|
-
button = new
|
17
|
+
button = new modularity.Button($('#test #button1'))
|
18
18
|
button.bind_event('clicked', (spy = jasmine.createSpy()))
|
19
19
|
|
20
20
|
button.container.click()
|
@@ -24,7 +24,7 @@ describe 'Button', ->
|
|
24
24
|
|
25
25
|
|
26
26
|
it 'fires when clicking embedded elements of the button', ->
|
27
|
-
button = new
|
27
|
+
button = new modularity.Button($('#test #button2'))
|
28
28
|
button.bind_event('clicked', (spy = jasmine.createSpy()))
|
29
29
|
|
30
30
|
button.container.find('.embedded').click()
|
@@ -36,7 +36,7 @@ describe 'Button', ->
|
|
36
36
|
describe 'programmatic clicks', ->
|
37
37
|
|
38
38
|
it 'programmatically clicks the button', ->
|
39
|
-
button = new
|
39
|
+
button = new modularity.Button($('#test #button2'))
|
40
40
|
spy = jasmine.createSpy()
|
41
41
|
button.bind_event('clicked', spy)
|
42
42
|
|
@@ -17,7 +17,7 @@ describe 'CounterButton', ->
|
|
17
17
|
describe 'manual clicks', ->
|
18
18
|
|
19
19
|
it 'fires when clicking on the container directly', ->
|
20
|
-
button = new
|
20
|
+
button = new modularity.CounterButton('#test #button1')
|
21
21
|
button.bind_event('clicked', (spy = jasmine.createSpy()))
|
22
22
|
|
23
23
|
button.container.click()
|
@@ -27,7 +27,7 @@ describe 'CounterButton', ->
|
|
27
27
|
|
28
28
|
|
29
29
|
it 'fires when clicking embedded elements of the button', ->
|
30
|
-
button = new
|
30
|
+
button = new modularity.CounterButton('#test #button2')
|
31
31
|
button.bind_event('clicked', (spy = jasmine.createSpy()))
|
32
32
|
|
33
33
|
button.container.find('.embedded').click()
|
@@ -38,7 +38,7 @@ describe 'CounterButton', ->
|
|
38
38
|
describe 'programmatic clicks', ->
|
39
39
|
|
40
40
|
it 'programmatically clicks the button', ->
|
41
|
-
button = new
|
41
|
+
button = new modularity.CounterButton('#test #button2')
|
42
42
|
spy = jasmine.createSpy()
|
43
43
|
button.bind_event('clicked', spy)
|
44
44
|
|
@@ -49,7 +49,7 @@ describe 'CounterButton', ->
|
|
49
49
|
describe 'CounterButton specific functionality', ->
|
50
50
|
|
51
51
|
it 'provides the click counter as the event payload', ->
|
52
|
-
button = new
|
52
|
+
button = new modularity.CounterButton('#test #button1')
|
53
53
|
button.bind_event('clicked', (spy = jasmine.createSpy()))
|
54
54
|
|
55
55
|
button.container.click()
|
@@ -1,30 +1,31 @@
|
|
1
|
-
#= require spec_helper
|
2
|
-
|
3
1
|
describe 'test environment setup', ->
|
4
2
|
|
5
3
|
it 'loading libraries', ->
|
6
4
|
load_modularity()
|
5
|
+
loadCS "/vendor/assets/javascripts/tools/cache.coffee"
|
7
6
|
loadCS "/vendor/assets/javascripts/tools/ajax_loader.coffee"
|
8
7
|
|
9
8
|
|
10
9
|
describe 'ajax_loader', ->
|
11
10
|
|
11
|
+
ajax_loader = null
|
12
|
+
beforeEach ->
|
13
|
+
ajax_loader = new modularity.AjaxLoader()
|
14
|
+
|
12
15
|
describe 'get', ->
|
16
|
+
|
17
|
+
url = "/users/4"
|
13
18
|
spy = null
|
14
19
|
beforeEach ->
|
15
20
|
spyOn(jQuery, 'get')
|
16
21
|
spy = jasmine.createSpy()
|
17
|
-
Module.loader.cache = {}
|
18
|
-
|
19
|
-
url = "user/4"
|
20
22
|
|
21
23
|
describe 'the data has already been loaded', ->
|
24
|
+
|
22
25
|
it 'calls the callback with the cached data', ->
|
23
|
-
|
24
|
-
url = "/users/4"
|
26
|
+
ajax_loader.cache.add url, "my data"
|
25
27
|
|
26
|
-
|
27
|
-
Module.loader.get(url, spy)
|
28
|
+
ajax_loader.get(url, spy)
|
28
29
|
|
29
30
|
expect(spy).toHaveBeenCalled()
|
30
31
|
expect(spy.argsForCall[0][0]).toEqual("my data")
|
@@ -33,13 +34,12 @@ describe 'ajax_loader', ->
|
|
33
34
|
describe 'the request is already in progress', ->
|
34
35
|
|
35
36
|
beforeEach ->
|
36
|
-
|
37
|
-
Module.loader.get(url, spy)
|
37
|
+
ajax_loader.cache.cache[url] = [spy]
|
38
38
|
|
39
39
|
|
40
40
|
it 'adds the callback to the callback array', ->
|
41
|
-
expect(
|
42
|
-
expect(
|
41
|
+
expect(ajax_loader.cache.get(url).length).toEqual(1)
|
42
|
+
expect(ajax_loader.cache.get(url)[0]).toEqual(spy)
|
43
43
|
|
44
44
|
|
45
45
|
it 'returns without calling the callback', ->
|
@@ -54,15 +54,15 @@ describe 'ajax_loader', ->
|
|
54
54
|
describe 'first time request', ->
|
55
55
|
|
56
56
|
beforeEach ->
|
57
|
-
|
57
|
+
ajax_loader.get(url, spy)
|
58
58
|
|
59
59
|
it 'makes an ajax request', ->
|
60
60
|
expect(jQuery.get).toHaveBeenCalled()
|
61
61
|
|
62
62
|
|
63
63
|
it 'saves the callback for later', ->
|
64
|
-
expect(
|
65
|
-
expect(
|
64
|
+
expect(ajax_loader.cache.get(url).length).toEqual(1)
|
65
|
+
expect(ajax_loader.cache.get(url)[0]).toEqual(spy)
|
66
66
|
|
67
67
|
it 'returns without calling the callback', ->
|
68
68
|
expect(spy).not.toHaveBeenCalled()
|
@@ -74,7 +74,7 @@ describe 'ajax_loader', ->
|
|
74
74
|
beforeEach ->
|
75
75
|
jquery_callback = null
|
76
76
|
jQuery.get = (url, callback) -> jquery_callback = callback
|
77
|
-
|
77
|
+
ajax_loader.get url, spy
|
78
78
|
jquery_callback('result')
|
79
79
|
|
80
80
|
it 'calls the given callbacks', ->
|
@@ -82,4 +82,4 @@ describe 'ajax_loader', ->
|
|
82
82
|
expect(spy.argsForCall[0][0]).toEqual('result')
|
83
83
|
|
84
84
|
it 'replaces the cache callbacks with returned data', ->
|
85
|
-
expect(
|
85
|
+
expect(ajax_loader.cache.get(url)).toEqual('result')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This mixin adds a 'clickable' aspect to modules.
|
2
2
|
# This means clicking anywhere on the module fires the 'clicked' event.
|
3
|
-
window.clickable =
|
3
|
+
window.modularity.clickable =
|
4
4
|
|
5
5
|
constructor: ->
|
6
6
|
@container.click @container_clicked
|
@@ -17,5 +17,5 @@ window.clickable =
|
|
17
17
|
|
18
18
|
|
19
19
|
# Event handler for clicks on this clickable element.
|
20
|
-
container_clicked: -> @fire_event clickable.events.clicked
|
20
|
+
container_clicked: -> @fire_event modularity.clickable.events.clicked
|
21
21
|
|
@@ -5,7 +5,35 @@
|
|
5
5
|
# Please see https://github.com/kevgo/modularity for more information.
|
6
6
|
|
7
7
|
|
8
|
-
window.modularity
|
8
|
+
window.modularity = {
|
9
|
+
|
10
|
+
# Checks whether the given condition is true.
|
11
|
+
# Shows an alert with the given message if not.
|
12
|
+
assert: (condition, message) ->
|
13
|
+
condition_ok = condition?.length > 0
|
14
|
+
alert(message) unless condition_ok
|
15
|
+
condition_ok
|
16
|
+
|
17
|
+
|
18
|
+
# GLOBAL EVENTS.
|
19
|
+
|
20
|
+
# Subscribes to the given global event,
|
21
|
+
# i.e. calls the given function when the given global event type happens.
|
22
|
+
bind_global_event: (event_type, callback) ->
|
23
|
+
return unless modularity.assert event_type, "modularity.bind_global_event: parameter 'event_type' is empty"
|
24
|
+
return alert "modularity.bind_global_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
|
25
|
+
modularity.global_event_container().bind event_type, callback
|
26
|
+
|
27
|
+
# Fires the given global event with the given data payload.
|
28
|
+
fire_global_event: (event_type, data) ->
|
29
|
+
modularity.assert event_type, 'Module.fire_global_event: You must provide the event type to fire.'
|
30
|
+
return alert("Module.fire_global_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
|
31
|
+
modularity.global_event_container().trigger event_type, data ?= []
|
32
|
+
|
33
|
+
# Returns the DOM object that is used to fire global events on.
|
34
|
+
global_event_container: -> modularity.global_event_container_cache or= $(window)
|
35
|
+
}
|
36
|
+
|
9
37
|
|
10
38
|
class window.modularity.Module
|
11
39
|
|
@@ -34,24 +62,17 @@ class window.modularity.Module
|
|
34
62
|
mixin_data.mixin.constructor.apply @, arguments
|
35
63
|
|
36
64
|
|
37
|
-
# Checks whether the given condition is true.
|
38
|
-
# Shows an alert with the given message if not.
|
39
|
-
@assert: (condition, message) ->
|
40
|
-
condition_ok = condition?.length > 0
|
41
|
-
alert(message) unless condition_ok
|
42
|
-
condition_ok
|
43
|
-
|
44
65
|
# MODULE EVENTS.
|
45
66
|
|
46
67
|
# Calls the given function when this widget fires the given local event.
|
47
68
|
bind_event: (event_type, callback) =>
|
48
|
-
return unless
|
69
|
+
return unless modularity.assert event_type, "Module.bind_event: parameter 'event_type' is empty"
|
49
70
|
return alert "Module.bind_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
|
50
71
|
@container.bind event_type, callback
|
51
72
|
|
52
73
|
# Fires the given local event with the given data payload.
|
53
74
|
fire_event: (event_type, data) =>
|
54
|
-
|
75
|
+
modularity.assert event_type, 'Module.fire_event: You must provide the event type to fire.'
|
55
76
|
return alert("Module.fire_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
|
56
77
|
@container.trigger event_type, data ?= {}
|
57
78
|
|
@@ -63,25 +84,6 @@ class window.modularity.Module
|
|
63
84
|
@prototype.mixins.push({mixin: mixin, params: p})
|
64
85
|
|
65
86
|
|
66
|
-
# GLOBAL EVENTS.
|
67
|
-
|
68
|
-
# Subscribes to the given global event,
|
69
|
-
# i.e. calls the given function when the given global event type happens.
|
70
|
-
@bind_global_event: (event_type, callback) =>
|
71
|
-
return unless @assert event_type, "Module.bind_global_event: parameter 'event_type' is empty"
|
72
|
-
return alert "Module.bind_global_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
|
73
|
-
@global_event_container().bind event_type, callback
|
74
|
-
|
75
|
-
# Fires the given global event with the given data payload.
|
76
|
-
@fire_global_event: (event_type, data) =>
|
77
|
-
@assert event_type, 'Module.fire_global_event: You must provide the event type to fire.'
|
78
|
-
return alert("Module.fire_global_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
|
79
|
-
@global_event_container().trigger event_type, data ?= []
|
80
|
-
|
81
|
-
# Returns the DOM object that is used to fire global events on.
|
82
|
-
@global_event_container: => @global_event_container_cache or= $(window)
|
83
|
-
|
84
|
-
|
85
87
|
# jQuery integration for creating Modules.
|
86
88
|
#
|
87
89
|
# Call like this: myModule = $('...').module(MyModuleClass)
|
@@ -3,6 +3,6 @@
|
|
3
3
|
# A button module.
|
4
4
|
# Responds to clicks on the container element.
|
5
5
|
# The container element is expected to already be populated.
|
6
|
-
class window.modularity.Button extends Module
|
7
|
-
@mixin clickable
|
6
|
+
class window.modularity.Button extends window.modularity.Module
|
7
|
+
@mixin window.modularity.clickable
|
8
8
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# A button that counts how often it is clicked.
|
2
2
|
# This is implemented as a subclass of Button,
|
3
3
|
# to take advantage of the already existing functionality there.
|
4
|
-
class window.modularity.CounterButton extends Button
|
4
|
+
class window.modularity.CounterButton extends modularity.Button
|
5
5
|
|
6
6
|
constructor: ->
|
7
7
|
super
|
@@ -1,3 +1,6 @@
|
|
1
|
+
#= require tools/cache
|
2
|
+
|
3
|
+
|
1
4
|
# A generic ajax loader for parallel GET requests.
|
2
5
|
# Prevents duplicate requests, caches the responses
|
3
6
|
# to answer subsequent requests immediately
|
@@ -5,24 +8,26 @@
|
|
5
8
|
#
|
6
9
|
# Warning: Caches the responses, so once a request is cached,
|
7
10
|
# any new content on the same URL will not be visible!
|
8
|
-
|
11
|
+
class modularity.AjaxLoader
|
12
|
+
|
13
|
+
constructor: ->
|
14
|
+
@cache = new modularity.Cache()
|
9
15
|
|
10
|
-
cache: {}
|
11
16
|
|
12
17
|
get: (url, callback) ->
|
13
|
-
|
18
|
+
cached_value = @cache.get url
|
14
19
|
|
15
20
|
# New request --> start GET call, store callback.
|
16
|
-
unless
|
17
|
-
|
18
|
-
return jQuery.get url, (data)
|
19
|
-
cb(data) for cb in
|
20
|
-
|
21
|
+
unless cached_value?
|
22
|
+
@cache.add url, [callback]
|
23
|
+
return jQuery.get url, (data) =>
|
24
|
+
cb(data) for cb in @cache.get(url)
|
25
|
+
@cache.add url, data
|
21
26
|
|
22
27
|
# Request while the GET call is still pending -->
|
23
28
|
# add the given callback to the list of waiting callbacks.
|
24
|
-
if
|
25
|
-
return
|
29
|
+
if cached_value.constructor is Array
|
30
|
+
return cached_value.push callback
|
26
31
|
|
27
32
|
# There is a cached response for this request --> answer the request immediately.
|
28
|
-
callback(
|
33
|
+
callback(cached_value)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modularity-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70160283637480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70160283637480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: capybara-webkit
|
27
|
-
requirement: &
|
27
|
+
requirement: &70160283637020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70160283637020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: evergreen
|
38
|
-
requirement: &
|
38
|
+
requirement: &70160283636560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70160283636560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rb-fsevent
|
49
|
-
requirement: &
|
49
|
+
requirement: &70160283635920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70160283635920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-livereload
|
60
|
-
requirement: &
|
60
|
+
requirement: &70160283635300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70160283635300
|
69
69
|
description: Description of ModularityRails.
|
70
70
|
email:
|
71
71
|
- kevin.goslar@gmail.com
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.15
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
131
|
summary: Summary of ModularityRails.
|