ende 0.3.2 → 0.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb1613e062a3e54de98840f579455b3f0f40e6f1
4
- data.tar.gz: e54b6e9c72d7fca5a89cb08d1ffd897e85dba482
3
+ metadata.gz: 54bd09d2da50fc28c4a33d1facdeebaaa0c84440
4
+ data.tar.gz: ea30029e995d48cb6008e390b39ba72495c38306
5
5
  SHA512:
6
- metadata.gz: 711ef07535c5cf8325fd6ffbe02c5bd741f9b7be6b977771577d50af5f806f10af905ad094988b1d8c046fcd3d80c57a383ecd6818bafb9ed5fe95f0b099bb12
7
- data.tar.gz: 34515cb01be277154400b9950759ded82a462841bb4e80bb31afc0334ab768b7527b516c63bc771da76adf5bf81f61c843871e1777764b97a3a2b675d0efa7cd
6
+ metadata.gz: 4d7e9c7f4544612d99bd25350700f8e88c62042ab2949f5441520658f3d6e240f92b10a12d2becef4cc2913f3c0cdb6869f69d399e376be2057be3ca28f8fe1b
7
+ data.tar.gz: fbbbdf48dee9f407dc2601cf39ea0403d3a5b2aab1332a146a6ef88eb7333f7c46438310f1f8d89f1fb4c544d2a8bc72fcb4eb8d5231289fa5d47aeefb1e10fd
@@ -0,0 +1,183 @@
1
+ prevent = require 'prevent'
2
+
3
+ # # Binding Formatters
4
+ # dermis provides some default data binding formatters to help you get going as quickly as possible
5
+ #
6
+ # The functions below can be used as standard rivets formatters and can be used in combination with one another to do crazy things.
7
+
8
+ cfg =
9
+ preloadData: true
10
+ formatters:
11
+ # ### exists
12
+ # ```data-show="user.name | exists"```
13
+ #
14
+ # Returns true or false if the value exists
15
+ exists: (v) -> v?
16
+
17
+ # ### empty
18
+ # ```data-hide="user.friends | empty"```
19
+ #
20
+ # Returns true if the value is non-existent or has a length of zero.
21
+ empty: (v) -> !(v? and v?.length isnt 0)
22
+
23
+ # ### date
24
+ # ```data-text="user.birthday | date"```
25
+ #
26
+ # You must include [moment.js](http://momentjs.com/) on your page to use this. It is not bundled.
27
+ #
28
+ # Returns the value date formatted by moment.js
29
+ date: (v) -> moment(v).format 'MMM DD, YYYY'
30
+
31
+ # ### money
32
+ # ```data-text="user.accountBalance | money"```
33
+ #
34
+ # You must include [accounting.js](http://josscrowcroft.github.com/accounting.js/) on your page to use this. It is not bundled.
35
+ #
36
+ # Returns the value currency formatted by accounting.js
37
+ money: (v) -> accounting.formatMoney v
38
+
39
+ # ### toNumber
40
+ # ```data-value="user.sweetText | toNumber"```
41
+ #
42
+ # Returns the value converted to a number
43
+ toNumber: (v) -> +v
44
+
45
+ # ### toString
46
+ # ```data-value="user.sweetNumber | toString"```
47
+ #
48
+ # Returns the value converted to a string
49
+ toString: (v) -> String v
50
+
51
+ # ### negate
52
+ # ```data-show="user.badBoy | exists | negate"```
53
+ #
54
+ # Returns the boolean opposite of the value (true=false, false=true)
55
+ negate: (v) -> !v
56
+
57
+ # ### is
58
+ # ```data-show="user.name | is John"```
59
+ #
60
+ # Returns true if the value equals the argument
61
+ is: (v,a) -> v is a
62
+
63
+ # ### isnt
64
+ # ```data-hide="user.name | isnt John"```
65
+ #
66
+ # Returns true if the value doesn't equal the argument
67
+ isnt: (v,a) -> v isnt a
68
+
69
+ # ### gt
70
+ # ```data-show="user.friends | length | gt 5"```
71
+ #
72
+ # Returns true if the value is greater than the argument
73
+ gt: (v,a) -> v > a
74
+
75
+ # ### lt
76
+ # ```data-hide="user.friends | length | lt 5"```
77
+ #
78
+ # Returns true if the value is less than the argument
79
+ lt: (v,a) -> v < a
80
+
81
+ # ### at
82
+ # ```data-text="user.friends | at 0"```
83
+ #
84
+ # Returns the item at the index specified for values
85
+ at: (v, a) ->
86
+ return v unless v?
87
+ return v[parseInt(a)]
88
+
89
+ # ### join
90
+ # ```data-text="user.friends | join ,"```
91
+ #
92
+ # Returns the output of value joined by the argument
93
+ join: (v, a) ->
94
+ return v unless v?
95
+ return v.join a
96
+
97
+ # ### split
98
+ # ```data-each-friend="user.friendList | split ,"```
99
+ #
100
+ # Returns an array of value split by the argument
101
+ split: (v, a) ->
102
+ return v unless v?
103
+ return v.split a
104
+
105
+ # ### prepend
106
+ # ```data-href="user.name | prepend /users/"```
107
+ #
108
+ # Returns a string of argument + value
109
+ prepend: (v,a...) -> a.join(' ')+v
110
+
111
+ # ### append
112
+ # ```data-href="user.name | prepend /users/ | append /messages"```
113
+ #
114
+ # Returns a string of value + argument
115
+ append: (v,a...) -> v+a.join(' ')
116
+
117
+ # ### length
118
+ # ```data-text="user.friends | length"```
119
+ #
120
+ # Returns the length of the value
121
+ length: (v) ->
122
+ return v unless v?
123
+ return v.length
124
+
125
+ # ### cancelEvent
126
+ # ```data-on-submit="user:save | cancelEvent"```
127
+ #
128
+ # Extremely useful for preventing forms from submitting but can be used to stop all event propagation.
129
+ #
130
+ # Returns a new function wrapping value that stops event propagation.
131
+ cancelEvent: (v) ->
132
+ return v unless v?
133
+ return (e) ->
134
+ prevent e
135
+ v.call @, e
136
+ return false
137
+
138
+ # ### sort
139
+ # ```data-each="movies.models | sort [asc | desc]"```
140
+ #
141
+ # Sorts collection in asc or desc order
142
+ sort: (arr, direction='asc') ->
143
+ return arr.sort().reverse() if direction is 'desc'
144
+ return arr.sort()
145
+
146
+ # ### sortBy
147
+ # ```data-each="movies | sortBy field, [asc | desc]"```
148
+ #
149
+ # Sorts collection in asc or desc order on a field
150
+ sortBy: (arr, field, direction='asc') ->
151
+ reverse = (direction is 'desc')
152
+ sortFn = (a, b) ->
153
+ if a[field] < b[field]
154
+ out = -1
155
+ else if a[field] > b[field]
156
+ out = 1
157
+ else
158
+ out = 0
159
+ return out*[1,-1][+!!reverse]
160
+
161
+ return arr.sort sortFn
162
+
163
+
164
+ adapter:
165
+ subscribe: (obj, kp, cb) ->
166
+ obj.on "change:#{kp}", cb
167
+ return
168
+
169
+ unsubscribe: (obj, kp, cb) ->
170
+ obj.removeListener "change:#{kp}", cb
171
+ return
172
+
173
+ read: (obj, kp) -> obj.get kp
174
+
175
+ publish: (obj, kp, val) ->
176
+ obj.set kp, val
177
+ return
178
+
179
+ publishers = ["toNumber", "toString"]
180
+ for k,v of cfg.formatters when publishers.indexOf(k) isnt -1
181
+ v.publish = v.read = v
182
+
183
+ module.exports = cfg
@@ -0,0 +1,172 @@
1
+ define 'extensions/rivets/formatters',
2
+
3
+ # ### exists
4
+ # ```data-show="user.name | exists"```
5
+ #
6
+ # Returns true or false if the value exists
7
+ exists: (v) -> v?
8
+
9
+ # ### empty
10
+ # ```data-hide="user.friends | empty"```
11
+ #
12
+ # Returns true if the value is non-existent or has a length of zero.
13
+ empty: (v) -> !(v? and v?.length isnt 0)
14
+
15
+ # ### date
16
+ # ```data-text="user.birthday | date"```
17
+ #
18
+ # You must include [moment.js](http://momentjs.com/) on your page to use this. It is not bundled.
19
+ #
20
+ # Returns the value date formatted by moment.js
21
+ # date: (v) -> moment(v).format 'MMM DD, YYYY'
22
+
23
+ # ### money
24
+ # ```data-text="user.accountBalance | money"```
25
+ #
26
+ # You must include [accounting.js](http://josscrowcroft.github.com/accounting.js/) on your page to use this. It is not bundled.
27
+ #
28
+ # Returns the value currency formatted by accounting.js
29
+ # money: (v) -> accounting.formatMoney v
30
+
31
+ # ### toNumber
32
+ # ```data-value="user.sweetText | toNumber"```
33
+ #
34
+ # Returns the value converted to a number
35
+ toNumber: (v) -> +v
36
+
37
+ # ### toString
38
+ # ```data-value="user.sweetNumber | toString"```
39
+ #
40
+ # Returns the value converted to a string
41
+ toString: (v) -> String v
42
+
43
+ # ### negate
44
+ # ```data-show="user.badBoy | exists | negate"```
45
+ #
46
+ # Returns the boolean opposite of the value (true=false, false=true)
47
+ # negate: (v) -> !v
48
+
49
+ # ### is
50
+ # ```data-show="user.name | is John"```
51
+ #
52
+ # Returns true if the value equals the argument
53
+ is: (v,a) -> v is a
54
+
55
+ # ### isnt
56
+ # ```data-hide="user.name | isnt John"```
57
+ #
58
+ # Returns true if the value doesn't equal the argument
59
+ isnt: (v,a) -> v isnt a
60
+
61
+ # ### gt
62
+ # ```data-show="user.friends | length | gt 5"```
63
+ #
64
+ # Returns true if the value is greater than the argument
65
+ gt: (v,a) -> v > a
66
+
67
+ # ### lt
68
+ # ```data-hide="user.friends | length | lt 5"```
69
+ #
70
+ # Returns true if the value is less than the argument
71
+ lt: (v,a) -> v < a
72
+
73
+ # ### at
74
+ # ```data-text="user.friends | at 0"```
75
+ #
76
+ # Returns the item at the index specified for values
77
+ at: (v, a) ->
78
+ return v unless v?
79
+ return v[parseInt(a)]
80
+
81
+ # ### join
82
+ # ```data-text="user.friends | join ,"```
83
+ #
84
+ # Returns the output of value joined by the argument
85
+ join: (v, a) ->
86
+ return v unless v?
87
+ return v.join a
88
+
89
+ # ### split
90
+ # ```data-each-friend="user.friendList | split ,"```
91
+ #
92
+ # Returns an array of value split by the argument
93
+ split: (v, a) ->
94
+ return v unless v?
95
+ return v.split a
96
+
97
+ # ### prepend
98
+ # ```data-href="user.name | prepend /users/"```
99
+ #
100
+ # Returns a string of argument + value
101
+ prepend: (v,a...) -> a.join(' ')+v
102
+
103
+ # ### append
104
+ # ```data-href="user.name | prepend /users/ | append /messages"```
105
+ #
106
+ # Returns a string of value + argument
107
+ append: (v,a...) -> v+a.join(' ')
108
+
109
+ # ### length
110
+ # ```data-text="user.friends | length"```
111
+ #
112
+ # Returns the length of the value
113
+ length: (v) ->
114
+ return v unless v?
115
+ return v.length
116
+
117
+ # ### cancelEvent
118
+ # ```data-on-submit="user:save | cancelEvent"```
119
+ #
120
+ # Extremely useful for preventing forms from submitting but can be used to stop all event propagation.
121
+ #
122
+ # Returns a new function wrapping value that stops event propagation.
123
+ cancelEvent: (v) ->
124
+ return v unless v?
125
+ return (e) ->
126
+ prevent e
127
+ v.call @, e
128
+ return false
129
+
130
+ # ### sort
131
+ # ```data-each="movies.models | sort [asc | desc]"```
132
+ #
133
+ # Sorts collection in asc or desc order
134
+ sort: (arr, direction='asc') ->
135
+ return arr.sort().reverse() if direction is 'desc'
136
+ return arr.sort()
137
+
138
+ # ### sortBy
139
+ # ```data-each="movies | sortBy field, [asc | desc]"```
140
+ #
141
+ # Sorts collection in asc or desc order on a field
142
+ sortBy: (arr, field, direction='asc') ->
143
+ reverse = (direction is 'desc')
144
+ sortFn = (a, b) ->
145
+ if a[field] < b[field]
146
+ out = -1
147
+ else if a[field] > b[field]
148
+ out = 1
149
+ else
150
+ out = 0
151
+ return out*[1,-1][+!!reverse]
152
+
153
+ return arr.sort sortFn
154
+
155
+
156
+ float: (value) ->
157
+ throw new TypeError "Invalid value passed to float formatter: #{value}" unless value?
158
+
159
+ # Blank value and impossible to convert to string
160
+ (!value || !(value + '')) && (value = 0)
161
+
162
+ # Force getter reading on IE
163
+ value = parseFloat value + ''
164
+
165
+ # Handle NaN
166
+ (isNaN(value)) && (value = 0)
167
+
168
+ # Format value
169
+ value.toFixed(2).toString().replace '.', ','
170
+
171
+ currency: (value) ->
172
+ 'R$ ' + rivets.formatters.float value
@@ -1,4 +1,6 @@
1
- define 'aura/extensions/rivets', ->
1
+ #= require 'aura/extensions/rivets/formatters'
2
+
3
+ define 'aura/extensions/rivets', ['extensions/rivets/formatters'], (formatters)->
2
4
 
3
5
  'use strict';
4
6
 
@@ -9,6 +11,9 @@ define 'aura/extensions/rivets', ->
9
11
  Rivets = rivets._
10
12
 
11
13
  observable_configuration = require 'indefinido-observable/lib/adapters/rivets'
14
+
15
+
16
+ extend rivets.formatters, formatters
12
17
 
13
18
  rivets.configure observable_configuration
14
19
  rivets.configure
@@ -211,29 +216,12 @@ define 'aura/extensions/rivets', ->
211
216
  else if value?.toString() isnt el.value?.toString()
212
217
  el.value = if value? then value else ''
213
218
 
214
- # TODO isntall formatters from the external custom formatters repo
215
- rivets.formatters.is ||= (one, other) -> one == other
216
-
217
- rivets.formatters.float ||= (value) ->
218
- throw new TypeError "Invalid value passed to float formatter: #{value}" unless value?
219
-
220
- # Blank value and impossible to convert to string
221
- (!value || !(value + '')) && (value = 0)
222
-
223
- # Force getter reading on IE
224
- value = parseFloat value + ''
225
-
226
- # Handle NaN
227
- (isNaN(value)) && (value = 0)
228
-
229
- # Format value
230
- value.toFixed(2).toString().replace '.', ','
231
219
 
232
- rivets.formatters.currency ||= (value) ->
233
- 'R$ ' + rivets.formatters.float value
234
220
 
221
+
235
222
 
236
223
  (application) ->
224
+ version: '0.1.0'
237
225
 
238
226
  initialize: (application) ->
239
227
  observable = require('observable').mixin
data/lib/ende/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ende
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ende
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heitor Salazar
@@ -76,6 +76,9 @@ files:
76
76
  - lib/assets/javascripts/aura/extensions/mediator.js
77
77
  - lib/assets/javascripts/aura/extensions/models.js.coffee.erb
78
78
  - lib/assets/javascripts/aura/extensions/rivets.js.coffee
79
+ - lib/assets/javascripts/aura/extensions/rivets/#formatters.js.coffee#
80
+ - lib/assets/javascripts/aura/extensions/rivets/formatters.js.coffee
81
+ - lib/assets/javascripts/aura/extensions/rivets/formatters.js.coffee~
79
82
  - lib/assets/javascripts/aura/extensions/routes.js.coffee
80
83
  - lib/assets/javascripts/aura/extensions/states.js.coffee
81
84
  - lib/assets/javascripts/aura/extensions/widget/eventable.js.coffee