modularity-rails 0.12.3 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
- # Modularity::Rails [![Build Status](https://secure.travis-ci.org/kevgo/modularity-rails.png)](http://travis-ci.org/#!/kevgo/modularity-rails)
1
+ # Modularity::Rails [![Build Status](https://secure.travis-ci.org/kevgo/modularity-rails.png)](http://travis-ci.org/#!/kevgo/modularity-rails) <a href="https://codeclimate.com/github/kevgo/modularity-rails" target="_blank"><img src="https://codeclimate.com/badge.png" /></a>
2
2
 
3
- A lightweight, modular, object and component oriented frontend framework for Rails applications.
3
+ Makes the [Modularity CoffeeScript](http://github.com/kevgo/modularity-coffeescript) library and related modules available to
4
+ Rails 3.1 applications.
4
5
 
5
- Makes the [Modularity CoffeeScript](http://github.com/kevgo/modularity-coffeescript) library available to
6
- Rails 3.1 applications.
7
-
8
- Modularity is a pattern and framework for lightweight object-oriented JavaScript
9
- that allows to compose functionally rich web pages in a clean and testable way
10
- out of well structured and reusable components.
6
+ Modularity is a framework for lightweight component-oriented CoffeeScript.
7
+ It allows to compose functionally rich web pages in a clean, intuitive, and testable way
8
+ out of well structured and reusable components. It scales very well with complexity.
11
9
 
12
10
 
13
11
  ## Authors
@@ -17,7 +15,7 @@ out of well structured and reusable components.
17
15
 
18
16
  # Installation
19
17
 
20
- Add this line to your application's Gemfile:
18
+ Load modularity in your application's Gemfile:
21
19
 
22
20
  ```ruby
23
21
  gem 'modularity-rails'
@@ -17,18 +17,6 @@ describe 'ajax_loader', ->
17
17
  loader = new modularity.AjaxLoader {caching: yes}
18
18
  loader.caching.should.be.true
19
19
 
20
- describe 'ajax', ->
21
-
22
- describe 'GET request', ->
23
-
24
- it 'buffers the request'
25
-
26
- it 'fires the events'
27
-
28
- it ''
29
-
30
- describe 'other requests'
31
-
32
20
 
33
21
   describe 'get', ->
34
22
  url = "/users/4"
@@ -54,8 +42,6 @@ describe 'ajax_loader', ->
54
42
  it 'returns without calling the callback', ->
55
43
  spy.should.not.have.been.called
56
44
 
57
- it 'fires the LOADING event'
58
-
59
45
  describe 'the request is already in progress', ->
60
46
 
61
47
  beforeEach ->
@@ -74,8 +60,6 @@ describe 'ajax_loader', ->
74
60
  it 'does not make another ajax request', ->
75
61
  jQuery.get.should.not.have.been.called
76
62
 
77
- it "doesn't fire the LOADING event again"
78
-
79
63
  describe 'ajax request successful', ->
80
64
 
81
65
  beforeEach ->
@@ -85,13 +69,11 @@ describe 'ajax_loader', ->
85
69
  jquery_callback('result')
86
70
 
87
71
  it 'calls the given callbacks with the server data', ->
88
- spy.should.have.been.calledWith 'result'
72
+ expect(spy.calledWith('result')).to.be.true
89
73
 
90
74
  it 'replaces the cache callbacks with returned data', ->
91
75
  ajax_loader.cache.get(url).should.equal 'result'
92
76
 
93
- it 'fires the LOADED event'
94
-
95
77
  describe 'the data has already been loaded', ->
96
78
 
97
79
     it 'calls the callback with the cached data', ->
@@ -100,9 +82,7 @@ describe 'ajax_loader', ->
100
82
  ajax_loader.get(url, spy)
101
83
 
102
84
  spy.should.have.been.called
103
- spy.should.have.been.calledWith "my data"
104
-
105
- it "doesn't fire any events"
85
+ expect(spy.calledWith('my data')).to.be.true
106
86
 
107
87
 
108
88
  describe 'with caching disabled', ->
@@ -149,7 +129,7 @@ describe 'ajax_loader', ->
149
129
  jquery_callback('result')
150
130
 
151
131
  it 'calls the given callbacks with the server data', ->
152
- spy.should.have.been.calledWith 'result'
132
+ expect(spy.calledWith "result").to.be.true
153
133
 
154
134
  it 'replaces the cache callbacks with returned data', ->
155
135
  expect(ajax_loader.cache.get(url)).to.be.undefined
@@ -41,7 +41,6 @@ describe 'PersistenceManager', ->
41
41
  persistence_manager.add_all data
42
42
  spy.should.have.been.calledOnce
43
43
 
44
-
45
44
  describe 'create', ->
46
45
  new_obj = {value: 'foo'}
47
46
 
@@ -137,52 +136,6 @@ describe 'PersistenceManager', ->
137
136
  loading_done_callback.should.have.been.calledOnce
138
137
 
139
138
 
140
- describe 'load_local', ->
141
-
142
- describe 'entry exists in client data cache', ->
143
- it 'returns the entry from the @client_data cache if it exists there', ->
144
- persistence_manager.client_data.add entry_1
145
- result = persistence_manager.load_local 1
146
- result.should.equal entry_1
147
-
148
- describe 'entry exists in server data cache', ->
149
-
150
- beforeEach ->
151
- persistence_manager.server_data.add entry_1
152
-
153
- it 'adds the entry to the client data cache', ->
154
- persistence_manager.load_local 1
155
- persistence_manager.client_data.length().should.equal 1
156
- persistence_manager.client_data.get(1).should.eql entry_1
157
-
158
- it 'returns the entry from the client data cache', ->
159
- result = persistence_manager.load_local 1
160
- client_cache_entry = persistence_manager.client_data.get 1
161
- result.should.equal client_cache_entry
162
-
163
- it 'returns a different hash than the server data, so that the user can make changes to it', ->
164
- result = persistence_manager.load_local 1
165
- server_cache_entry = persistence_manager.server_data.get 1
166
- result.should.not.equal server_cache_entry
167
-
168
- describe "entry doesn't exist in any cache", ->
169
-
170
- it 'returns undefined', ->
171
- expect(persistence_manager.load_local(1)).to.be.undefined
172
-
173
-
174
- describe 'load_many', ->
175
-
176
- describe 'all entries exists in the cache', ->
177
- it 'returns the entries immediately', (done) ->
178
- persistence_manager.add_all [entry_1, entry_2]
179
- persistence_manager.load_many [1,2], (entries) ->
180
- entries.length.should.equal 2
181
- entries[0].should.eql entry_1
182
- entries[1].should.eql entry_2
183
- done()
184
-
185
-
186
139
  describe 'load', ->
187
140
 
188
141
  describe 'entry exists in client data cache', ->
@@ -48,23 +48,23 @@ describe 'modularity', ->
48
48
 
49
49
  it 'shows an alert with the given message if the given condition is false', ->
50
50
  modularity.assert false, 'Message'
51
- window.alert.should.have.been.calledWith "Message"
51
+ expect(window.alert.calledWith "Message").to.be.true
52
52
 
53
53
  it 'fails when the condition is null', ->
54
54
  modularity.assert null, 'Message'
55
- window.alert.should.have.been.calledWith "Message"
55
+ expect(window.alert.calledWith "Message").to.be.true
56
56
 
57
57
  it 'fails when the condition is undefined', ->
58
58
  modularity.assert undefined, 'Message'
59
- window.alert.should.have.been.calledWith "Message"
59
+ expect(window.alert.calledWith "Message").to.be.true
60
60
 
61
61
  it 'fails when the condition is an empty array', ->
62
62
  modularity.assert [], 'Message'
63
- window.alert.should.have.been.calledWith "Message"
63
+ expect(window.alert.calledWith "Message").to.be.true
64
64
 
65
65
  it 'fails when the condition is an empty string', ->
66
66
  modularity.assert '', 'Message'
67
- window.alert.should.have.been.calledWith "Message"
67
+ expect(window.alert.calledWith "Message").to.be.true
68
68
 
69
69
  it 'passes when the condition is a string', ->
70
70
  modularity.assert '123', 'Message'
@@ -77,6 +77,15 @@ describe 'modularity', ->
77
77
  modularity.assert('123').should.be.true
78
78
 
79
79
 
80
+ describe '@$ notation', ->
81
+
82
+ it 'returns a new jQuery object relative to container', ->
83
+ module = new TestModule $ '#module_container'
84
+ insideObject = module.$ '.inside_module,.outside_module'
85
+ insideObject.length.should.equal 1
86
+ insideObject.hasClass('inside_module').should.be.true
87
+
88
+
80
89
  describe 'jQuery Integration', ->
81
90
 
82
91
  it 'works', ->
@@ -299,7 +308,7 @@ describe 'modularity', ->
299
308
  sinon.spy myMixin, 'method1'
300
309
  instance = new Test('testing')
301
310
  instance.method1("arg1", "arg2")
302
- myMixin.method1.should.have.been.calledWith("arg1", "arg2")
311
+ expect(myMixin.method1.calledWith("arg1", "arg2")).to.be.true
303
312
  myMixin.method1.restore()
304
313
 
305
314
 
@@ -3,7 +3,6 @@
3
3
  #= require sinon-chai
4
4
  #= require_tree ./templates
5
5
 
6
- window.chai.use window.sinonChai
7
6
 
8
7
  # Renders the template with the given path in the #konacha div.
9
8
  window.template = (path) ->
@@ -1,3 +1,6 @@
1
- <div id="module_container"></div>
1
+ <div id="module_container">
2
+ <div class="inside_module"></div>
3
+ </div>
4
+ <div class="outside_module"></div>
5
+ <div class="double"></div>
2
6
  <div class="double"></div>
3
- <div class="double"></div>
@@ -1,3 +1,3 @@
1
1
  module ModularityRails
2
- VERSION = "0.12.3"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # Use UglifyJS (http://github.com/mishoo/UglifyJS) for compression.
4
4
  #
5
- # Please see https://github.com/kevgo/modularity for more information.
5
+ # Please see https://github.com/kevgo/modularity for more information on Modularity,
6
+ # and https://github.com/kevgo/modularity-rails for Rails integration.
6
7
 
7
8
 
8
9
  window.modularity = {
@@ -10,9 +11,10 @@ window.modularity = {
10
11
  # Checks whether the given condition is true.
11
12
  # Shows an alert with the given message if not.
12
13
  assert: (condition, message) ->
13
- condition_ok = condition?.length > 0
14
- alert(message) unless condition_ok
15
- condition_ok
14
+ if !condition or condition?.length == 0
15
+ alert message
16
+ return false
17
+ true
16
18
 
17
19
 
18
20
  # GLOBAL EVENTS.
@@ -20,7 +22,7 @@ window.modularity = {
20
22
  # Subscribes to the given global event,
21
23
  # i.e. calls the given function when the given global event type happens.
22
24
  bind_global_event: (event_type, callback) ->
23
- return unless modularity.assert event_type, "modularity.bind_global_event: parameter 'event_type' is empty"
25
+ return unless modularity.assert typeof event_type == 'string', "modularity.bind_global_event: parameter 'event_type' is empty"
24
26
  return alert "modularity.bind_global_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
25
27
  modularity.global_event_container().bind event_type, callback
26
28
 
@@ -33,8 +35,8 @@ window.modularity = {
33
35
  # Returns the DOM object that is used to fire global events on.
34
36
  global_event_container: -> modularity.global_event_container_cache or= $(window)
35
37
  }
36
- modularity.bindGlobalEvent = modularity.bind_global_event
37
- modularity.fireGlobalEvent = modularity.fire_global_event
38
+ window.modularity.bindGlobalEvent = window.modularity.bind_global_event
39
+ window.modularity.fireGlobalEvent = window.modularity.fire_global_event
38
40
 
39
41
 
40
42
  class window.modularity.Module
@@ -54,7 +56,7 @@ class window.modularity.Module
54
56
  # Attach mixins.
55
57
  if @mixins?
56
58
  for mixin_data in @mixins
57
-
59
+
58
60
  # Attach all properties from mixin to the prototype.
59
61
  for methodName, method of mixin_data.mixin
60
62
  do (methodName, method) => unless @[methodName]
@@ -64,11 +66,16 @@ class window.modularity.Module
64
66
  mixin_data.mixin?.constructor?.apply(@, arguments)
65
67
 
66
68
 
69
+ # Runs the given query within the container element.
70
+ $: (query) ->
71
+ @container.find query
72
+
73
+
67
74
  # MODULE EVENTS.
68
75
 
69
76
  # Calls the given function when this widget fires the given local event.
70
77
  bind_event: (event_type, callback) =>
71
- return unless modularity.assert event_type, "Module.bind_event: parameter 'event_type' is empty"
78
+ return unless modularity.assert typeof event_type == 'string', "Module.bind_event: parameter 'event_type' is empty"
72
79
  return alert "Module.bind_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
73
80
  @container.bind event_type, callback
74
81
  bindEvent: Module::bind_event
@@ -80,6 +87,12 @@ class window.modularity.Module
80
87
  @container.trigger event_type, data ?= {}
81
88
  fireEvent: Module::fire_event
82
89
 
90
+
91
+ # Hides this module.
92
+ hide: ->
93
+ @container.hide()
94
+
95
+
83
96
  # mixin = constructor of Draggable
84
97
  # self = Card
85
98
  @mixin: (mixin, p...) ->
@@ -88,6 +101,11 @@ class window.modularity.Module
88
101
  @prototype.mixins.push({mixin: mixin, params: p})
89
102
 
90
103
 
104
+ # Shows this module.
105
+ show: ->
106
+ @container.show()
107
+
108
+
91
109
  # jQuery integration for creating Modules.
92
110
  #
93
111
  # Call like this: myModule = $('...').module(MyModuleClass)
@@ -103,7 +121,7 @@ jQuery.fn.module = (klass, args...) ->
103
121
 
104
122
  # Check parameters.
105
123
  if typeof klass != 'function'
106
- return alert "ERROR!\n\nYou must provide the Module class when calling $.module().\n\nExample: $('...').module(MyModuleClass)\n\nYou provided: #{klass} (#{typeof klass})"
124
+ return alert "ERROR!\n\nYou must provide the Module class when calling $.module().\n\nExample: $('...').module(MyModuleClass)\n\nYou provided: #{klass} (#{typeof klass})"
107
125
 
108
126
  # Instantiate the class and return the instance.
109
127
  new klass(this, args...)
@@ -18,18 +18,6 @@ class window.modularity.AjaxLoader
18
18
  @caching = params.caching
19
19
 
20
20
 
21
- # The different events that this widget can fire.
22
- @events =
23
- AJAX_LOADING: 'AJAX_LOADING' # Called when an AJAX request starts.
24
- AJAX_LOADED: 'AJAX_LOADED' # Called when an AJAX request finishes.
25
-
26
-
27
- # Makes the given AJAX call.
28
- # Buffers the call if it's a GET request.
29
- # Fires the AJAX events.
30
- ajax: (options) ->
31
-
32
-
33
21
  get: (url, callback) ->
34
22
  cached_value = @cache.get url
35
23
 
@@ -63,8 +63,16 @@ class modularity.PersistenceManager
63
63
  # Returns the entry with the given key.
64
64
  load: (key, callback) ->
65
65
 
66
- entry = @load_local key
67
- return callback(entry) if entry
66
+ # Try to use client_data cache.
67
+ client_obj = @client_data.get key
68
+ return callback(client_obj) if client_obj
69
+
70
+ # No data in client cache --> try to use server cache.
71
+ server_obj = @server_data.get key
72
+ if server_obj
73
+ client_obj = modularity.clone_hash server_obj
74
+ @client_data.add client_obj
75
+ return callback client_obj
68
76
 
69
77
  # No data on client at all --> load data from server.
70
78
  @loader.get "#{@base_url}/#{key}", (server_entry) =>
@@ -86,38 +94,7 @@ class modularity.PersistenceManager
86
94
  callback()
87
95
  }
88
96
 
89
-
90
- # Loads the entry synchronously from the cache.
91
- # Doesn't fall back to the server.
92
- load_local: (key) ->
93
-
94
- # Try to use client_data cache.
95
- client_obj = @client_data.get key
96
- return client_obj if client_obj
97
-
98
- # No data in client cache --> try to use server cache.
99
- server_obj = @server_data.get key
100
- return null unless server_obj
101
- client_obj = modularity.clone_hash server_obj
102
- @client_data.add client_obj
103
- client_obj
104
97
 
105
-
106
- # Returns all entries with the given keys.
107
- load_many: (keys, callback) ->
108
- result = []
109
- missing_keys = []
110
- for key in keys
111
- do (key) =>
112
- entry = @load_local key
113
- if entry
114
- result.push entry
115
- else
116
- missing_keys.push key
117
- alert "modularity.PersistenceManager.load_many(): Missing functionality to load from the server." if missing_keys.length > 0
118
- callback result
119
-
120
-
121
98
  # Saves the given object.
122
99
  # Does the right thing (create or update) dependent on
123
100
  # whether the object already has a key parameter.
@@ -1,8 +1,3 @@
1
- # Returns an object that contains only the attributes
2
- # that are different between obj_1 and obj_2.
3
- # Only looks for changed attributes, not missing attributes.
4
-
5
-
6
1
  # Returns a replica of the given hash.
7
2
  # Don't use this method for real objects with superclasses, prototypes, and stuff.
8
3
  modularity.clone_hash = (obj) ->
@@ -11,6 +6,9 @@ modularity.clone_hash = (obj) ->
11
6
  result
12
7
 
13
8
 
9
+ # Returns an object that contains only the attributes
10
+ # that are different between obj_1 and obj_2.
11
+ # Only looks for changed attributes, not missing attributes.
14
12
  modularity.object_diff = (obj_1, obj_2) ->
15
13
  result = {}
16
14
  for own key, value_2 of obj_2
@@ -20,7 +18,8 @@ modularity.object_diff = (obj_1, obj_2) ->
20
18
  result
21
19
 
22
20
 
21
+ # Returns the number of attributes of the given object.
22
+ # NOTE(KG): This doesn't work in IE8.
23
23
  modularity.object_length = (obj) ->
24
- # NOTE(KG): This doesn't work in IE8.
25
24
  Object.keys(obj).length
26
25
 
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.12.3
4
+ version: 0.14.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-06-02 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70181204940740 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70181204940740
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: capybara-webkit
27
- requirement: &70181204936980 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70181204936980
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: evergreen
38
- requirement: &70181204934000 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70181204934000
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rb-fsevent
49
- requirement: &70181204930600 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70181204930600
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: guard-livereload
60
- requirement: &70181204926320 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70181204926320
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: Description of ModularityRails.
70
95
  email:
71
96
  - kevin.goslar@gmail.com
@@ -155,7 +180,6 @@ files:
155
180
  - vendor/assets/javascripts/modularity/data/persistence_manager.coffee
156
181
  - vendor/assets/javascripts/modularity/mixins/clickable.coffee
157
182
  - vendor/assets/javascripts/modularity/mixins/closable.coffee
158
- - vendor/assets/javascripts/modularity/modules/ajax_indicator.coffee
159
183
  - vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
160
184
  - vendor/assets/javascripts/modularity/modules/button.coffee
161
185
  - vendor/assets/javascripts/modularity/modules/counter_button.coffee
@@ -181,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
205
  version: '0'
182
206
  requirements: []
183
207
  rubyforge_project:
184
- rubygems_version: 1.8.15
208
+ rubygems_version: 1.8.24
185
209
  signing_key:
186
210
  specification_version: 3
187
211
  summary: Summary of ModularityRails.
@@ -1,24 +0,0 @@
1
- # Indicates that an AJAX request is running.
2
- class sn.AjaxIndicator extends modularity.Module
3
-
4
- constructor: ->
5
-
6
- # The number of currently running ajax requests.
7
- @ajax_counter = 0
8
-
9
- @searchManager.bind_event sn.SearchManager.events.AJAX_LOADING, @ajax_loading
10
- @searchManager.bind_event sn.SearchManager.events.AJAX_LOADED, @ajax_loaded
11
-
12
-
13
- # Called when an ajax request starts.
14
- ajax_loading: =>
15
- @container.addClass 'loading' if @ajax_counter == 0
16
- @ajax_counter += 1
17
-
18
-
19
- # Called when the ajax request is done.
20
- ajax_loaded: =>
21
- @ajax_counter -= 1
22
- @ajax_counter = 0 if @ajax_counter <= 0
23
- @container.removeClass 'loading'
24
-