modularity-rails 0.5.2 → 0.6.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
@@ -33,6 +33,33 @@ The easiest way is to add it to `application.js`:
33
33
 
34
34
  See [http://github.com/kevgo/modularity-coffeescript].
35
35
 
36
+ ## Mixins
37
+
38
+ Similar to Ruby mixins, mixins in Modularity allow to include orthogonal functional aspects defined in separate objects into a class.
39
+ ```coffeescript
40
+
41
+ myMixin =
42
+
43
+ # This will be called when an instance of a class that includes this mixin is created.
44
+ constructor: ->
45
+
46
+ # This method will be available in every class that includes
47
+ myMethod: ->
48
+
49
+
50
+ class MyModule extends Module
51
+
52
+ @mixin myMixin
53
+
54
+ constructor: (container) ->
55
+
56
+ # The super constructor will call the mixin constructors here.
57
+ super
58
+
59
+ # ...
60
+
61
+ ```
62
+
36
63
 
37
64
  # Development
38
65
 
@@ -1,3 +1,3 @@
1
1
  module ModularityRails
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -17,7 +17,7 @@ describe 'modularity loader', ->
17
17
 
18
18
  # Test class.
19
19
  class window.TestModule extends Module
20
- constructor: (container) ->
20
+ constructor: (container) ->
21
21
  super
22
22
 
23
23
 
@@ -271,3 +271,37 @@ describe 'modularity', ->
271
271
  Module.fire_global_event {}
272
272
  expect(mockGlobalContainer.trigger).not.toHaveBeenCalled()
273
273
  expect(window.alert).toHaveBeenCalled()
274
+
275
+ describe 'mixins', ->
276
+
277
+ myMixin = instance = recordedSelf = null
278
+
279
+ beforeEach ->
280
+ myMixin =
281
+ constructor: -> recordedSelf = @
282
+ method1: ->
283
+
284
+ spyOn(myMixin, 'constructor').andCallThrough()
285
+
286
+ class Test extends Module
287
+ @mixin myMixin
288
+
289
+ instance = new Test('testing')
290
+
291
+
292
+ it 'adds all methods from the mixin object to the class prototype', ->
293
+ expect(typeof instance.method1).toBe("function")
294
+
295
+
296
+ it 'calls the constructor of the mixin', ->
297
+ expect(myMixin.constructor).toHaveBeenCalled()
298
+
299
+
300
+ it 'calls the constructor with the this pointing to the instance', ->
301
+ expect(recordedSelf).toBe(instance)
302
+
303
+
304
+
305
+
306
+
307
+
@@ -17,6 +17,18 @@ class window.Module
17
17
  return alert "Error in Module constructor: The given container ('#{container.selector}') is empty." unless container? and container.length > 0
18
18
  return alert "Error in Module constructor: The given container ('#{container.selector}') has more than one element." unless container? and container.length == 1
19
19
 
20
+
21
+ if @mixins?
22
+ for mixin in @mixins
23
+
24
+ # Attach all properties from mixin to the prototype.
25
+ for methodName, method of mixin
26
+ @[methodName] = method
27
+
28
+ # Call constructor function from mixin.
29
+ mixin.constructor.apply @, arguments
30
+
31
+
20
32
  # Checks whether the given condition is true.
21
33
  # Shows an alert with the given message if not.
22
34
  @assert: (condition, message) ->
@@ -39,6 +51,13 @@ class window.Module
39
51
  @container.trigger event_type, data ?= {}
40
52
 
41
53
 
54
+ # mixin = constructor of Draggable
55
+ # self = Card
56
+ @mixin: (mixin) ->
57
+ @prototype.mixins = [] unless @prototype.mixins?
58
+ @prototype.mixins.push mixin
59
+
60
+
42
61
  # GLOBAL EVENTS.
43
62
 
44
63
  # Subscribes to the given global event,
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.5.2
4
+ version: 0.6.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-04-17 00:00:00.000000000 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70138326211200 !ruby/object:Gem::Requirement
16
+ requirement: &70150578537300 !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: *70138326211200
24
+ version_requirements: *70150578537300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capybara-webkit
27
- requirement: &70138326210780 !ruby/object:Gem::Requirement
27
+ requirement: &70150578536860 !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: *70138326210780
35
+ version_requirements: *70150578536860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: evergreen
38
- requirement: &70138314263400 !ruby/object:Gem::Requirement
38
+ requirement: &70150578536380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70138314263400
46
+ version_requirements: *70150578536380
47
47
  description: Description of ModularityRails.
48
48
  email:
49
49
  - kevin.goslar@gmail.com