dynamic_scaffold 1.7.0 → 1.9.0
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 +4 -4
- data/README.md +9 -0
- data/app/views/dynamic_scaffold/bootstrap/form/_row.html.erb +7 -1
- data/lib/dynamic_scaffold.rb +8 -2
- data/lib/dynamic_scaffold/controller.rb +4 -1
- data/lib/dynamic_scaffold/form/item/base.rb +14 -2
- data/lib/dynamic_scaffold/form/item/block.rb +2 -2
- data/lib/dynamic_scaffold/form/item/cocoon.rb +1 -0
- data/lib/dynamic_scaffold/form/item/json_object.rb +32 -0
- data/lib/dynamic_scaffold/form/item/single_option.rb +2 -2
- data/lib/dynamic_scaffold/form/item/two_options.rb +2 -2
- data/lib/dynamic_scaffold/form/item/two_options_with_block.rb +2 -2
- data/lib/dynamic_scaffold/form/item/type.rb +3 -1
- data/lib/dynamic_scaffold/form_builder.rb +6 -1
- data/lib/dynamic_scaffold/json_object/attribute.rb +24 -0
- data/lib/dynamic_scaffold/json_object/model.rb +18 -0
- data/lib/dynamic_scaffold/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d0ca43e5c5f7d3eac65d3ecb58f9c8db1c5fc56c16afa34ecd09dd5d04ee4e4
|
4
|
+
data.tar.gz: ef7f572241d232e3579d991d501e49da461baac0297598014b1f145cca959c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5df70910ffc6358f63638bd48748910176a889a89ca0ec9667c01aa37a4e3bd97a2981e3915b4efc2a6542a134bb12b7892271a7e438ebd3eb8078bb9d8cf59
|
7
|
+
data.tar.gz: bcf91e27f537462fe3f9417f0230c21d95c76fb1e13db923121951f6001437d3b328aaf303c2b60c6d1ca0b86c8f96e418851ad7994f5addba7fbdfc3b301169
|
data/README.md
CHANGED
@@ -253,6 +253,9 @@ class ShopController < ApplicationController
|
|
253
253
|
config.form.item(:collection_check_boxes, :state_ids, State.all, :id, :name)
|
254
254
|
config.form.item(:collection_radio_buttons, :status, Shop.statuses.map{|k, _v| [k, k.titleize]}, :first, :last)
|
255
255
|
|
256
|
+
# If you want to use parameters to get list, Pass Proc or Lambda to argument. It will be called in view scope.
|
257
|
+
config.form.item(:collection_select, :status, -> { Shop.where(area_id: params[:area_id]) }, :first, :last)
|
258
|
+
|
256
259
|
# If you want to display more free form field, use block.
|
257
260
|
# The block is executed in the context of view, so you can call the method of view.
|
258
261
|
config.form.item :block, :free do |form, field|
|
@@ -364,6 +367,12 @@ We support [cocoon](https://github.com/nathanvda/cocoon).
|
|
364
367
|
end
|
365
368
|
```
|
366
369
|
|
370
|
+
##### json_object
|
371
|
+
|
372
|
+
You can save json object string in a column using each form items and validations.
|
373
|
+
Check this [wiki](https://github.com/gomo/dynamic_scaffold/wiki/Handling-json-object-string-column)
|
374
|
+
|
375
|
+
|
367
376
|
#### Overwrite actions
|
368
377
|
|
369
378
|
You can pass the block to super in index/create/update actions.
|
@@ -68,7 +68,7 @@
|
|
68
68
|
<%end%>
|
69
69
|
<% end %>
|
70
70
|
<% elsif elem.type? :cocoon %>
|
71
|
-
<%= form.fields_for
|
71
|
+
<%= form.fields_for(elem.name, elem.build_children(@record)) do |child_form| %>
|
72
72
|
<%= render 'dynamic_scaffold/bootstrap/form/cocoon', f: child_form, items: elem.form.items, depth: depth %>
|
73
73
|
<% end %>
|
74
74
|
<%= link_to_add_association(
|
@@ -86,6 +86,12 @@
|
|
86
86
|
.gsub(/ : /, '<span class="mr-2" style="display: inline-block;">:</span>')
|
87
87
|
%>
|
88
88
|
</div>
|
89
|
+
<% elsif elem.type?(:json_object) %>
|
90
|
+
<%= form.fields_for(elem.name, @record.public_send(elem.name)) do |child_form| %>
|
91
|
+
<%- elem.form.items.each do |child_elem|-%>
|
92
|
+
<%= render 'dynamic_scaffold/bootstrap/form/row', form: child_form, elem: child_elem, depth: depth %>
|
93
|
+
<% end %>
|
94
|
+
<% end %>
|
89
95
|
<% else %>
|
90
96
|
<%= elem.render(self, form, class_names('form-control', {'is-invalid': errors.present?})) %>
|
91
97
|
<% end %>
|
data/lib/dynamic_scaffold.rb
CHANGED
@@ -32,8 +32,14 @@ module DynamicScaffold
|
|
32
32
|
autoload :SingleOption, 'dynamic_scaffold/form/item/single_option'
|
33
33
|
autoload :TwoOptionsWithBlock, 'dynamic_scaffold/form/item/two_options_with_block'
|
34
34
|
autoload :TwoOptions, 'dynamic_scaffold/form/item/two_options'
|
35
|
-
autoload :GlobalizeFields,
|
36
|
-
autoload :Cocoon,
|
35
|
+
autoload :GlobalizeFields, 'dynamic_scaffold/form/item/globalize_fields'
|
36
|
+
autoload :Cocoon, 'dynamic_scaffold/form/item/cocoon'
|
37
|
+
autoload :JSONObject, 'dynamic_scaffold/form/item/json_object'
|
37
38
|
end
|
38
39
|
end
|
40
|
+
|
41
|
+
module JSONObject
|
42
|
+
autoload :Attribute, 'dynamic_scaffold/json_object/attribute'
|
43
|
+
autoload :Model, 'dynamic_scaffold/json_object/model'
|
44
|
+
end
|
39
45
|
end
|
@@ -77,7 +77,7 @@ module DynamicScaffold
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
def update # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
80
|
+
def update # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
81
81
|
values = update_values
|
82
82
|
@record = find_record(dynamic_scaffold.model.primary_key => params['id'])
|
83
83
|
datetime_select_keys = []
|
@@ -93,6 +93,9 @@ module DynamicScaffold
|
|
93
93
|
# globalize
|
94
94
|
next [:translations_attributes, @record.translations] if k == 'translations_attributes'
|
95
95
|
|
96
|
+
# skip nested_attributes
|
97
|
+
next unless @record.respond_to? k
|
98
|
+
|
96
99
|
[k, @record.public_send(k)]
|
97
100
|
end.compact.to_h.with_indifferent_access
|
98
101
|
|
@@ -15,7 +15,8 @@ module DynamicScaffold
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
attr_accessor :parent_item
|
19
|
+
attr_reader :name, :multiple
|
19
20
|
def initialize(config, type, name, html_attributes = {})
|
20
21
|
@config = config
|
21
22
|
@name = name
|
@@ -32,7 +33,10 @@ module DynamicScaffold
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def unique_name
|
35
|
-
|
36
|
+
results = [@config.model.table_name]
|
37
|
+
results << parent_item.name if parent_item.present?
|
38
|
+
results << name
|
39
|
+
results.join('_')
|
36
40
|
end
|
37
41
|
|
38
42
|
def notes?
|
@@ -180,6 +184,14 @@ module DynamicScaffold
|
|
180
184
|
options[:class] = classnames_list.join(' ') unless classnames_list.empty?
|
181
185
|
options
|
182
186
|
end
|
187
|
+
|
188
|
+
def build_args(view, args)
|
189
|
+
args.map do |arg|
|
190
|
+
next arg unless arg.is_a? Proc
|
191
|
+
|
192
|
+
view.instance_exec(&arg)
|
193
|
+
end
|
194
|
+
end
|
183
195
|
end
|
184
196
|
end
|
185
197
|
end
|
@@ -2,8 +2,8 @@ module DynamicScaffold
|
|
2
2
|
module Form
|
3
3
|
module Item
|
4
4
|
class Block < Base
|
5
|
-
def initialize(config, type, name, &block)
|
6
|
-
super(config, type, name,
|
5
|
+
def initialize(config, type, name, options = {}, &block)
|
6
|
+
super(config, type, name, options)
|
7
7
|
@block = block
|
8
8
|
end
|
9
9
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module Form
|
3
|
+
module Item
|
4
|
+
class JSONObject < Base
|
5
|
+
attr_reader :form
|
6
|
+
def initialize(config, type, name, options = {})
|
7
|
+
super
|
8
|
+
@options = options
|
9
|
+
@form = FormBuilder.new(config)
|
10
|
+
@form.parent_item = self
|
11
|
+
yield(@form)
|
12
|
+
end
|
13
|
+
|
14
|
+
# the lable is always empty.
|
15
|
+
def render_label(_view, _depth)
|
16
|
+
''
|
17
|
+
end
|
18
|
+
|
19
|
+
def extract_parameters(permitting)
|
20
|
+
hash = permitting.find {|e| e.is_a?(Hash) && e.key?(name) }
|
21
|
+
if hash.nil?
|
22
|
+
hash = {}
|
23
|
+
hash[name] = form.items.map(&:name)
|
24
|
+
permitting << hash
|
25
|
+
else
|
26
|
+
hash[name].concat(form.items.map(&:name))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -9,11 +9,11 @@ module DynamicScaffold
|
|
9
9
|
super(config, type, name, html_attributes)
|
10
10
|
end
|
11
11
|
|
12
|
-
def render(
|
12
|
+
def render(view, form, classnames = nil)
|
13
13
|
html_attributes = build_html_attributes(classnames)
|
14
14
|
# Retain the value of the password field on error.
|
15
15
|
html_attributes[:value] = form.object.public_send(@name) if @type == :password_field
|
16
|
-
form.public_send(@type, @name,
|
16
|
+
form.public_send(@type, @name, *build_args(view, @args), html_attributes)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -18,9 +18,9 @@ module DynamicScaffold
|
|
18
18
|
super(config, type, name, html_attributes)
|
19
19
|
end
|
20
20
|
|
21
|
-
def render(
|
21
|
+
def render(view, form, classnames = nil)
|
22
22
|
html_attributes = build_html_attributes(classnames)
|
23
|
-
form.public_send(@type, @name,
|
23
|
+
form.public_send(@type, @name, *build_args(view, @args), @options, html_attributes)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -2,11 +2,11 @@ module DynamicScaffold
|
|
2
2
|
module Form
|
3
3
|
module Item
|
4
4
|
class TwoOptionsWithBlock < TwoOptions
|
5
|
-
def render(
|
5
|
+
def render(view, form, classnames = nil)
|
6
6
|
form.public_send(
|
7
7
|
@type,
|
8
8
|
@name,
|
9
|
-
|
9
|
+
*build_args(view, @args),
|
10
10
|
@options,
|
11
11
|
build_html_attributes(classnames)
|
12
12
|
) do |builder|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module DynamicScaffold
|
2
2
|
class FormBuilder
|
3
|
+
attr_accessor :parent_item
|
4
|
+
|
3
5
|
def initialize(config)
|
4
6
|
@config = config
|
5
7
|
@items = []
|
@@ -11,7 +13,9 @@ module DynamicScaffold
|
|
11
13
|
@config.model.column_names.each do |column|
|
12
14
|
type = :text_field
|
13
15
|
type = :hidden_field if @config.scope && @config.scope.include?(column.to_sym)
|
14
|
-
|
16
|
+
item = Form::Item::SingleOption.new(@config, type, column)
|
17
|
+
item.parent_item = parent_item
|
18
|
+
@items << item
|
15
19
|
end
|
16
20
|
end
|
17
21
|
@items
|
@@ -28,6 +32,7 @@ module DynamicScaffold
|
|
28
32
|
|
29
33
|
def item(type, *args, &block)
|
30
34
|
item = Form::Item::Base.create(@config, type, *args, &block)
|
35
|
+
item.parent_item = parent_item
|
31
36
|
@items << item
|
32
37
|
item
|
33
38
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module JSONObject
|
3
|
+
module Attribute
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
@json_object_attribute_names ||= []
|
8
|
+
|
9
|
+
define_method :valid? do |context = nil|
|
10
|
+
result = super(context)
|
11
|
+
json_object_attribute_names = self.class.instance_variable_get(:@json_object_attribute_names)
|
12
|
+
json_object_attribute_names.all? {|method| public_send(method).valid?(context) } && result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def json_object_attributte(attribute_name, model)
|
18
|
+
@json_object_attribute_names << attribute_name
|
19
|
+
serialize attribute_name, model
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module JSONObject
|
3
|
+
module Model
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def dump(obj)
|
8
|
+
obj = obj.attributes if obj.is_a? ActiveModel::Attributes
|
9
|
+
obj.to_json if obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(source)
|
13
|
+
new(source ? JSON.parse(source) : {})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masamoto Miyata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: classnames-rails-view
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: '5.0'
|
48
48
|
- - "<="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '6.
|
50
|
+
version: '6.1'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: '5.0'
|
58
58
|
- - "<="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '6.
|
60
|
+
version: '6.1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: capybara
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -295,12 +295,15 @@ files:
|
|
295
295
|
- lib/dynamic_scaffold/form/item/carrier_wave_image.rb
|
296
296
|
- lib/dynamic_scaffold/form/item/cocoon.rb
|
297
297
|
- lib/dynamic_scaffold/form/item/globalize_fields.rb
|
298
|
+
- lib/dynamic_scaffold/form/item/json_object.rb
|
298
299
|
- lib/dynamic_scaffold/form/item/single_option.rb
|
299
300
|
- lib/dynamic_scaffold/form/item/two_options.rb
|
300
301
|
- lib/dynamic_scaffold/form/item/two_options_with_block.rb
|
301
302
|
- lib/dynamic_scaffold/form/item/type.rb
|
302
303
|
- lib/dynamic_scaffold/form_builder.rb
|
303
304
|
- lib/dynamic_scaffold/icons/fontawesome.rb
|
305
|
+
- lib/dynamic_scaffold/json_object/attribute.rb
|
306
|
+
- lib/dynamic_scaffold/json_object/model.rb
|
304
307
|
- lib/dynamic_scaffold/list/item.rb
|
305
308
|
- lib/dynamic_scaffold/list/pagination.rb
|
306
309
|
- lib/dynamic_scaffold/list_builder.rb
|