rails-angulate 0.0.5.rc4 → 0.0.5

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: 775f90b033d45baa2c8de1c4cb7eb1946555964a
4
- data.tar.gz: 374a6fac127a7e5304c6b6d9c49acef925dbe3cf
3
+ metadata.gz: 576545c753d58329200048bb33bec86c55d9ce24
4
+ data.tar.gz: 88c7ef8625b479fee67aaaff6e73491fdef2c397
5
5
  SHA512:
6
- metadata.gz: c02bf48f7ddb80b2c329895ae936ad5dcf609b157c633e72b05f8c1ed1e8294d5112d761a62b490934b8b67b9625d7e01f8046d824e58efd913b4e15e9fdce59
7
- data.tar.gz: 4ed585232d4abaf11eb77760fc914cee95e2966a064f7ad8584d30d3d637b0eaf2f95df800fd8c41be48ec76d3934aeefae0878a6ab9967a7f629b2c02f321c8
6
+ metadata.gz: 8cf18883909ca7da685db56e03d65bc7dc98d5d9d841170fab3a4914526e2fc18442822d10fb7e50cbba369830671a115f607c36396a8ba1034de174d50543b7
7
+ data.tar.gz: df92fabf45cb2f9a84ebcb05750ece38004082d5986cfd10e4bcf1ea2d1257b3715a34df224ce4896a0db06de4273db3d2b55f49463318354c7f01da4434a43f
@@ -20,16 +20,28 @@ module Rails
20
20
  end
21
21
  end
22
22
 
23
- %i{
24
- ng_form_name
25
- ng_valid
26
- ng_valid_for
27
- ng_invalid_for
28
- ng_invalid
29
- }.each do |_simple_method|
30
- define_method _simple_method do |*args, &block|
31
- @template.send(_simple_method, object, *args, &block)
32
- end
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(record, &block)
37
- valid_wrapper(record, '$valid', &block)
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(record, &block)
41
- valid_wrapper(record, '$invalid', &block)
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(record, attribute, &block)
45
- valid_wrapper(record, '$valid', attribute, &block)
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(record, attribute, &block)
49
- valid_wrapper(record, '$invalid', attribute, &block)
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(angular_error_list_html) unless validators.empty?
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 angular_error_list_html
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' => "#{angular_form_field_object_name}.$error.#{error_type}"
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: angular_form_object_name,
37
- field: angular_form_field_object_name,
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
- field = angular_form_field_object_name
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}" : "#{field}.$#{kind}") << op
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
- @validators ||=
23
- object.class.validators.select { |v| v.attributes.include?(@method_name.to_sym) }
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/, '')
@@ -11,6 +11,7 @@ module Rails
11
11
  autoload :NgTextArea
12
12
  autoload :NgEmailField
13
13
  autoload :NgValidationErrors
14
+ autoload :NgValid
14
15
  end
15
16
  end
16
17
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Angulate
3
- VERSION = "0.0.5.rc4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
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.rc4
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-07-22 00:00:00.000000000 Z
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: 1.3.1
127
+ version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
130
  rubygems_version: 2.2.2