activeadmin-reform 0.1.4 → 0.2.0

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: fe939c986a95a4baa7f598300146d7e6247f9b69
4
- data.tar.gz: 084b5868e4f14229ee070851682c5ff2dba2222b
3
+ metadata.gz: 3b57cf76087dee6fbc7ec42507e0b62f28205a1a
4
+ data.tar.gz: 30b6c7abf2867fa0e0159bdc8c33e71d02e647c4
5
5
  SHA512:
6
- metadata.gz: a30cb87402a350883dacdec185801524b4a8a2082f5df1efb912cf68c9336608611a4b53c2eb3399e7d5f4010c0123fd5c3ddb28272fb9829ef05a536273dc00
7
- data.tar.gz: 46e2b596f13acb1e5feb090a0a7e887ad3c07e4b061ad259c3f313dd5e904103af1fa1671eab11f26d45f7e3e290f364d047fd7ce4e5fd1dd71d92e34efb3f0e
6
+ metadata.gz: 0b50e20d28f8a443e83796f0ec92f8586105d1d1faee899a31b2f40976655c4058d197fdecfad25fdd1d63107ef4e61e8464469299d9d569e1e670b921fb37a0
7
+ data.tar.gz: f39944434946235702a6d7da515c860051aa5c7a3b4335230e85b9b5dad54b4929c3335febc3c5452c97e681c8c8600bd1b65e79b5efc12543636407426c8820
data/.rubocop.yml CHANGED
@@ -6,9 +6,13 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
+ inherit_gem:
10
+ spbtv_code_style: .rubocop.yml
11
+
9
12
  AllCops:
10
13
  Exclude:
11
14
  - spec/dummy/**/*
15
+ - spec/templates/*
12
16
 
13
17
  # Configuration parameters: AllowURI, URISchemes.
14
18
  Metrics/LineLength:
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.2.0
2
+
3
+ * Update reform dependency to 2.2.1
data/Gemfile CHANGED
@@ -13,6 +13,7 @@ group :test do
13
13
  gem 'launchy', '~> 2.4.3'
14
14
  gem 'database_cleaner', '~> 1.5.1'
15
15
  gem 'capybara', '~> 2.5.0'
16
+ gem 'poltergeist'
16
17
 
17
18
  gem 'codeclimate-test-reporter', '~> 0.4.8', require: nil
18
19
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'activeadmin-reform'
7
- spec.version = '0.1.4'
7
+ spec.version = '0.2.0'
8
8
  spec.authors = ['Artyom Bolshakov']
9
9
  spec.email = ['abolshakov@spbtv.com']
10
10
 
@@ -20,9 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'rails', '>= 3.2'
22
22
  spec.add_dependency 'disposable', '>= 0.2.0'
23
- spec.add_dependency 'reform', '>= 2.0'
23
+ spec.add_dependency 'reform', '~> 2.2.1'
24
+ spec.add_dependency 'reform-rails'
24
25
  spec.add_development_dependency 'bundler', '~> 1.10'
25
26
  spec.add_development_dependency 'rake', '~> 10.0'
26
27
  spec.add_development_dependency 'rspec', '~> 3.4'
27
- spec.add_development_dependency 'rubocop', '~> 0.34.2'
28
+ spec.add_development_dependency 'spbtv_code_style', '~> 1.4.1'
28
29
  end
@@ -0,0 +1,29 @@
1
+ require 'reform'
2
+ require 'reform/form/active_record'
3
+ require 'reform/form/active_model/model_reflections'
4
+
5
+ module ActiveAdmin
6
+ module Reform
7
+ # Module that prepares the Reform::Form for use in activeadmin
8
+ module ActiveRecord
9
+ extend ActiveSupport::Concern
10
+
11
+ delegate :new_record?, to: :model
12
+
13
+ included do
14
+ include ::Reform::Form::ModelReflections
15
+ include ::Reform::Form::ActiveRecord
16
+ end
17
+
18
+ # Those methods are being used by activeadmin and are proxied to an inferred from name model
19
+ module ClassMethods
20
+ delegate :human_attribute_name, to: :model_class
21
+ delegate :lookup_ancestors, to: :model_class
22
+
23
+ def model_class
24
+ @model_class ||= model_name.to_s.constantize
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -10,6 +10,8 @@ module ActiveAdmin
10
10
  require 'active_admin'
11
11
  require_relative 'dsl'
12
12
  require_relative 'forms'
13
+
14
+ ActiveAdmin::FormBuilder.prepend FormBuilder
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,47 @@
1
+ require 'reform/form/active_model/model_reflections'
2
+
3
+ module ActiveAdmin
4
+ module Reform
5
+ # Patching ActiveAdmin::FormBuilder#js_for_has_many to provide nested forms support
6
+ # https://github.com/activeadmin/activeadmin/blob/539fa4b/lib/active_admin/form_builder.rb#L123
7
+ module FormBuilder
8
+ private
9
+
10
+ # Capture the ADD JS
11
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
+ def js_for_has_many(assoc, form_block, template, new_record, class_string)
13
+ assoc_reflection = object.class.reflect_on_association assoc
14
+ assoc_name = assoc_reflection.klass.model_name
15
+ placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(%r{/}, '_')}_RECORD"
16
+ opts = {
17
+ for: [assoc, nested_object(assoc)],
18
+ class: class_string,
19
+ for_options: { child_index: placeholder },
20
+ }
21
+ html = template.capture { inputs_for_nested_attributes opts, &form_block }
22
+ text = new_record.is_a?(String) ? new_record : I18n.t('active_admin.has_many_new', model: assoc_name.human)
23
+
24
+ template.link_to text, '#', class: 'button has_many_add', data: {
25
+ html: CGI.escapeHTML(html).html_safe, placeholder: placeholder
26
+ }
27
+ end
28
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
29
+
30
+ def nested_form_class(assoc)
31
+ if object.is_a?(::Reform::Form) && (property = object.class.definitions[assoc.to_s]) &&
32
+ (nested_form = property[:nested]) < ::Reform::Form
33
+ nested_form
34
+ end
35
+ end
36
+
37
+ def nested_object(assoc)
38
+ assoc_reflection = object.class.reflect_on_association assoc
39
+ if (nested_form = nested_form_class(assoc))
40
+ nested_form.new(assoc_reflection.klass.new).tap(&:prepopulate!)
41
+ else
42
+ assoc_reflection.klass.new
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,6 +1,11 @@
1
+ require 'reform'
2
+ require 'reform/rails'
3
+
1
4
  module ActiveAdmin
2
5
  #
3
6
  module Reform
4
7
  require_relative 'reform/engine'
8
+ require_relative 'reform/active_record'
9
+ require_relative 'reform/form_builder'
5
10
  end
6
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom Bolshakov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,18 +40,32 @@ dependencies:
40
40
  version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: reform
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: reform-rails
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '2.0'
61
+ version: '0'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '2.0'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +109,19 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3.4'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rubocop
112
+ name: spbtv_code_style
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.34.2
117
+ version: 1.4.1
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.34.2
124
+ version: 1.4.1
111
125
  description: Provides ability to use form object in your ActiveAdmin application
112
126
  email:
113
127
  - abolshakov@spbtv.com
@@ -120,6 +134,7 @@ files:
120
134
  - ".rspec"
121
135
  - ".rubocop.yml"
122
136
  - ".travis.yml"
137
+ - CHANGELOG.md
123
138
  - CODE_OF_CONDUCT.md
124
139
  - CONTRIBUTING.md
125
140
  - Gemfile
@@ -130,8 +145,10 @@ files:
130
145
  - bin/console
131
146
  - bin/setup
132
147
  - lib/active_admin/reform.rb
148
+ - lib/active_admin/reform/active_record.rb
133
149
  - lib/active_admin/reform/dsl.rb
134
150
  - lib/active_admin/reform/engine.rb
151
+ - lib/active_admin/reform/form_builder.rb
135
152
  - lib/active_admin/reform/forms.rb
136
153
  - lib/active_admin/reform/resource.rb
137
154
  - lib/active_admin/reform/resource_controller/data_access.rb