form_angular 0.0.1 → 0.0.2

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: df338d7e4cd77e4e218a855bd39eac24349834dd
4
- data.tar.gz: a533b71363ac59792bce35ec008d073bfaa5db57
3
+ metadata.gz: 10b085e08a657283eb0d7ed56cf681518c107f46
4
+ data.tar.gz: abf225ebac05be230089f0e62d0f1c16c574de7d
5
5
  SHA512:
6
- metadata.gz: 20cc36741a1e26b7df18c0d1f2bc0ad075808e9b13eebc131cc70a9b42b890d256a78ebd72ae287214e1d4a823a266eb7e2d626fb583ead04c18f4186cb49668
7
- data.tar.gz: e35f8772c5f0e3e7c9f6de0bf466a1be1eee7229c9e0daae28ffc2dd532a3ff55e90bca6e87b3fd2fb6e4cd3254c84477d0d179084d9418601723df8e341d083
6
+ metadata.gz: 98d8ff8da7a044967fa3d8e44b2dd799194706949f07e61acfe53647973e4a36ed82c9fcea69950af655f283ca0f43d5d39755ef47b62d33d2a527c4292ac37c
7
+ data.tar.gz: df6a7d672c467b9c0beb8246c89b5023e6401821d417466d92cf3f40c0b80f5adf047f72622cd309160d25c881030b202e947e3f193b79f3bd10befda9ff1a59
@@ -1,31 +1,29 @@
1
1
  module FormAngular
2
2
  module Fields
3
3
  module NgModelInput
4
- include NgOptionUtils
5
4
  extend ActiveSupport::Concern
5
+ include NgOptionUtils
6
6
 
7
7
  included do
8
- alias_method_chain :input, :ng_model
8
+ alias_method_chain :initialize, :ng_model
9
9
  end
10
10
 
11
- def input_with_ng_model(attribute_name, options = {}, &block)
12
- options[:input_html] ||= {}
13
- if @options[:ngform]
14
- options[:input_html].merge! build_angular_options(attribute_name, @options)
15
- else
16
- parent_builder = @options[:parent_builder]
17
- until !parent_builder || parent_builder.options[:ngform]
18
- parent_builder = parent_builder.options[:parent_builder]
19
- end
20
- if parent_builder && parent_builder.options[:ngform]
21
- options[:input_html].merge! build_angular_options(attribute_name, @options[:parent_builder].options)
22
- end
23
- end
11
+ def initialize_with_ng_model(builder, attribute_name, column, input_type, options = {})
12
+ initialize_without_ng_model(builder, attribute_name, column, input_type, options)
13
+ input_html_options.merge! build_angular_options(attribute_name, @builder) if is_ng_form?
14
+ end
24
15
 
25
- input_without_angular(attribute_name, options, &block)
16
+ def is_ng_form?
17
+ return @builder.options[:ngform] if @builder.options[:ngform].present?
18
+ parent_builder = @builder.options[:parent_builder]
19
+ #Find a parent builder with ngform
20
+ until !parent_builder || parent_builder.options[:ngform].present?
21
+ parent_builder = parent_builder.options[:parent_builder]
22
+ end
23
+ return parent_builder && parent_builder.options[:ngform]
26
24
  end
27
25
  end
28
26
  end
29
27
  end
30
28
 
31
- SimpleForm::FormBuilder.send :include, FormAngular::Fields::NgModelInput
29
+ SimpleForm::Inputs::Base.send :include, FormAngular::Fields::NgModelInput
@@ -11,19 +11,19 @@ module FormAngular
11
11
  }
12
12
  end
13
13
 
14
- def form_context(record)
15
- record.class.name.camelize(:lower)
16
- end
17
14
 
18
- def fields_context(record, options)
19
- "#{options[:fields_context]}.#{context_name(record)}"
15
+ def build_angular_options(attribute_name, builder)
16
+ begin
17
+ angular_options = {
18
+ 'ng-model' => "#{builder.object_name.sub("[", ".").sub("]", "").sub("_attributes", "")}.#{attribute_name}",
19
+ 'server-error' => "true"
20
+ }
21
+ rescue => e
22
+ end
20
23
  end
21
24
 
22
- def build_angular_options(attribute_name, form_options)
23
- angular_options = {
24
- 'ng-model' => "#{form_options[:fields_context]}.#{attribute_name}",
25
- 'server-error' => "true"
26
- }
25
+ def form_context(record)
26
+ record.class.name.camelize(:lower)
27
27
  end
28
28
 
29
29
  def context_name(record)
@@ -36,19 +36,19 @@ module FormAngular
36
36
 
37
37
  #Find a better way to make the form name trickledown globally in the wrapper api
38
38
  def form_name
39
- name = name_from_options(@builder.options)
39
+ name = from_html_options(:name, @builder.options)
40
40
  return name unless name.blank?
41
41
  builder = @builder
42
42
  until !builder || !name.blank?
43
- name = name_from_options(builder.options)
43
+ name = from_html_options(:name, builder.options)
44
44
  builder = builder.options[:parent_builder]
45
45
  end
46
46
  name
47
47
  end
48
48
 
49
- def name_from_options(from_options)
50
- if from_options[:html]
51
- from_options[:html][:name]
49
+ def from_html_options(key, html_options)
50
+ if html_options[:html]
51
+ html_options[:html][key]
52
52
  end
53
53
  end
54
54
 
@@ -1,3 +1,3 @@
1
1
  module FormAngular
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_angular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Balaine
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -55,7 +55,6 @@ files:
55
55
  - lib/form_angular.rb
56
56
  - lib/form_angular/errors/ng_error.rb
57
57
  - lib/form_angular/errors/ng_input_error.rb
58
- - lib/form_angular/fields/ng_fieldset.rb
59
58
  - lib/form_angular/fields/ng_model.rb
60
59
  - lib/form_angular/forms/ng_form.rb
61
60
  - lib/form_angular/helpers/ng_option_utils.rb
@@ -1,32 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'helpers', 'ng_option_utils')
2
-
3
- module FormAngular
4
- module FieldSet
5
- module NgFields
6
- include NgOptionUtils
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- alias_method_chain :simple_fields_for, :ng_model
11
- end
12
-
13
- def simple_fields_for_with_ng_model(record, options = {}, &block)
14
- if @options[:ngform]
15
- @options[:fields_context] = fields_context(record, @options)
16
- else
17
- parent_builder = @options[:parent_builder]
18
- until !parent_builder || parent_builder.options[:ngform]
19
- parent_builder = parent_builder.options[:parent_builder]
20
- end
21
- if parent_builder && parent_builder.options[:ngform]
22
- @options[:fields_context] = fields_context(record, @options[:parent_builder].options)
23
- end
24
- end
25
-
26
- simple_fields_for_without_ng_model(record, options, &block)
27
- end
28
- end
29
- end
30
- end
31
-
32
- SimpleForm::FormBuilder.send :include, FormAngular::FieldSet::NgFields