modularity-rails 0.17.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -0
- data/app/assets/javascripts/modularity/data/indexed_cache.coffee +4 -4
- data/app/assets/javascripts/modularity/data/persistence_manager.coffee +4 -4
- data/app/assets/javascripts/modularity/mixins/clickable.coffee +1 -1
- data/app/assets/javascripts/modularity/mixins/closable.coffee +1 -1
- data/app/assets/javascripts/modularity/modularity.coffee +25 -4
- data/app/assets/javascripts/modularity/tools/string_tools.coffee +3 -0
- data/lib/modularity-rails/version.rb +1 -1
- metadata +44 -43
data/README.md
CHANGED
@@ -55,6 +55,51 @@ Each module has a container. The container is the outermost DOM element of a sec
|
|
55
55
|
Everything the module does must happen inside this container.
|
56
56
|
The module is responsible for managing the inner DOM-structure of the container.
|
57
57
|
|
58
|
+
## Events
|
59
|
+
|
60
|
+
Modules are supposed to form a loosely coupled architecture, in which they communicate with each other through events.
|
61
|
+
Similar to jQuery events, a module can trigger an event using its `trigger` method, like so:
|
62
|
+
```coffeescript
|
63
|
+
@trigger 'user_selected', user
|
64
|
+
```
|
65
|
+
|
66
|
+
The first argument is the event name, the second one an optional data payload. The event is a normal jQuery event,
|
67
|
+
triggered from the container of the module.
|
68
|
+
|
69
|
+
Other modules can subscribe to events from particular modules using a similar mechanism:
|
70
|
+
```coffeescript
|
71
|
+
@user_list.on 'user_selected', (e, user) -> ...
|
72
|
+
```
|
73
|
+
|
74
|
+
The first argument is the jQuery event object, the second one the data payload.
|
75
|
+
|
76
|
+
### Event Autobinding
|
77
|
+
|
78
|
+
If you want to avoid writing lots of boilerplate code to wire up events, use Modularities `autobind` method together with the convention to name your event handler methods "on_#{module_name}_#{event_name}".
|
79
|
+
For example, to listen to the "entry_created" event of a module called "userlist", name your method "on_userlist_entry_created". To illustrate this more, the following two pieces of code are equivalent:
|
80
|
+
|
81
|
+
Manual event listener setup:
|
82
|
+
```coffeescript
|
83
|
+
@userlist = new UserList()
|
84
|
+
@userlist.on 'entry_selected', @user_selected
|
85
|
+
@userlist.on 'entry_created', @user_created
|
86
|
+
@userlist.on 'entry_deleted', @user_deleted
|
87
|
+
|
88
|
+
user_selected: (e, user) -> ...
|
89
|
+
user_created: (e, user) -> ...
|
90
|
+
user_deleted: (e, user) -> ...
|
91
|
+
```
|
92
|
+
|
93
|
+
Automatic event listener setup:
|
94
|
+
```coffeescript
|
95
|
+
@userlist = new UserList()
|
96
|
+
@autobind()
|
97
|
+
|
98
|
+
on_userlist_entry_selected: (e, user) -> ...
|
99
|
+
on_userlist_entry_created: (e, user) -> ...
|
100
|
+
on_userlist_entry_deleted: (e, user) -> ...
|
101
|
+
```
|
102
|
+
|
58
103
|
|
59
104
|
## Mixins
|
60
105
|
|
@@ -16,12 +16,12 @@ class modularity.IndexedCache
|
|
16
16
|
@add(entry) for entry in entries
|
17
17
|
|
18
18
|
|
19
|
-
remove: (
|
20
|
-
@cache.remove
|
19
|
+
remove: (entry_id) ->
|
20
|
+
@cache.remove entry_id
|
21
21
|
|
22
22
|
|
23
|
-
remove_many: (
|
24
|
-
@cache.remove_many
|
23
|
+
remove_many: (entry_ids) ->
|
24
|
+
@cache.remove_many entry_ids
|
25
25
|
|
26
26
|
|
27
27
|
get: (key) ->
|
@@ -55,13 +55,13 @@ class modularity.PersistenceManager
|
|
55
55
|
|
56
56
|
|
57
57
|
# Deletes the given objects from the server.
|
58
|
-
delete_many: (
|
59
|
-
@client_data.remove_many
|
60
|
-
@server_data.remove_many
|
58
|
+
delete_many: (object_ids, callback) ->
|
59
|
+
@client_data.remove_many object_ids
|
60
|
+
@server_data.remove_many object_ids
|
61
61
|
jQuery.ajax
|
62
62
|
url: @base_url
|
63
63
|
type: 'DELETE'
|
64
|
-
data:
|
64
|
+
data: {ids: object_ids}
|
65
65
|
success: ->
|
66
66
|
callback() if callback?
|
67
67
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
#= require jquery
|
2
|
+
#= require_self
|
3
|
+
#= require ./tools/string_tools
|
2
4
|
|
3
5
|
# The Modularity framework written specificially for CoffeeScript.
|
4
6
|
#
|
@@ -75,21 +77,40 @@ class @modularity.Module
|
|
75
77
|
|
76
78
|
# MODULE EVENTS.
|
77
79
|
|
80
|
+
# Automatically binds events to member elements.
|
81
|
+
autobind: ->
|
82
|
+
my_fields = []
|
83
|
+
my_callbacks = []
|
84
|
+
for element of @
|
85
|
+
switch typeof @[element]
|
86
|
+
when 'object'
|
87
|
+
my_fields.push element
|
88
|
+
when 'function'
|
89
|
+
my_callbacks.push(element) if modularity.string_starts_with element, 'on_'
|
90
|
+
for field in my_fields
|
91
|
+
for callback in my_callbacks
|
92
|
+
if modularity.string_starts_with callback, "on_#{field}_"
|
93
|
+
event_name = callback.substring 4 + field.length
|
94
|
+
@[field].on event_name, @[callback]
|
95
|
+
false
|
96
|
+
|
97
|
+
|
78
98
|
# Calls the given function when this widget fires the given local event.
|
79
|
-
|
99
|
+
on: (event_type, callback) =>
|
80
100
|
return unless modularity.assert typeof event_type == 'string', "Module.bind_event: parameter 'event_type' is empty"
|
81
101
|
return alert "Module.bind_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
|
82
102
|
@container.bind event_type, callback
|
83
103
|
bindEvent: Module::bind_event
|
84
|
-
|
104
|
+
bind_event: Module::bind_event
|
105
|
+
|
85
106
|
|
86
107
|
# Fires the given local event with the given data payload.
|
87
|
-
|
108
|
+
trigger: (event_type, data) =>
|
88
109
|
modularity.assert event_type, 'Module.fire_event: You must provide the event type to fire.'
|
89
110
|
return alert("Module.fire_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
|
90
111
|
@container.trigger event_type, data ?= {}
|
91
112
|
fireEvent: Module::fire_event
|
92
|
-
|
113
|
+
fire_event: Module::fire_event
|
93
114
|
|
94
115
|
|
95
116
|
# Hides this module.
|
metadata
CHANGED
@@ -1,144 +1,144 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modularity-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.19.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.17.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Goslar
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
prerelease: false
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 3.2.12
|
21
|
-
none: false
|
22
|
-
type: :runtime
|
23
15
|
name: rails
|
24
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
25
18
|
requirements:
|
26
19
|
- - ~>
|
27
20
|
- !ruby/object:Gem::Version
|
28
21
|
version: 3.2.12
|
29
|
-
|
30
|
-
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
31
23
|
prerelease: false
|
32
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
33
26
|
requirements:
|
34
|
-
- -
|
27
|
+
- - ~>
|
35
28
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
|
38
|
-
type: :runtime
|
29
|
+
version: 3.2.12
|
30
|
+
- !ruby/object:Gem::Dependency
|
39
31
|
name: coffee-rails
|
40
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
41
34
|
requirements:
|
42
35
|
- - ! '>='
|
43
36
|
- !ruby/object:Gem::Version
|
44
37
|
version: '0'
|
45
|
-
|
46
|
-
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
47
39
|
prerelease: false
|
48
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
49
42
|
requirements:
|
50
43
|
- - ! '>='
|
51
44
|
- !ruby/object:Gem::Version
|
52
45
|
version: '0'
|
53
|
-
|
54
|
-
type: :runtime
|
46
|
+
- !ruby/object:Gem::Dependency
|
55
47
|
name: jquery-rails
|
56
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
57
50
|
requirements:
|
58
51
|
- - ! '>='
|
59
52
|
- !ruby/object:Gem::Version
|
60
53
|
version: '0'
|
61
|
-
|
62
|
-
- !ruby/object:Gem::Dependency
|
54
|
+
type: :runtime
|
63
55
|
prerelease: false
|
64
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
65
58
|
requirements:
|
66
59
|
- - ! '>='
|
67
60
|
- !ruby/object:Gem::Version
|
68
61
|
version: '0'
|
69
|
-
|
70
|
-
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
71
63
|
name: guard-livereload
|
72
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
73
66
|
requirements:
|
74
67
|
- - ! '>='
|
75
68
|
- !ruby/object:Gem::Version
|
76
69
|
version: '0'
|
77
|
-
|
78
|
-
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
79
71
|
prerelease: false
|
80
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
81
74
|
requirements:
|
82
75
|
- - ! '>='
|
83
76
|
- !ruby/object:Gem::Version
|
84
77
|
version: '0'
|
85
|
-
|
86
|
-
type: :development
|
78
|
+
- !ruby/object:Gem::Dependency
|
87
79
|
name: konacha
|
88
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
89
82
|
requirements:
|
90
83
|
- - ! '>='
|
91
84
|
- !ruby/object:Gem::Version
|
92
85
|
version: '0'
|
93
|
-
|
94
|
-
- !ruby/object:Gem::Dependency
|
86
|
+
type: :development
|
95
87
|
prerelease: false
|
96
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
97
90
|
requirements:
|
98
91
|
- - ! '>='
|
99
92
|
- !ruby/object:Gem::Version
|
100
93
|
version: '0'
|
101
|
-
|
102
|
-
type: :development
|
94
|
+
- !ruby/object:Gem::Dependency
|
103
95
|
name: poltergeist
|
104
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
105
98
|
requirements:
|
106
99
|
- - ! '>='
|
107
100
|
- !ruby/object:Gem::Version
|
108
101
|
version: '0'
|
109
|
-
|
110
|
-
- !ruby/object:Gem::Dependency
|
102
|
+
type: :development
|
111
103
|
prerelease: false
|
112
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
113
106
|
requirements:
|
114
107
|
- - ! '>='
|
115
108
|
- !ruby/object:Gem::Version
|
116
109
|
version: '0'
|
117
|
-
|
118
|
-
type: :development
|
110
|
+
- !ruby/object:Gem::Dependency
|
119
111
|
name: rb-fsevent
|
120
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
121
114
|
requirements:
|
122
115
|
- - ! '>='
|
123
116
|
- !ruby/object:Gem::Version
|
124
117
|
version: '0'
|
125
|
-
|
126
|
-
- !ruby/object:Gem::Dependency
|
118
|
+
type: :development
|
127
119
|
prerelease: false
|
128
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
129
122
|
requirements:
|
130
123
|
- - ! '>='
|
131
124
|
- !ruby/object:Gem::Version
|
132
125
|
version: '0'
|
133
|
-
|
134
|
-
type: :development
|
126
|
+
- !ruby/object:Gem::Dependency
|
135
127
|
name: sqlite3
|
136
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
137
130
|
requirements:
|
138
131
|
- - ! '>='
|
139
132
|
- !ruby/object:Gem::Version
|
140
133
|
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
137
|
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
142
|
description: Makes the modularity-coffee framework available to Ruby on Rails applications.
|
143
143
|
email:
|
144
144
|
- kevin.goslar@gmail.com
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- app/assets/javascripts/modularity/modules/button.coffee
|
158
158
|
- app/assets/javascripts/modularity/tools/array_tools.coffee
|
159
159
|
- app/assets/javascripts/modularity/tools/object_tools.coffee
|
160
|
+
- app/assets/javascripts/modularity/tools/string_tools.coffee
|
160
161
|
- config/initializers/konacha.rb
|
161
162
|
- lib/modularity-rails/engine.rb
|
162
163
|
- lib/modularity-rails/version.rb
|
@@ -171,20 +172,20 @@ rdoc_options: []
|
|
171
172
|
require_paths:
|
172
173
|
- lib
|
173
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
174
176
|
requirements:
|
175
177
|
- - ! '>='
|
176
178
|
- !ruby/object:Gem::Version
|
177
179
|
version: '0'
|
178
|
-
none: false
|
179
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
180
182
|
requirements:
|
181
183
|
- - ! '>='
|
182
184
|
- !ruby/object:Gem::Version
|
183
185
|
version: '0'
|
184
|
-
none: false
|
185
186
|
requirements: []
|
186
187
|
rubyforge_project:
|
187
|
-
rubygems_version: 1.8.
|
188
|
+
rubygems_version: 1.8.23
|
188
189
|
signing_key:
|
189
190
|
specification_version: 3
|
190
191
|
summary: A lightweight, object- and component-oriented CoffeeScript framework for
|