vanilla_nested 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vanilla_nested/view_helpers.rb +14 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d47f68290b80623181ca454d3c30088e5c8178f6b7846b01affdbf07ec51e94
|
4
|
+
data.tar.gz: 20a430b78106da4df2220667b05b9ef0e14172768750b4e198b6642cf1689470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94bc333d6a5ba8949068ff25a77f76eb4073bd0fe91bffea4cae5fa9865edbaaa274ed98618b5c532898073673e7709bbb6dc9abadfe84c29259eace7bf16f05
|
7
|
+
data.tar.gz: 979c5c4f836a8dc4685723a3226864f8d0b8a11c5df08ed4a78a228afa7f1199e907adac3f45c8c99d8671937c4bd5fe8052a10f2f717cf462c14fc5a2ce6ccb
|
@@ -11,8 +11,9 @@ module VanillaNested
|
|
11
11
|
# @param partial_form_variable [String, Symbol] name of the variable that represents the form builder inside the fields partial
|
12
12
|
# @param tag [String] HTML tag to use for the html generated, defaults to and `a` tag
|
13
13
|
# @param link_content [Block] block of code for the link content
|
14
|
+
# @param tag_attributes [Hash<attribute, value>] hash with attribute,value pairs for the html tag
|
14
15
|
# @return [String] link tag
|
15
|
-
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form, tag: 'a', &link_content)
|
16
|
+
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form, tag: 'a', tag_attributes: {}, &link_content)
|
16
17
|
association_class = form.object.class.reflections[association.to_s].klass
|
17
18
|
object = association_class.new
|
18
19
|
|
@@ -36,7 +37,11 @@ module VanillaNested
|
|
36
37
|
nested_options = form.object.class.nested_attributes_options[association.to_sym]
|
37
38
|
data['limit'] = nested_options[:limit] if nested_options[:limit]
|
38
39
|
|
39
|
-
|
40
|
+
attributes = tag_attributes
|
41
|
+
attributes[:class] = "#{attributes.fetch(:class, '')} #{classes}"
|
42
|
+
attributes[:data] = attributes.fetch(:data, {}).merge(data)
|
43
|
+
|
44
|
+
content_tag(tag, attributes) do
|
40
45
|
if block_given?
|
41
46
|
yield link_content
|
42
47
|
else
|
@@ -54,8 +59,9 @@ module VanillaNested
|
|
54
59
|
# @param ulink_classes [String] space separated list of classes for the "x" link
|
55
60
|
# @param tag [String] HTML tag to use for the html generated, defaults to and `a` tag
|
56
61
|
# @param link_content [Block] block of code for the link content
|
62
|
+
# @param tag_attributes [Hash<attribute, value>] hash with attribute,value pairs for the html tag
|
57
63
|
# @return [String] hidden field and link tag
|
58
|
-
def link_to_remove_nested(form, link_text: 'X', fields_wrapper_selector: nil, undo_link_timeout: nil, undo_link_text: 'Undo', undo_link_classes: '', link_classes: '', tag: 'a', &link_content)
|
64
|
+
def link_to_remove_nested(form, link_text: 'X', fields_wrapper_selector: nil, undo_link_timeout: nil, undo_link_text: 'Undo', undo_link_classes: '', link_classes: '', tag: 'a', tag_attributes: {}, &link_content)
|
59
65
|
data = {
|
60
66
|
'fields-wrapper-selector': fields_wrapper_selector,
|
61
67
|
'undo-timeout': undo_link_timeout,
|
@@ -65,10 +71,14 @@ module VanillaNested
|
|
65
71
|
|
66
72
|
classes = "vanilla-nested-remove #{link_classes}"
|
67
73
|
|
74
|
+
attributes = tag_attributes
|
75
|
+
attributes[:class] = "#{attributes.fetch(:class, '')} #{classes}"
|
76
|
+
attributes[:data] = attributes.fetch(:data, {}).merge(data)
|
77
|
+
|
68
78
|
capture do
|
69
79
|
concat form.hidden_field(:_destroy, value: 0)
|
70
80
|
concat(
|
71
|
-
content_tag(tag,
|
81
|
+
content_tag(tag, attributes) do
|
72
82
|
if block_given?
|
73
83
|
yield link_content
|
74
84
|
else
|