rails-angulate 0.0.4 → 0.0.5.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rails/angulate/directives/form_extensions.js.coffee +4 -4
- data/lib/rails/angulate/configuration.rb +2 -3
- data/lib/rails/angulate/helpers/form_builder.rb +9 -0
- data/lib/rails/angulate/helpers/form_helper.rb +1 -0
- data/lib/rails/angulate/helpers/tags/ng_validation_errors.rb +24 -13
- data/lib/rails/angulate/helpers/tags/tag_common.rb +4 -2
- data/lib/rails/angulate/version.rb +1 -1
- metadata +4 -5
- data/lib/rails/angulate/railtie.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 028e9269a483d6f3148f726cf86b2c5f49d50dc3
|
4
|
+
data.tar.gz: 24f89a7798749b0c76ea78c50abb300019e77068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 089bc3386ff49bf0d79c9488016e34fea3c29a6c1ae4678bd928d957533df0831854a1c49e4c98c2a7ee28cd92d1d8f96a3c3b10a8066486d26edf142af7db70
|
7
|
+
data.tar.gz: 2f1038662c1f44a85cbc4d4ca9f7f422cd6ba4817a80e9715c5bc9c5cff5a3e57c63d4b7f013f6b75eefc96419df32435657df42c952d0a3e87ba485d554cf79
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Add $blur flag to form controller
|
2
2
|
blurifyDirective = ['$timeout', ($timeout) ->
|
3
3
|
restrict: 'E',
|
4
|
-
require: '
|
4
|
+
require: '?^form'
|
5
5
|
link: (scope, element, attrs, form) ->
|
6
|
-
return
|
6
|
+
return if !attrs.name || !form
|
7
7
|
form.$blur = false
|
8
8
|
|
9
9
|
element.on 'blur', handler = ->
|
@@ -17,7 +17,7 @@ blurifyDirective = ['$timeout', ($timeout) ->
|
|
17
17
|
]
|
18
18
|
|
19
19
|
formExtensions = ['$timeout', ($timeout) ->
|
20
|
-
restrict: '
|
20
|
+
restrict: 'EAC'
|
21
21
|
priority: 10
|
22
22
|
require: 'form'
|
23
23
|
compile: ->
|
@@ -48,7 +48,7 @@ angular.module 'angulate.directives'
|
|
48
48
|
.directive('select', blurifyDirective)
|
49
49
|
.directive('blurify', blurifyDirective)
|
50
50
|
|
51
|
-
.directive('
|
51
|
+
.directive('angForm', formExtensions)
|
52
52
|
.config ['$provide', ($provide) ->
|
53
53
|
$provide.decorator 'ngSubmitDirective', ['$delegate', ($delegate) ->
|
54
54
|
# Remove default ngSubmit
|
@@ -9,13 +9,12 @@ module Rails
|
|
9
9
|
# blur: only once the field has been visited
|
10
10
|
# dirty: only if the field is dirty
|
11
11
|
# submit_attempt: only once the user has submitted the form
|
12
|
-
attr_accessor :validate_on
|
13
|
-
|
14
|
-
attr_accessor :validate_show_condition
|
12
|
+
attr_accessor :validate_on, :default_error_classes, :validate_show_condition
|
15
13
|
|
16
14
|
def initialize
|
17
15
|
self.validate_on = { submit_attempt: :or, blur: nil }
|
18
16
|
self.validate_show_condition = "%{field}.$invalid && (%{validate_on})"
|
17
|
+
self.default_error_classes = []
|
19
18
|
end
|
20
19
|
|
21
20
|
def validator_mappings
|
@@ -14,6 +14,7 @@ module Rails
|
|
14
14
|
}.each do |_adv_method|
|
15
15
|
define_method _adv_method do |*args, &block|
|
16
16
|
options = args.extract_options!
|
17
|
+
options = apply_builder_options(options)
|
17
18
|
options = objectify_options(options)
|
18
19
|
@template.send(_adv_method, @object_name, *args, options, &block)
|
19
20
|
end
|
@@ -30,6 +31,14 @@ module Rails
|
|
30
31
|
@template.send(_simple_method, object, *args, &block)
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def apply_builder_options(options)
|
38
|
+
options.dup.tap do |opts|
|
39
|
+
opts[:validate_on] ||= self.options[:validate_on]
|
40
|
+
end
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
@@ -6,17 +6,9 @@ module Rails
|
|
6
6
|
include TagCommon
|
7
7
|
|
8
8
|
def render
|
9
|
-
attrs = {}
|
10
|
-
[:id, :class].each do |key|
|
11
|
-
if options.include?(key)
|
12
|
-
value = options[key]
|
13
|
-
attrs[key] = value unless value.blank?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
9
|
# We can't use content_tag with a block (no self.output_buffer)
|
18
10
|
# so we pass in content
|
19
|
-
container
|
11
|
+
container(angular_error_list_html)
|
20
12
|
end
|
21
13
|
|
22
14
|
private
|
@@ -25,8 +17,8 @@ module Rails
|
|
25
17
|
@_options ||= @options.symbolize_keys
|
26
18
|
end
|
27
19
|
|
28
|
-
def container(
|
29
|
-
content_tag :ul, content,
|
20
|
+
def container(content)
|
21
|
+
content_tag :ul, content, container_attrs
|
30
22
|
end
|
31
23
|
|
32
24
|
def angular_error_list_html
|
@@ -46,16 +38,35 @@ module Rails
|
|
46
38
|
validate_on: validate_on || 'true'
|
47
39
|
}
|
48
40
|
|
49
|
-
{
|
41
|
+
attrs = {
|
50
42
|
'ng-show' => ng_show
|
51
43
|
}
|
44
|
+
|
45
|
+
attrs[:class] = configuration.default_error_classes
|
46
|
+
.dup.concat([options[:class]]).compact.uniq.join(' ')
|
47
|
+
|
48
|
+
attrs
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_on_options
|
52
|
+
validate_on = (options[:validate_on] || configuration.validate_on)
|
53
|
+
case validate_on
|
54
|
+
when Array
|
55
|
+
validate_on = validate_on.each_with_index.map { |cond, i| [cond, i == validate_on.length - 1 ? nil : :and] }
|
56
|
+
when Symbol
|
57
|
+
options[:validate_on] = Array.wrap(validate_on)
|
58
|
+
validate_on = validate_on_options
|
59
|
+
end
|
60
|
+
validate_on
|
52
61
|
end
|
53
62
|
|
54
63
|
def validate_on
|
55
64
|
field = angular_form_field_object_name
|
56
65
|
form = angular_form_object_name
|
57
66
|
|
58
|
-
|
67
|
+
return validate_on_options if validate_on_options.is_a?(String)
|
68
|
+
|
69
|
+
validate_on_options.inject('') do |str, (kind, op)|
|
59
70
|
op = case op
|
60
71
|
when :and
|
61
72
|
' && '
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-angulate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stan Bondi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -104,7 +104,6 @@ files:
|
|
104
104
|
- lib/rails/angulate/mappers/length_validator_mapper.rb
|
105
105
|
- lib/rails/angulate/mappers/numericality_validator_mapper.rb
|
106
106
|
- lib/rails/angulate/mappers/validator_mapper.rb
|
107
|
-
- lib/rails/angulate/railtie.rb
|
108
107
|
- lib/rails/angulate/version.rb
|
109
108
|
homepage: https://github.com/fixate/rails-angulate
|
110
109
|
licenses:
|
@@ -121,9 +120,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
120
|
version: '0'
|
122
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
122
|
requirements:
|
124
|
-
- - "
|
123
|
+
- - ">"
|
125
124
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
125
|
+
version: 1.3.1
|
127
126
|
requirements: []
|
128
127
|
rubyforge_project:
|
129
128
|
rubygems_version: 2.2.2
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'angulate/helpers'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Angulate
|
6
|
-
class Railtie < ::Rails::Railtie
|
7
|
-
initializer :include_helpers do |app|
|
8
|
-
ActiveSupport.on_load(:action_view) do
|
9
|
-
include Rails::Angulate::Helpers
|
10
|
-
cattr_accessor(:default_form_builder) { Rails::Angulate::Helpers::FormBuilder }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|