rails-angulate 0.0.3.rc5 → 0.0.3.rc6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47ca55fe4215c80db19fed2c3a358e7acc0d22e4
4
- data.tar.gz: 05741ea8c5b7a9370aaec76b4765aa52a48fb5c0
3
+ metadata.gz: 9cee89dda57048056c176f750c2b292d1f71db9f
4
+ data.tar.gz: 6d9d4482bc62bf84db08b1d532937b47dcd6ce1e
5
5
  SHA512:
6
- metadata.gz: 6d6e01525b3d3c786bcf9d5cd15f8d90357b522e278a03f88ef0a675d46b819f12f92ddce309a1c11ae7347d05b271d6157e82738653e8dae0c1f96d4b47cd3b
7
- data.tar.gz: 418721541bc300d42f86d46d9771ebaff2173b3b9c506bc85659e94c10dc3764b7a26229d0ea2a21cca80d216082b297fda6c0d8192e06b7b0e89af79a40eaef
6
+ metadata.gz: 8e93a9aa6087dbf45109bba3a8752500e18e62d0e8f2f2f8de7a1278adc765553a7574b120c326e81041d2a2c2a7f431140424a9100c411346c8eb48d3bb40be
7
+ data.tar.gz: cf932fe7780e0d1ba0241f0c462a55e22de024b3ab5c07466d0ec6a533ac751c0cca72c749c61ddc23ed80e382d134df3f1f2f612902c6648849ed4e64a36974
@@ -0,0 +1,47 @@
1
+ # Add $blur flag to form controller
2
+ blurifyDirective = ['$timeout', ($timeout) ->
3
+ restrict: 'E',
4
+ require: '^form'
5
+ link: (scope, element, attrs, form) ->
6
+ return unless attrs.name
7
+ form.$blur = false
8
+
9
+ element.on 'blur', handler = ->
10
+ field = form[attrs.name]
11
+ if field?
12
+ $timeout ->
13
+ field.$blur = true
14
+
15
+ scope.$on '$destroy', ->
16
+ element.off 'blur', handler
17
+ ]
18
+
19
+ formExtensions = ['$timeout', ($timeout) ->
20
+ restrict: 'E',
21
+ require: 'form',
22
+ link: (scope, element, attrs, form) ->
23
+ element.attr('novalidate', 'novalidate')
24
+ form.$submitted = false
25
+ _submit = (e) ->
26
+ if form.$invalid
27
+ e.preventDefault()
28
+ $timeout ->
29
+ form.$submit_attempt = true
30
+ else
31
+ $timeout ->
32
+ form.$submitted = true
33
+
34
+ element.on 'submit', _submit
35
+
36
+ scope.$on '$destroy', ->
37
+ element.off 'submit', _submit
38
+ ]
39
+
40
+ angular.module 'angulate.directives'
41
+
42
+ .directive('input', blurifyDirective)
43
+ .directive('textarea', blurifyDirective)
44
+ .directive('select', blurifyDirective)
45
+ .directive('blurify', blurifyDirective)
46
+
47
+ .directive('form', formExtensions)
@@ -0,0 +1,17 @@
1
+ angular.module 'angulate.directives'
2
+
3
+ # Using ng qualifier because this "goes" with ng-maxlength and ng-minlength
4
+ .directive 'ngIslength', ->
5
+ restrict: 'AC',
6
+ require: 'ngModel'
7
+ link: (scope, element, attrs, ctrl) ->
8
+ length = +attrs.ngIslength
9
+
10
+ isLengthValidator = (value) ->
11
+ validity = ctrl.$isEmpty(value) || value.length == length
12
+ ctrl.$setValidity('islength', validity)
13
+ return value if validity
14
+
15
+ ctrl.$parsers.push(isLengthValidator)
16
+ ctrl.$formatters.push(isLengthValidator)
17
+
@@ -0,0 +1 @@
1
+ angular.module 'angulate.directives', []
@@ -0,0 +1,37 @@
1
+ angular.module 'angulate.directives'
2
+
3
+ # Generic validator
4
+ .directive 'angValidator', ->
5
+ restrict: 'AC',
6
+ require: '?ngModel'
7
+ scope:
8
+ validIf: '&angValidIf'
9
+ link: (scope, element, attrs, ctrl) ->
10
+ return unless ctrl?
11
+
12
+ validationType = attrs.angValidator || 'validator'
13
+
14
+ validate_each = (value, validationExpr) ->
15
+ boolOrValidations = scope.$eval(validationExpr, value: value)
16
+ return boolOrValidations if typeof valid is 'boolean'
17
+
18
+ result = true
19
+ for type, condition of boolOrValidations
20
+ valid = scope.$eval(condition, value: value)
21
+ ctrl.$setValidity(type, valid)
22
+ result &&= valid
23
+
24
+ result
25
+
26
+ validator = (value) ->
27
+ return unless value?
28
+
29
+ if attrs.angValidIf
30
+ valid = validate_each(value, attrs.angValidIf)
31
+
32
+ ctrl.$setValidity(validationType, valid)
33
+ return value if valid
34
+
35
+ ctrl.$parsers.push(validator)
36
+ ctrl.$formatters.push(validator)
37
+
@@ -0,0 +1,5 @@
1
+ throw "In order to use Angulate you must include AngularJS yourself." unless angular?
2
+
3
+ angular.module 'angulate', [
4
+ 'angulate.directives'
5
+ ]
@@ -0,0 +1,6 @@
1
+ #= require ./angulate/module
2
+ #
3
+ #= require ./angulate/directives/module
4
+ #= require ./angulate/directives/form_extensions
5
+ #= require ./angulate/directives/is_length
6
+ #= require ./angulate/directives/validator
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Angulate
3
- VERSION = "0.0.3.rc5"
3
+ VERSION = "0.0.3.rc6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-angulate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.rc5
4
+ version: 0.0.3.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stan Bondi
@@ -78,6 +78,12 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
+ - app/assets/javascripts/rails/angulate.js.coffee
82
+ - app/assets/javascripts/rails/angulate/directives/form_extensions.js.coffee
83
+ - app/assets/javascripts/rails/angulate/directives/is_length.js.coffee
84
+ - app/assets/javascripts/rails/angulate/directives/module.js.coffee
85
+ - app/assets/javascripts/rails/angulate/directives/validator.js.coffee
86
+ - app/assets/javascripts/rails/angulate/module.js.coffee
81
87
  - lib/rails-angulate.rb
82
88
  - lib/rails/angulate.rb
83
89
  - lib/rails/angulate/configuration.rb