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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca0695302433ce2ff7b48e7673894ca698034f0cfffe9eeb822eb1e47b78943b
4
- data.tar.gz: 9db10e3cba8445ab747f8c360403518e8bcfb4c296b1dc7aaab0bdbc629ed980
3
+ metadata.gz: 0d47f68290b80623181ca454d3c30088e5c8178f6b7846b01affdbf07ec51e94
4
+ data.tar.gz: 20a430b78106da4df2220667b05b9ef0e14172768750b4e198b6642cf1689470
5
5
  SHA512:
6
- metadata.gz: 55c3480096e5d17f8a2a0c14ae3f1c976e3b081177a6ff51b3d8c4da3dbfd1d5af2caa720ff6c6c546c51a379a0adbc385d0f16d798532e0377bd26d3a1486f2
7
- data.tar.gz: 4f64f3dcad06add84d899ac23415ca18489b1f2fe22c8ea57862aae7278c24eb82e056327cf7877fb7c5406ec42e57f2b83c9b49408200a626eef7c41b33a56e
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
- content_tag(tag, class: classes, data: data) do
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, class: classes, data: data) do
81
+ content_tag(tag, attributes) do
72
82
  if block_given?
73
83
  yield link_content
74
84
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla_nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Juodziukynas <arieljuod@gmail.com>