dynamic_fields_for_rails 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +87 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/app/helpers/dynamic_fields_for_helper.rb +14 -9
- data/dynamic_fields_for_rails.gemspec +14 -13
- data/lib/dynamic_fields_for_rails/version.rb +3 -1
- data/lib/dynamic_fields_for_rails.rb +7 -3
- data/test/config/active_record.rb +5 -0
- data/test/dummy/Rakefile +3 -1
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/application_record.rb +5 -0
- data/test/dummy/app/models/child.rb +3 -1
- data/test/dummy/app/models/parent.rb +3 -1
- data/test/dummy/config/application.rb +8 -4
- data/test/dummy/config/boot.rb +4 -2
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/development.rb +2 -0
- data/test/dummy/config/environments/production.rb +3 -1
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/test/dummy/config/initializers/inflections.rb +2 -0
- data/test/dummy/config/initializers/mime_types.rb +2 -0
- data/test/dummy/config/initializers/secret_token.rb +3 -2
- data/test/dummy/config/initializers/session_store.rb +2 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/config.ru +2 -0
- data/test/dummy/db/migrate/20130423140255_create_parents.rb +2 -0
- data/test/dummy/db/migrate/20130423140307_create_children.rb +2 -0
- data/test/dummy/db/schema.rb +9 -8
- data/test/dummy/log/test.log +694 -0
- data/test/dummy/script/rails +4 -2
- data/test/dynamic_fields_for_helper_test.rb +3 -1
- data/test/link_to_add_fields_test.rb +7 -5
- data/test/link_to_delete_fields_test.rb +10 -8
- data/test/test_helper.rb +7 -5
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4fb93a2e2de4bdf5c990fa45f0ef8e1a07ab99564fded98502037a3bf02b92a6
|
4
|
+
data.tar.gz: 6aed3f7be5c1a3c47fa6ee45a5fb02bd5a23de836689715b875e55aa0b736606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b9f8dc2cf26c34a8a160e0471a51766c36fc94f8f489ceeae21eb164d6b668a7af814b3307e36e479787af38bbebf64d90c640d86c11a460e8d55dfca406bd8
|
7
|
+
data.tar.gz: 35e0d9745b721606ae77b682546a12c3c466540d4a8e2e655eb906b6e3c808f6dad93208875ae3642c17a084bb6a15b5e5e897d74abc48a11271510d272a607b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- 'node_modules/**/*'
|
5
|
+
- 'db/**/*'
|
6
|
+
- 'tmp/**/*'
|
7
|
+
- 'vendor/**/*'
|
8
|
+
- 'bin/**/*'
|
9
|
+
- 'log/**/*'
|
10
|
+
- 'Brewfile'
|
11
|
+
- 'Rakefile'
|
12
|
+
|
13
|
+
Rails:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false # for now
|
18
|
+
|
19
|
+
Style/Lambda:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/RaiseArgs:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Naming/FileName:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
# User.all.map do |user|
|
29
|
+
# [user.name, user.children.map(&:names)]
|
30
|
+
# end.flatten.map do |name|
|
31
|
+
# name.capitalize
|
32
|
+
# end.join(", ")
|
33
|
+
Style/MultilineBlockChain:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# [
|
37
|
+
# "foo",
|
38
|
+
# "bar",
|
39
|
+
# ]
|
40
|
+
Style/TrailingCommaInArrayLiteral:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/TrailingCommaInHashLiteral:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Layout/RescueEnsureAlignment:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/AccessModifierDeclarations:
|
50
|
+
EnforcedStyle: inline
|
51
|
+
|
52
|
+
Metrics/LineLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/ClassLength:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Metrics/MethodLength:
|
59
|
+
Max: 40
|
60
|
+
|
61
|
+
Metrics/BlockLength:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Metrics/AbcSize:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Metrics/PerceivedComplexity:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/ParallelAssignment:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Metrics/CyclomaticComplexity:
|
74
|
+
Max: 10
|
75
|
+
|
76
|
+
# `fail` is seldom/never seen in Ruby code.
|
77
|
+
# https://github.com/bbatsov/ruby-style-guide/issues/233
|
78
|
+
Style/SignalException:
|
79
|
+
EnforcedStyle: only_raise
|
80
|
+
|
81
|
+
# Would complain about `new_record?` otherwise
|
82
|
+
Style/TrivialAccessors:
|
83
|
+
ExactNameMatch: true
|
84
|
+
|
85
|
+
Rails/Delegate:
|
86
|
+
Exclude:
|
87
|
+
- lib/**/*
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,21 +1,24 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module DynamicFieldsForHelper
|
3
4
|
def link_to_add_fields(form, association, options = {}, &block)
|
4
5
|
partial = options[:partial] || nil
|
5
6
|
name = options[:name] || nil
|
6
7
|
css_classes = options[:class] || nil
|
7
8
|
target = options[:target] || nil
|
8
|
-
|
9
9
|
new_object = form.object.send(association).klass.new
|
10
10
|
id = new_object.object_id
|
11
|
+
|
11
12
|
fields = form.fields_for(association, new_object, child_index: id) do |builder|
|
12
13
|
if partial
|
13
|
-
render("#{form.object.class.name.
|
14
|
+
render("#{form.object.class.name.underscore.pluralize}/#{partial}", fields: builder)
|
14
15
|
else
|
15
|
-
render("#{form.object.class.name.
|
16
|
+
render("#{form.object.class.name.underscore.pluralize}/#{association.to_s.singularize}_fields", fields: builder)
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
18
20
|
css_classes = css_classes(DynamicFieldsForRails.add_css_classes, css_classes)
|
21
|
+
|
19
22
|
if block_given?
|
20
23
|
link_to('#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target }, &block)
|
21
24
|
else
|
@@ -30,20 +33,22 @@ module DynamicFieldsForHelper
|
|
30
33
|
link = []
|
31
34
|
link << fields.hidden_field(:_destroy) unless fields.object.new_record?
|
32
35
|
css_classes = css_classes(DynamicFieldsForRails.delete_css_classes, css_classes)
|
36
|
+
|
33
37
|
link << if block_given?
|
34
38
|
link_to('#', class: css_classes, title: name, &block)
|
35
39
|
else
|
36
40
|
link_to(name, '#', class: css_classes)
|
37
41
|
end
|
42
|
+
|
43
|
+
# rubocop:disable Rails/OutputSafety
|
38
44
|
link.join('').html_safe
|
45
|
+
# rubocop:enable Rails/OutputSafety
|
39
46
|
end
|
40
47
|
|
41
|
-
protected
|
42
|
-
|
43
|
-
def css_classes(default, css_class)
|
48
|
+
protected def css_classes(default, css_class)
|
44
49
|
style_class = []
|
45
|
-
style_class << default
|
46
|
-
style_class << css_class
|
50
|
+
style_class << default if default.present?
|
51
|
+
style_class << css_class if css_class.present?
|
47
52
|
style_class.join(' ')
|
48
53
|
end
|
49
54
|
end
|
@@ -1,27 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'dynamic_fields_for_rails/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'dynamic_fields_for_rails'
|
8
9
|
spec.version = DynamicFieldsForRails::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Marten Klitzke']
|
11
|
+
spec.email = ['m.klitzke@gmail.com']
|
11
12
|
spec.description = 'Dynamic fields helper for Rails.'
|
12
13
|
spec.summary = 'Helper for nested forms with dynamic fields.'
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/mortik/dynamic_fields_for_rails'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
20
21
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'mocha', '~> 1'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12'
|
25
|
+
spec.add_development_dependency 'sqlite3', '~> 1'
|
25
26
|
|
26
|
-
spec.add_dependency
|
27
|
+
spec.add_dependency 'rails', '>= 3.0.0', '< 6.0.0'
|
27
28
|
end
|
@@ -1,16 +1,20 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'dynamic_fields_for_rails/version'
|
4
|
+
|
5
|
+
# rubocop:disable Style/ClassVars
|
3
6
|
module DynamicFieldsForRails
|
4
7
|
class Engine < Rails::Engine
|
5
8
|
end
|
6
9
|
|
7
10
|
mattr_accessor :add_css_classes
|
8
|
-
@@add_css_classes =
|
11
|
+
@@add_css_classes = 'add_fields'
|
9
12
|
|
10
13
|
mattr_accessor :delete_css_classes
|
11
|
-
@@delete_css_classes =
|
14
|
+
@@delete_css_classes = 'remove_fields'
|
12
15
|
|
13
16
|
def self.setup
|
14
17
|
yield self
|
15
18
|
end
|
16
19
|
end
|
20
|
+
# rubocop:enable Style/ClassVars
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# rubocop:disable ClassAndModuleChildren
|
4
|
+
# rubocop:disable Style/ClassVars
|
2
5
|
class ActiveRecord::Base
|
3
6
|
mattr_accessor :shared_connection
|
4
7
|
@@shared_connection = nil
|
@@ -7,4 +10,6 @@ class ActiveRecord::Base
|
|
7
10
|
@@shared_connection || retrieve_connection
|
8
11
|
end
|
9
12
|
end
|
13
|
+
# rubocop:enable Style/ClassVars
|
14
|
+
# rubocop:enable ClassAndModuleChildren
|
10
15
|
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
data/test/dummy/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
4
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
5
|
|
4
|
-
require File.expand_path('
|
6
|
+
require File.expand_path('config/application', __dir__)
|
5
7
|
require 'rake'
|
6
8
|
|
7
9
|
Dummy::Application.load_tasks
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require File.expand_path('boot', __dir__)
|
4
|
+
|
5
|
+
require 'rails/all'
|
4
6
|
|
5
7
|
Bundler.require
|
6
|
-
require
|
8
|
+
require 'dynamic_fields_for_rails'
|
7
9
|
|
8
10
|
module Dummy
|
9
11
|
class Application < Rails::Application
|
@@ -33,9 +35,11 @@ module Dummy
|
|
33
35
|
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
34
36
|
|
35
37
|
# Configure the default encoding used in templates for Ruby 1.9.
|
36
|
-
config.encoding =
|
38
|
+
config.encoding = 'utf-8'
|
37
39
|
|
38
40
|
# Configure sensitive parameters which will be filtered from the log file.
|
39
41
|
config.filter_parameters += [:password]
|
42
|
+
|
43
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true
|
40
44
|
end
|
41
45
|
end
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
|
-
gemfile = File.expand_path('
|
4
|
+
gemfile = File.expand_path('../../../Gemfile', __dir__)
|
3
5
|
|
4
6
|
if File.exist?(gemfile)
|
5
7
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -7,4 +9,4 @@ if File.exist?(gemfile)
|
|
7
9
|
Bundler.setup
|
8
10
|
end
|
9
11
|
|
10
|
-
$LOAD_PATH.unshift File.expand_path('
|
12
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Dummy::Application.configure do
|
2
4
|
# Settings specified here will take precedence over those in config/application.rb
|
3
5
|
|
@@ -11,7 +13,7 @@ Dummy::Application.configure do
|
|
11
13
|
config.action_controller.perform_caching = true
|
12
14
|
|
13
15
|
# Specifies the header that your server uses for sending files
|
14
|
-
config.action_dispatch.x_sendfile_header =
|
16
|
+
config.action_dispatch.x_sendfile_header = 'X-Sendfile'
|
15
17
|
|
16
18
|
# For nginx:
|
17
19
|
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Be sure to restart your server when you modify this file.
|
2
4
|
|
3
5
|
# Your secret key for verifying the integrity of signed cookies.
|
4
6
|
# If you change this key, all old signed cookies will become invalid!
|
5
7
|
# Make sure the secret is at least 30 characters and all random,
|
6
8
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
Dummy::Application.config.
|
8
|
-
Dummy::Application.config.secret_key_base = 'test_secret'
|
9
|
+
Dummy::Application.config.secret_key_base = '5d8d9599457d5f2fa50c978d19da955350fa36c215f514e6b572b9d1d843b844d477d70fe02eacec84742e0f252cf4d93339762e5d57fed7146063faad77a030'
|
data/test/dummy/config/routes.rb
CHANGED
data/test/dummy/config.ru
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# This file is auto-generated from the current state of the database. Instead
|
3
4
|
# of editing this file, please use the migrations feature of Active Record to
|
4
5
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -12,14 +13,14 @@
|
|
12
13
|
# It's strongly recommended to check this file into your version control system.
|
13
14
|
|
14
15
|
ActiveRecord::Schema.define(version: 20_130_423_140_307) do
|
15
|
-
create_table
|
16
|
-
t.integer
|
17
|
-
t.datetime
|
18
|
-
t.datetime
|
16
|
+
create_table 'children', force: true do |t|
|
17
|
+
t.integer 'parent_id'
|
18
|
+
t.datetime 'created_at', null: false
|
19
|
+
t.datetime 'updated_at', null: false
|
19
20
|
end
|
20
21
|
|
21
|
-
create_table
|
22
|
-
t.datetime
|
23
|
-
t.datetime
|
22
|
+
create_table 'parents', force: true do |t|
|
23
|
+
t.datetime 'created_at', null: false
|
24
|
+
t.datetime 'updated_at', null: false
|
24
25
|
end
|
25
26
|
end
|