administrate-field-nested_has_many 0.0.2 → 1.0.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
- SHA1:
3
- metadata.gz: 2cb29d90820122048ad397c50a5f663381a06975
4
- data.tar.gz: f0f0d555baa0f4f2dc0e414b509cb415e1bb74c8
2
+ SHA256:
3
+ metadata.gz: dd88637ffa9a205a64a76b0c72b2af2a9aea05331094d563ad055f0347dcb49c
4
+ data.tar.gz: '021851337256c69a63d69045caf809bad66f998949d6cf50433961290db4c726'
5
5
  SHA512:
6
- metadata.gz: a07b34b7debeba156a264e191b0b7d4ab054519ee12fd71d536b3e50fbd68536050f49cc5e7375c802a9f68900195bf6f3167b620bbedcaa035c8c517d7b6ed5
7
- data.tar.gz: ca68e9204dfcc2e472ec7e1da8d5039b1bcbc11e3d90b80f3dc0fc37c6d2bf48d04d440e343ac6dc1c611776ffb29002e0f2a7e3e75303674058b3369b2b2dd5
6
+ metadata.gz: 2d6c8787987ca3ebe4c5e4cd93fd8008b71107759612816e7f31eb0adc752b8cd9d174c42052ebcec9bded051447a40a2226723e4628134a95dbfeccd9b31e95
7
+ data.tar.gz: 24417b0d9eb65d813f9b898ee3cd776ee22129bb37f865bd20eb0e0ec20b853112308af7931789b601c52486b1fce69aca8d3aa5c46adf427cce80b71e02eb08
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1,35 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0
4
+
5
+ * Add `rake` for testing and release tools ([#16][]).
6
+ * Fixes for `administrate` 0.9.0 ([#11][]).
7
+ * Ensure current data is injected into nested fields ([#10][]).
8
+ * Remove direct dependency on Rails ([#10][]).
9
+ * Add i18n support ([#10][]).
10
+ * Make styling more consistent with `has_one` form ([#10][]).
11
+ * Add missing Gemfile and missing dependency on RSpec ([#15][]).
12
+ * Update gem location and authors ([#14][]).
13
+ * Avoid circular dependencies by not including the full library in the Gemspec
14
+ ([#13][]).
15
+
16
+ [#16]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/16
17
+ [#15]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/15
18
+ [#14]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/14
19
+ [#13]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/13
20
+ [#11]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/11
21
+ [#10]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/10
22
+
23
+ ## 0.1.0
24
+
25
+ * Updates for changes in `administrate` 0.2.1.
26
+ * Import JavaScript automatically.
27
+
28
+ ## 0.0.2
29
+
30
+ * Add missing import for `cocoon`.
31
+ * Note stop gap fix for missing JavaScript imports.
32
+
33
+ ## 0.0.1
34
+
35
+ * Initial Release.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md CHANGED
@@ -7,7 +7,7 @@ A plugin for nested has_many forms in [Administrate].
7
7
  Add to your `Gemfile`:
8
8
 
9
9
  ```ruby
10
- gem "administrate-field-nested_has_many", "~> 0.0.2"
10
+ gem "administrate-field-nested_has_many"
11
11
  ```
12
12
 
13
13
  Run:
@@ -17,6 +17,7 @@ $ bundle install
17
17
  ```
18
18
 
19
19
  Add to your `FooDashboard`:
20
+
20
21
  ```ruby
21
22
  ATTRIBUTE_TYPES = [
22
23
  bars: Field::NestedHasMany.with_options(skip: :foo),
@@ -34,20 +35,4 @@ Otherwise, Administrate will try to render a field
34
35
  for the order's `:customer` attribute,
35
36
  which breaks the nested form logic.
36
37
 
37
- ## Stopgap fix for javascript
38
-
39
- At the moment, Administrate doesn't automatically load javascripts from plugins.
40
- To fix this, you need to generate the Administrate javascript file:
41
-
42
- ```bash
43
- $ rails g administrate:views:layout
44
- ```
45
-
46
- And then add a line to `app/views/admin/application/_javascript.html.erb`
47
- to input the javascript for this gem:
48
-
49
- ```
50
- <%= javascript_include_tag "administrate-field-nested_has_many/application" %>
51
- ```
52
-
53
38
  [Administrate]: https://github.com/thoughtbot/administrate
@@ -0,0 +1,20 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "bundler/gem_tasks"
8
+
9
+ ##
10
+ # Configure the test suite.
11
+ ##
12
+ require "rspec/core"
13
+ require "rspec/core/rake_task"
14
+
15
+ RSpec::Core::RakeTask.new
16
+
17
+ ##
18
+ # By default, just run the tests.
19
+ ##
20
+ task default: :spec
@@ -1,13 +1,12 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
- require "administrate/field/nested_has_many"
4
-
5
3
  Gem::Specification.new do |gem|
6
4
  gem.name = "administrate-field-nested_has_many"
7
- gem.version = Administrate::Field::NestedHasMany::VERSION
8
- gem.authors = ["Grayson Wright"]
9
- gem.email = ["wright.grayson@gmail.com"]
10
- gem.homepage = "https://github.com/graysonwright/administrate-field-nested_has_many"
5
+ gem.version = "1.0.0"
6
+ gem.authors = ["Nick Charlton", "Grayson Wright"]
7
+ gem.email = ["nick@nickcharlton.net", "wright.grayson@gmail.com"]
8
+ gem.homepage = "https://github.com/nickcharlton/" \
9
+ "administrate-field-nested_has_many"
11
10
  gem.summary = "Plugin for nested has_many forms in Administrate"
12
11
  gem.description = gem.summary
13
12
  gem.license = "MIT"
@@ -16,7 +15,9 @@ Gem::Specification.new do |gem|
16
15
  gem.files = `git ls-files`.split("\n")
17
16
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
17
 
19
- gem.add_dependency "administrate", "~> 0.2.0"
20
- gem.add_dependency "cocoon", "~> 1.2"
21
- gem.add_dependency "rails", "~> 4.2"
18
+ gem.add_dependency "administrate", "> 0.8", "< 1"
19
+ gem.add_dependency "cocoon", "~> 1.2", ">= 1.2.11"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
22
23
  end
@@ -0,0 +1,14 @@
1
+ @import 'administrate/library/variables';
2
+ @import 'administrate/library/clearfix';
3
+
4
+ .field-unit--nested-has-many {
5
+ .nested-fields {
6
+ @include administrate-clearfix;
7
+ margin-bottom: $base-spacing;
8
+ padding-bottom: $base-spacing;
9
+ }
10
+
11
+ .remove_fields, .add_fields {
12
+ float: right;
13
+ }
14
+ }
@@ -1,11 +1,9 @@
1
- <div class="nested-fields" style="width:100%">
2
-
3
- <% field.nested_fields.each do |attribute| -%>
1
+ <div class="nested-fields">
2
+ <% field.nested_fields_for_builder(f).each do |attribute| -%>
4
3
  <div class="field-unit field-unit--<%= attribute.html_class %>">
5
4
  <%= render_field attribute, f: f %>
6
5
  </div>
7
6
  <% end -%>
8
7
 
9
- <%# TODO I18n %>
10
- <%= link_to_remove_association "Remove #{field.associated_class_name.titleize}", f %>
8
+ <%= link_to_remove_association I18n.t("administrate.fields.nested_has_many.remove", resource: field.associated_class_name.titleize), f %>
11
9
  </div>
@@ -1,23 +1,23 @@
1
- <div class="nested-fields" style="width: 40%; margin-left: 20%;">
2
-
1
+ <fieldset class="field-unit--nested">
2
+ <legend><%= f.label field.attribute %></legend>
3
3
  <%= f.fields_for field.association_name do |nested_form| %>
4
- <%= render(
5
- partial: "fields/nested_has_many/fields",
6
- locals: {
7
- f: nested_form,
8
- field: field,
9
- },
10
- ) %>
4
+ <%= render(
5
+ partial: "fields/nested_has_many/fields",
6
+ locals: {
7
+ f: nested_form,
8
+ field: field,
9
+ },
10
+ ) %>
11
11
  <% end %>
12
12
 
13
13
  <div>
14
14
  <%= link_to_add_association(
15
- # TODO I18n
16
- "Add #{field.associated_class_name.titleize}",
15
+ I18n.t("administrate.fields.nested_has_many.add", resource: field.associated_class_name.titleize),
17
16
  f,
18
17
  field.association_name,
18
+ class: 'button',
19
19
  partial: "fields/nested_has_many/fields",
20
20
  render_options: { locals: { field: field } },
21
21
  ) %>
22
22
  </div>
23
- </div>
23
+ </fieldset>
@@ -22,7 +22,8 @@ from the associated resource class's dashboard.
22
22
  <%= render(
23
23
  "collection",
24
24
  collection_presenter: field.associated_collection,
25
- resources: field.resources
25
+ resources: field.resources,
26
+ table_title: field.name
26
27
  ) %>
27
28
 
28
29
  <% if field.more_than_limit? %>
@@ -36,5 +37,5 @@ from the associated resource class's dashboard.
36
37
  <% end %>
37
38
 
38
39
  <% else %>
39
- <%= t("administrate.fields.has_many.none") %>
40
+ <%= t("administrate.fields.has_many.none", default: "–") %>
40
41
  <% end %>
@@ -0,0 +1,7 @@
1
+ ---
2
+ en:
3
+ administrate:
4
+ fields:
5
+ nested_has_many:
6
+ add: "Add %{resource}"
7
+ remove: "Remove %{resource}"
@@ -1,17 +1,22 @@
1
1
  require "administrate/field/has_many"
2
2
  require "administrate/page/form"
3
3
  require "rails"
4
+ require "administrate/engine"
4
5
  require "cocoon"
5
6
 
6
7
  module Administrate
7
8
  module Field
8
9
  class NestedHasMany < Administrate::Field::HasMany
9
- VERSION = "0.0.2"
10
-
11
10
  class Engine < ::Rails::Engine
11
+ Administrate::Engine.add_javascript(
12
+ "administrate-field-nested_has_many/application",
13
+ )
14
+ Administrate::Engine.add_stylesheet(
15
+ "administrate-field-nested_has_many/application",
16
+ )
12
17
  end
13
18
 
14
- DEFAULT_ATTRIBUTES = [:id, :_destroy].freeze
19
+ DEFAULT_ATTRIBUTES = %i(id _destroy).freeze
15
20
 
16
21
  def nested_fields
17
22
  associated_form.attributes.reject do |nested_field|
@@ -19,6 +24,21 @@ module Administrate
19
24
  end
20
25
  end
21
26
 
27
+ def nested_fields_for_builder(form_builder)
28
+ return nested_fields unless form_builder.index.is_a? Integer
29
+
30
+ nested_fields.each do |nested_field|
31
+ next if nested_field.resource.blank?
32
+
33
+ # inject current data into field
34
+ resource = nested_field.resource[form_builder.index]
35
+ nested_field.instance_variable_set(
36
+ "@data",
37
+ resource.send(nested_field.attribute),
38
+ )
39
+ end
40
+ end
41
+
22
42
  def to_s
23
43
  data
24
44
  end
@@ -32,7 +52,7 @@ module Administrate
32
52
  dashboard_for_resource(associated_resource).new.permitted_attributes
33
53
  end
34
54
 
35
- def self.permitted_attribute(associated_resource)
55
+ def self.permitted_attribute(associated_resource, _options = nil)
36
56
  {
37
57
  "#{associated_resource}_attributes".to_sym =>
38
58
  associated_attributes(associated_resource),
@@ -48,7 +68,7 @@ module Administrate
48
68
  end
49
69
 
50
70
  def associated_form
51
- Administrate::Page::Form.new(associated_dashboard, association_name)
71
+ Administrate::Page::Form.new(associated_dashboard, data)
52
72
  end
53
73
 
54
74
  private
metadata CHANGED
@@ -1,29 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-nested_has_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Nick Charlton
7
8
  - Grayson Wright
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
12
+ date: 2018-03-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: administrate
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - "~>"
18
+ - - ">"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.8'
21
+ - - "<"
18
22
  - !ruby/object:Gem::Version
19
- version: 0.2.0
23
+ version: '1'
20
24
  type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
- - - "~>"
28
+ - - ">"
25
29
  - !ruby/object:Gem::Version
26
- version: 0.2.0
30
+ version: '0.8'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
27
34
  - !ruby/object:Gem::Dependency
28
35
  name: cocoon
29
36
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +38,9 @@ dependencies:
31
38
  - - "~>"
32
39
  - !ruby/object:Gem::Version
33
40
  version: '1.2'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.11
34
44
  type: :runtime
35
45
  prerelease: false
36
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,37 +48,62 @@ dependencies:
38
48
  - - "~>"
39
49
  - !ruby/object:Gem::Version
40
50
  version: '1.2'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.11
41
54
  - !ruby/object:Gem::Dependency
42
- name: rails
55
+ name: rake
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
- - - "~>"
58
+ - - ">="
46
59
  - !ruby/object:Gem::Version
47
- version: '4.2'
48
- type: :runtime
60
+ version: '0'
61
+ type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
- - - "~>"
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
53
80
  - !ruby/object:Gem::Version
54
- version: '4.2'
81
+ version: '0'
55
82
  description: Plugin for nested has_many forms in Administrate
56
83
  email:
84
+ - nick@nickcharlton.net
57
85
  - wright.grayson@gmail.com
58
86
  executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
90
+ - ".gitignore"
91
+ - CHANGELOG.md
92
+ - Gemfile
62
93
  - README.md
94
+ - Rakefile
63
95
  - administrate-field-nested_has_many.gemspec
64
96
  - app/assets/javascripts/administrate-field-nested_has_many/application.js
97
+ - app/assets/stylesheets/administrate-field-nested_has_many/application.css
98
+ - app/assets/stylesheets/administrate-field-nested_has_many/base.scss
65
99
  - app/views/fields/nested_has_many/_fields.html.erb
66
100
  - app/views/fields/nested_has_many/_form.html.erb
67
101
  - app/views/fields/nested_has_many/_index.html.erb
68
102
  - app/views/fields/nested_has_many/_show.html.erb
103
+ - config/locales/administrate-field-nested_has_many.en.yml
69
104
  - lib/administrate/field/nested_has_many.rb
70
105
  - spec/lib/administrate/field/nested_has_many_spec.rb
71
- homepage: https://github.com/graysonwright/administrate-field-nested_has_many
106
+ homepage: https://github.com/nickcharlton/administrate-field-nested_has_many
72
107
  licenses:
73
108
  - MIT
74
109
  metadata: {}
@@ -88,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
123
  version: '0'
89
124
  requirements: []
90
125
  rubyforge_project:
91
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.7.3
92
127
  signing_key:
93
128
  specification_version: 4
94
129
  summary: Plugin for nested has_many forms in Administrate