rails-angulate 0.0.5.rc4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails/angulate/helpers/form_builder.rb +22 -10
- data/lib/rails/angulate/helpers/form_helper.rb +8 -18
- data/lib/rails/angulate/helpers/tags/ng_valid.rb +28 -0
- data/lib/rails/angulate/helpers/tags/ng_validation_errors.rb +7 -8
- data/lib/rails/angulate/helpers/tags/tag_common.rb +27 -10
- data/lib/rails/angulate/helpers/tags.rb +1 -0
- data/lib/rails/angulate/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 576545c753d58329200048bb33bec86c55d9ce24
|
4
|
+
data.tar.gz: 88c7ef8625b479fee67aaaff6e73491fdef2c397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf18883909ca7da685db56e03d65bc7dc98d5d9d841170fab3a4914526e2fc18442822d10fb7e50cbba369830671a115f607c36396a8ba1034de174d50543b7
|
7
|
+
data.tar.gz: df92fabf45cb2f9a84ebcb05750ece38004082d5986cfd10e4bcf1ea2d1257b3715a34df224ce4896a0db06de4273db3d2b55f49463318354c7f01da4434a43f
|
@@ -20,16 +20,28 @@ module Rails
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
ng_form_name
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
def ng_form_name
|
24
|
+
@template.ng_form_name(@object_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ng_valid(options = {}, html_options = {}, &block)
|
28
|
+
options = objectify_options(options)
|
29
|
+
@template.ng_valid(@object_name, options, html_options, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ng_invalid(options = {}, html_options = {}, &block)
|
33
|
+
options = objectify_options(options)
|
34
|
+
@template.ng_invalid(@object_name, options, html_options, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ng_valid_for(method, options = {}, html_options = {}, &block)
|
38
|
+
options = objectify_options(options)
|
39
|
+
@template.ng_valid_for(@object_name, method, options, html_options, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ng_invalid_for(method, options = {}, html_options = {}, &block)
|
43
|
+
options = objectify_options(options)
|
44
|
+
@template.ng_invalid_for(@object_name, method, options, html_options, &block)
|
33
45
|
end
|
34
46
|
|
35
47
|
def ng_select(method, choices = {}, options = {}, html_options = {})
|
@@ -33,24 +33,20 @@ module Rails
|
|
33
33
|
Tags::NgValidationErrors.new(object_name, method, self, options).render
|
34
34
|
end
|
35
35
|
|
36
|
-
def ng_valid(
|
37
|
-
|
36
|
+
def ng_valid(object_name, options, html_options, &block)
|
37
|
+
Tags::NgValid.new(object_name, nil, self, options, html_options, '$valid').render(&block)
|
38
38
|
end
|
39
39
|
|
40
|
-
def ng_invalid(
|
41
|
-
|
40
|
+
def ng_invalid(object_name, options, html_options, &block)
|
41
|
+
Tags::NgValid.new(object_name, nil, self, options, html_options, '$invalid').render(&block)
|
42
42
|
end
|
43
43
|
|
44
|
-
def ng_valid_for(
|
45
|
-
|
44
|
+
def ng_valid_for(object_name, method, options, html_options, &block)
|
45
|
+
Tags::NgValid.new(object_name, method, self, options, html_options, '$valid').render(&block)
|
46
46
|
end
|
47
47
|
|
48
|
-
def ng_invalid_for(
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def ng_form_field_name(record, attribute)
|
53
|
-
"#{ng_form_name(record)}['#{object_name_for(record)}[#{attribute}]']"
|
48
|
+
def ng_invalid_for(object_name, method, options, html_options, &block)
|
49
|
+
Tags::NgValid.new(object_name, method, self, options, html_options, '$invalid').render(&block)
|
54
50
|
end
|
55
51
|
|
56
52
|
def ng_form_name(record)
|
@@ -70,12 +66,6 @@ module Rails
|
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
73
|
-
def valid_wrapper(record, type, attribute = nil, &block)
|
74
|
-
ng_if = attribute.nil? ? ng_form_name(record) : ng_form_field_name(record, attribute)
|
75
|
-
content = capture(&block)
|
76
|
-
content_tag :span, content.html_safe, 'ng-if' => "#{ng_if}.#{type}"
|
77
|
-
end
|
78
|
-
|
79
69
|
end
|
80
70
|
end
|
81
71
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rails
|
2
|
+
module Angulate
|
3
|
+
module Helpers
|
4
|
+
module Tags
|
5
|
+
class NgValid < ActionView::Helpers::Tags::Base
|
6
|
+
include TagCommon
|
7
|
+
attr_accessor :output_buffer
|
8
|
+
|
9
|
+
def initialize(object_name, method, template_object, options, html_options, qualifier)
|
10
|
+
@html_options = html_options
|
11
|
+
@qualifier = qualifier
|
12
|
+
@output_buffer = ActionView::OutputBuffer.new
|
13
|
+
|
14
|
+
super(object_name, method, template_object, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(&block)
|
18
|
+
object_name = @method_name.nil? ? form_object_name : form_field_object_name
|
19
|
+
|
20
|
+
content = ''
|
21
|
+
content = @template_object.capture(&block) if block_given?
|
22
|
+
content_tag :span, content, 'ng-show' => "#{object_name}.#{@qualifier}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -8,7 +8,7 @@ module Rails
|
|
8
8
|
def render
|
9
9
|
# We can't use content_tag with a block (no self.output_buffer)
|
10
10
|
# so we pass in content
|
11
|
-
container(
|
11
|
+
container(error_list_html) unless validators.empty?
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -21,11 +21,11 @@ module Rails
|
|
21
21
|
content_tag :ul, content, container_attrs
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def error_list_html
|
25
25
|
validators.map do |validator|
|
26
26
|
mapper = validator_mapper_for(validator)
|
27
27
|
mapper.error_messages.map do |error_type, msg|
|
28
|
-
content_tag :li, msg, 'ng-show' => "#{
|
28
|
+
content_tag :li, msg, 'ng-show' => "#{form_field_object_name}.$error.#{error_type}"
|
29
29
|
end.join
|
30
30
|
end.join.html_safe
|
31
31
|
end
|
@@ -33,8 +33,8 @@ module Rails
|
|
33
33
|
def container_attrs
|
34
34
|
ng_show = configuration.validate_show_condition % {
|
35
35
|
model: @object_name,
|
36
|
-
form:
|
37
|
-
field:
|
36
|
+
form: form_object_name,
|
37
|
+
field: form_field_object_name,
|
38
38
|
validate_on: validate_on || 'true'
|
39
39
|
}
|
40
40
|
|
@@ -61,8 +61,7 @@ module Rails
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def validate_on
|
64
|
-
|
65
|
-
form = angular_form_object_name
|
64
|
+
form = form_object_name
|
66
65
|
|
67
66
|
return validate_on_options if validate_on_options.is_a?(String)
|
68
67
|
|
@@ -76,7 +75,7 @@ module Rails
|
|
76
75
|
''
|
77
76
|
end
|
78
77
|
|
79
|
-
str << (kind == :submit_attempt ? "#{form}.$#{kind}" : "#{
|
78
|
+
str << (kind == :submit_attempt ? "#{form}.$#{kind}" : "#{field_name}.$#{kind}") << op
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|
@@ -10,17 +10,18 @@ module Rails
|
|
10
10
|
|
11
11
|
delegate :configuration, to: Rails::Angulate
|
12
12
|
|
13
|
-
def angular_form_object_name
|
14
|
-
@template_object.ng_form_name(object)
|
15
|
-
end
|
16
|
-
|
17
|
-
def angular_form_field_object_name
|
18
|
-
@template_object.ng_form_field_name(object, @method_name)
|
19
|
-
end
|
20
|
-
|
21
13
|
def validators
|
22
|
-
|
23
|
-
|
14
|
+
if object.nil?
|
15
|
+
raise RuntimeError.new(<<-TEXT.strip)
|
16
|
+
Form helper object is nil. If this is an association
|
17
|
+
make sure that you accept_nested_attributes_for :assocation
|
18
|
+
so that validations for nested attributes can be determined.
|
19
|
+
TEXT
|
20
|
+
end
|
21
|
+
|
22
|
+
@validators ||= object.class.validators.select do |v|
|
23
|
+
v.attributes.include?(@method_name.to_sym)
|
24
|
+
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def add_ng_validation_attrs(attrs)
|
@@ -54,6 +55,22 @@ module Rails
|
|
54
55
|
name.camelize(:lower)
|
55
56
|
end
|
56
57
|
|
58
|
+
def form_object_name
|
59
|
+
"#{@object_name.gsub(/\[.+\]/, '')}_form"
|
60
|
+
end
|
61
|
+
|
62
|
+
def form_field_object_name
|
63
|
+
"#{form_object_name}['#{field_name}']"
|
64
|
+
end
|
65
|
+
|
66
|
+
def field_name
|
67
|
+
@field_name ||= begin
|
68
|
+
names = {}
|
69
|
+
add_default_name_and_id(names)
|
70
|
+
names['name']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
57
74
|
module ClassMethods
|
58
75
|
def field_type
|
59
76
|
@field_type ||= super.sub(/^ng/, '')
|
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.5
|
4
|
+
version: 0.0.5
|
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-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/rails/angulate/helpers/tags/ng_select.rb
|
98
98
|
- lib/rails/angulate/helpers/tags/ng_text_area.rb
|
99
99
|
- lib/rails/angulate/helpers/tags/ng_text_field.rb
|
100
|
+
- lib/rails/angulate/helpers/tags/ng_valid.rb
|
100
101
|
- lib/rails/angulate/helpers/tags/ng_validation_errors.rb
|
101
102
|
- lib/rails/angulate/helpers/tags/tag_common.rb
|
102
103
|
- lib/rails/angulate/mappers.rb
|
@@ -121,9 +122,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '0'
|
122
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
124
|
requirements:
|
124
|
-
- - "
|
125
|
+
- - ">="
|
125
126
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
127
|
+
version: '0'
|
127
128
|
requirements: []
|
128
129
|
rubyforge_project:
|
129
130
|
rubygems_version: 2.2.2
|