modularity-rails 0.6.3 → 0.7.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/.evergreen CHANGED
@@ -3,4 +3,4 @@ require 'capybara-webkit'
3
3
  Evergreen.configure do |config|
4
4
  config.driver = :webkit
5
5
  config.public_dir = ''
6
- end
6
+ end
data/README.md CHANGED
@@ -40,7 +40,7 @@ Modularity provides practices to create code bases of incredible complexity that
40
40
  nicely manageable and perform very well.
41
41
 
42
42
 
43
- # Modules
43
+ ## Modules
44
44
 
45
45
  Modules are native CoffeeScript classes that are specialized for doing what most JavaScript running in browsers does:
46
46
  managing a UI consisting of DOM elements, reacting to events that happen within that section,
@@ -77,24 +77,39 @@ class MyModule extends Module
77
77
  # ...
78
78
  ```
79
79
 
80
+ ## Hooks
80
81
 
81
- ## Reusable example modules and mixins.
82
+ Hooks are a more direct and easier way to interact with mixins. They are methods with predefined names that mixing modules can implement to hook into events of their mixins
83
+ without the need to wire up event handlers, and with the ability to interact with the workflow of the mixins.
84
+
85
+
86
+ # Reusable example modules and mixins.
82
87
 
83
88
  Modularity comes bundled with a bunch of example modules and mixins that can be used in production code.
84
89
  The example modules are located in `vendor/assets/javascripts/modules/` and _vendor/assets/javascripts/mixins_
85
90
  and must be explicitly required in your Rails files using the `require` commands of the asset pipeline.
86
91
 
87
92
 
88
- ### Modules
93
+ ## Modules
89
94
 
90
95
  * __button.coffee__: A simple button. Fires the `clicked` event when anything inside the container is clicked. Uses the `clickable` mixin.
91
96
  * __counter_button.coffee__: Similar to button, but includes the click count as data payload in the fired event.
92
97
 
93
98
 
94
- ### Mixins
99
+ ## Mixins
100
+
101
+ ###clickable
102
+ Including this mixins adds a 'clickable' aspect to your module, i.e. turns it into a button. Clicking anywhere inside the container makes it fire the 'clicked' event.
103
+
104
+ ###closable
105
+ Including this mixin makes a module closable. The mixin searches for an embedded DOM element with the class 'CloseButton'. When it is clicked, the following things happen:
95
106
 
96
- * __clickable.coffee__: Including this mixins adds a 'clickable' aspect to your module, i.e. turns it into a button. Clicking anywhere inside the container makes it fire the 'clicked' event.
97
- * __closable.coffee__: Including this mixin makes a module closable. This means that when the user clicks on an embedded DOM element with the class 'CloseButton', a 'closing' event will be fired, and the whole module will be removed from the DOM.
107
+ * The _closable_closing_ hook of the closable class is called.
108
+ This hook could be used to display confirmation dialogs (and abort the close process) or to fire custom events that depend on the DOM still being present.
109
+ If this method returns a falsy value, the closing process is aborted.
110
+ * The closable module fires a local 'closing' event (with the DOM still present).
111
+ * The whole module including its container is removed from the DOM.
112
+ * The _closable_closed_ hook of the closable class is called.
98
113
 
99
114
 
100
115
  # Development
@@ -1,3 +1,3 @@
1
1
  module ModularityRails
2
- VERSION = "0.6.3"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -6,7 +6,8 @@ describe 'test environment setup', ->
6
6
  load_modularity()
7
7
  loadCS "/vendor/assets/javascripts/mixins/closable.coffee"
8
8
 
9
- class window.ClosableModuleStandard extends Module
9
+ # A standard closable module.
10
+ class window.ClosableModule1 extends Module
10
11
  @mixin closable
11
12
 
12
13
 
@@ -16,31 +17,82 @@ describe 'Closable', ->
16
17
  describe 'constructor', ->
17
18
  it 'shows an alert if there is no close button', ->
18
19
  spy = spyOn window, 'alert'
19
- new ClosableModuleStandard('#test #closable3')
20
+ new ClosableModule1('#test #closable3')
20
21
  expect(spy).toHaveBeenCalled()
21
22
  expect(spy.argsForCall[0][0]).toMatch(/close button not found/i)
22
23
 
23
24
  it 'shows no alert if there is a close button', ->
24
25
  spy = spyOn window, 'alert'
25
- new ClosableModuleStandard('#test #closable1')
26
+ new ClosableModule1('#test #closable1')
26
27
  expect(spy).not.toHaveBeenCalled()
27
28
 
28
29
  it 'finds the close button div automatically', ->
29
- new ClosableModuleStandard('#test #closable1')
30
+ new ClosableModule1('#test #closable1')
30
31
  $('#test #closable1 .CloseButton').click()
31
32
  expect($('#test #closable1').length).toEqual(0)
32
33
 
33
34
 
34
35
  describe 'when clicking the close button', ->
36
+
37
+ it "calls the closable_closing hook on the object if it exists", ->
38
+
39
+ # A closable module with the 'closing' hook.
40
+ class ClosableModule extends Module
41
+ @mixin closable
42
+
43
+ constructor: ->
44
+ super
45
+ @closing_hook_got_called = no
46
+
47
+ closable_closing: =>
48
+ @closing_hook_got_called = yes
49
+
50
+ module = new ClosableModule('#test #closable1')
51
+ $('#test #closable1 .CloseButton').click()
52
+ expect(module.closing_hook_got_called).toBeTruthy()
53
+
54
+
55
+ it "calls the closable_closed hook on the object if it exists", ->
56
+
57
+ # A closable module with the 'closed' hook.
58
+ class ClosableModule extends Module
59
+ @mixin closable
60
+
61
+ constructor: ->
62
+ super
63
+ @closed_hook_got_called = no
64
+
65
+ closable_closed: =>
66
+ @closed_hook_got_called = yes
67
+
68
+ module = new ClosableModule('#test #closable1')
69
+ $('#test #closable1 .CloseButton').click()
70
+ expect(module.closed_hook_got_called).toBeTruthy()
71
+
72
+
73
+ it "aborts the close operation if the closable_closing method returns false", ->
74
+
75
+ class ClosableModuleWithHookThatReturnsFalse extends Module
76
+ @mixin closable
77
+ closable_closing: -> false
78
+
79
+ module = new ClosableModuleWithHookThatReturnsFalse('#test #closable1')
80
+ module.bind_event('closed', (spy = jasmine.createSpy()))
81
+
82
+ $('#test #closable1 .CloseButton').click()
83
+
84
+ expect(spy).not.toHaveBeenCalled()
85
+
86
+
35
87
  it 'removes the container', ->
36
- new ClosableModuleStandard('#test #closable1')
88
+ new ClosableModule1('#test #closable1')
37
89
  $('#test #closable1 .CloseButton').click()
38
90
 
39
91
  expect($('#test #closable1').length).toEqual(0)
40
-
41
-
92
+
93
+
42
94
  it "fires the 'closed' event", ->
43
- closable_module = new ClosableModuleStandard('#test #closable1')
95
+ closable_module = new ClosableModule1('#test #closable1')
44
96
  closable_module.bind_event('closed', (spy = jasmine.createSpy()))
45
97
 
46
98
  $('#test #closable1 .CloseButton').click()
@@ -4,7 +4,7 @@ window.closable =
4
4
  close_button = @container.find('.CloseButton')
5
5
  unless close_button?.length > 0
6
6
  window.alert 'Error: Close button not found'
7
- close_button.click @close_button_clicked
7
+ close_button.click => @close_button_clicked()
8
8
 
9
9
 
10
10
  # The events that can be fired by closable objects.
@@ -14,5 +14,8 @@ window.closable =
14
14
 
15
15
  # Called when the button got clicked by the user or programmatically.
16
16
  close_button_clicked: ->
17
+ if @closable_closing
18
+ return unless @closable_closing()
17
19
  @fire_event 'closed'
18
20
  @container.remove()
21
+ @closable_closed() if @closable_closed
@@ -18,6 +18,7 @@ class window.Module
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
20
 
21
+ # Attach mixins.
21
22
  if @mixins?
22
23
  for mixin_data in @mixins
23
24
 
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.6.3
4
+ version: 0.7.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-30 00:00:00.000000000 Z
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70358087399780 !ruby/object:Gem::Requirement
16
+ requirement: &70343797333300 !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: *70358087399780
24
+ version_requirements: *70343797333300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capybara-webkit
27
- requirement: &70358087399360 !ruby/object:Gem::Requirement
27
+ requirement: &70343797332340 !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: *70358087399360
35
+ version_requirements: *70343797332340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: evergreen
38
- requirement: &70358087398900 !ruby/object:Gem::Requirement
38
+ requirement: &70343797331680 !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: *70358087398900
46
+ version_requirements: *70343797331680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rb-fsevent
49
- requirement: &70358087398440 !ruby/object:Gem::Requirement
49
+ requirement: &70343797331020 !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: *70358087398440
57
+ version_requirements: *70343797331020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-livereload
60
- requirement: &70358087398020 !ruby/object:Gem::Requirement
60
+ requirement: &70343797330580 !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: *70358087398020
68
+ version_requirements: *70343797330580
69
69
  description: Description of ModularityRails.
70
70
  email:
71
71
  - kevin.goslar@gmail.com
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 1.8.15
124
+ rubygems_version: 1.8.10
125
125
  signing_key:
126
126
  specification_version: 3
127
127
  summary: Summary of ModularityRails.