simple_form_attachments 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1540e6d1e827ffdfacb5bf1fabb16add5326a15a
4
- data.tar.gz: be5daa41dee23d745418119e798407f4e88e7c5c
3
+ metadata.gz: a12fab48309e9d05e47affed9ba0634611420bbf
4
+ data.tar.gz: 05e4628edee4e1ba554512ea9b57f6a7d5ad4f44
5
5
  SHA512:
6
- metadata.gz: 3e57492026a7dc0e6bb79051ea58d642f77a4be62c5e5fb14477b812f05c3cb7d09b0f3e2961664008b6cf26eac1df906bed84b38516d9e716c6aafc032575b8
7
- data.tar.gz: d7081f1fb537c5be4c22165dd5671478d5e7b24617f7c200e71bed50aa1eee7dc36052c404d214ef720cf20e8172e5b775e338ec784222623aa71acd3a0df238
6
+ metadata.gz: d80eb51c12da9c051bec72e632189ff403cf7725081c1819d0292b744c69d7a3750067fd245321602f9c352bd38736cd8aa566374a32765db4ed8c65e5bf1302
7
+ data.tar.gz: 9648f1b70f24048f549088341aef1e437b130f5931ff9e275c2c0952fea8a7dddc95917dc6bdcb55629008383b695c303acceaea6c60e7379b3c0bcacd28f440
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_attachments (0.0.4)
4
+ simple_form_attachments (0.0.5)
5
5
  jquery-ui-rails
6
6
  rails (>= 4.2)
7
7
  rails-assets-blueimp-file-upload (>= 9.6.0)
@@ -50,7 +50,7 @@ GEM
50
50
  tzinfo (~> 1.1)
51
51
  addressable (2.3.8)
52
52
  arel (6.0.0)
53
- bson (3.1.1)
53
+ bson (3.1.2)
54
54
  builder (3.2.2)
55
55
  coderay (1.1.0)
56
56
  connection_pool (2.2.0)
@@ -69,11 +69,11 @@ GEM
69
69
  multi_json (~> 1.0)
70
70
  rack (>= 1.3.0)
71
71
  erubis (2.7.0)
72
- ffi (1.9.9)
72
+ ffi (1.9.10)
73
73
  formatador (0.2.5)
74
74
  globalid (0.3.5)
75
75
  activesupport (>= 4.1.0)
76
- guard (2.12.7)
76
+ guard (2.12.8)
77
77
  formatador (>= 0.2.4)
78
78
  listen (>= 2.7, <= 4.0)
79
79
  lumberjack (~> 1.0)
@@ -92,7 +92,7 @@ GEM
92
92
  jquery-ui-rails (5.0.5)
93
93
  railties (>= 3.2.16)
94
94
  json (1.8.3)
95
- listen (3.0.0)
95
+ listen (3.0.1)
96
96
  rb-fsevent (>= 0.9.3)
97
97
  rb-inotify (>= 0.9)
98
98
  loofah (2.0.2)
@@ -116,7 +116,7 @@ GEM
116
116
  bson (~> 3.0)
117
117
  connection_pool (~> 2.0)
118
118
  optionable (~> 0.2.0)
119
- multi_json (1.11.1)
119
+ multi_json (1.11.2)
120
120
  nenv (0.2.0)
121
121
  netrc (0.10.3)
122
122
  nokogiri (1.6.6.2)
@@ -145,7 +145,7 @@ GEM
145
145
  railties (= 4.2.3)
146
146
  sprockets-rails
147
147
  rails-assets-blueimp-canvas-to-blob (2.1.1)
148
- rails-assets-blueimp-file-upload (9.10.1)
148
+ rails-assets-blueimp-file-upload (9.10.3)
149
149
  rails-assets-blueimp-canvas-to-blob (>= 2.1.1)
150
150
  rails-assets-blueimp-load-image (>= 1.13.0)
151
151
  rails-assets-blueimp-tmpl (>= 2.5.4)
data/README.md CHANGED
@@ -96,7 +96,7 @@ validates :attachment_pdfs, length: { maximum: 2 }
96
96
  Mount the engine in your routes:
97
97
 
98
98
  ```ruby
99
- mount SimpleFormAttachments::Engine => "/"
99
+ mount SimpleFormAttachments::Engine => "/"
100
100
  ```
101
101
 
102
102
  This will include a default `/attachments` route.
@@ -145,7 +145,6 @@ td.file_info
145
145
  = fields.input :caption
146
146
  ```
147
147
 
148
-
149
148
  #### Validation errors
150
149
 
151
150
  If you want to show validation errors in your partial, simply include the `simple_form_attachments/errors` partial as shown above.
@@ -23,6 +23,7 @@ module SimpleFormAttachments
23
23
  def partial_locals
24
24
  {
25
25
  parent: parent,
26
+ parent_name: parent_name,
26
27
  parent_class: parent_class,
27
28
  child_index: child_index,
28
29
  attachment: attachment,
@@ -35,6 +36,10 @@ module SimpleFormAttachments
35
36
  params.require(:attachment).permit!
36
37
  end
37
38
 
39
+ def parent_name
40
+ params[:attachment_parent][:name]
41
+ end
42
+
38
43
  def attachment_class
39
44
  params[:attachment_type].constantize
40
45
  end
@@ -1,4 +1,4 @@
1
- - form = ActionView::Helpers::FormBuilder.new(parent_class.model_name.param_key, parent, self, {})
1
+ - form = ActionView::Helpers::FormBuilder.new(parent_name, parent, self, {})
2
2
 
3
3
  = form.simple_fields_for attachment_relation[:name].to_sym, attachment, { child_index: child_index } do |fields|
4
4
  - partial_locals = { attachment: attachment, form: form, fields: fields, multiple: multiple, relation_key: attachment_relation[:key] }
@@ -43,6 +43,7 @@
43
43
  dropZone: @$element
44
44
  formData: {
45
45
  'attachment_type]': @get_attachment_type_input().val(),
46
+ 'attachment_parent[name]': @get_attachment_parent_name_input().val(),
46
47
  'attachment_parent[class]': @get_attachment_parent_class_input().val(),
47
48
  'attachment_relation[type]': @get_attachment_relation_type_input().val(),
48
49
  'attachment_relation[key]': @get_attachment_relation_key_input().val(),
@@ -147,6 +148,8 @@
147
148
  @$element.find('input[name="attachment[multiple]"]')
148
149
  get_attachment_parent_class_input: ->
149
150
  @$element.find('input[name="attachment_parent[class]"]')
151
+ get_attachment_parent_name_input: ->
152
+ @$element.find('input[name="attachment_parent[name]"]')
150
153
  get_attachment_relation_key_input: ->
151
154
  @$element.find('input[name="attachment_relation[key]"]')
152
155
  get_attachment_relation_name_input: ->
@@ -21,10 +21,12 @@ module SimpleFormAttachments
21
21
 
22
22
  def input wrapper_options
23
23
  template.content_tag :div, merge_wrapper_options(input_html_options, wrapper_options) do
24
+ template.concat attachment_blank_field
24
25
  template.concat attachment_file_field
25
26
  template.concat attachment_type_field
26
27
  template.concat attachment_multiple_field
27
28
  template.concat attachment_parent_class_field
29
+ template.concat attachment_parent_name_field
28
30
  template.concat attachment_relation_key_field
29
31
  template.concat attachment_relation_name_field
30
32
  template.concat attachment_relation_class_field
@@ -81,6 +83,10 @@ module SimpleFormAttachments
81
83
  @builder.object.class.name
82
84
  end
83
85
 
86
+ def parent_name
87
+ @builder.object_name
88
+ end
89
+
84
90
  def relation_class
85
91
  relation.relation.to_s
86
92
  end
@@ -162,6 +168,10 @@ module SimpleFormAttachments
162
168
 
163
169
  # ---------------------------------------------------------------------
164
170
 
171
+ def attachment_blank_field
172
+ template.hidden_field_tag("#{parent_name}[#{relation_key}][]", nil)
173
+ end
174
+
165
175
  def attachment_file_field
166
176
  input_html_options = {
167
177
  multiple: multiple?,
@@ -185,6 +195,10 @@ module SimpleFormAttachments
185
195
  template.hidden_field_tag('attachment_parent[class]', parent_class)
186
196
  end
187
197
 
198
+ def attachment_parent_name_field
199
+ template.hidden_field_tag('attachment_parent[name]', parent_name)
200
+ end
201
+
188
202
  def attachment_relation_name_field
189
203
  template.hidden_field_tag('attachment_relation[name]', @attribute_name)
190
204
  end
@@ -208,7 +222,7 @@ module SimpleFormAttachments
208
222
  table_classes << 'sortable' if sortable?
209
223
  template.content_tag :table, class: table_classes do
210
224
  @builder.simple_fields_for attribute_name do |attachment_fields|
211
- template.render partial: attachment_fields.object.to_partial_path, format: :html, layout: 'layouts/simple_form_attachments/attachment_layout',
225
+ template.render partial: "simple_form_attachments/#{attachment_fields.object.to_partial_path}", format: :html, layout: 'layouts/simple_form_attachments/attachment_layout',
212
226
  locals: {
213
227
  attachment: attachment_fields.object,
214
228
  fields: attachment_fields,
@@ -1,3 +1,3 @@
1
1
  module SimpleFormAttachments
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_attachments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2015-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -280,7 +280,6 @@ files:
280
280
  - test/dummy/app/models/attachment_image.rb
281
281
  - test/dummy/app/models/concerns/.keep
282
282
  - test/dummy/app/models/test.rb
283
- - test/dummy/app/views/attachment_images/_attachment_image.html.slim
284
283
  - test/dummy/app/views/layouts/application.html.erb
285
284
  - test/dummy/app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim
286
285
  - test/dummy/app/views/tests/_form.html.slim
@@ -418,7 +417,6 @@ test_files:
418
417
  - test/dummy/app/models/attachment_image.rb
419
418
  - test/dummy/app/models/concerns/.keep
420
419
  - test/dummy/app/models/test.rb
421
- - test/dummy/app/views/attachment_images/_attachment_image.html.slim
422
420
  - test/dummy/app/views/layouts/application.html.erb
423
421
  - test/dummy/app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim
424
422
  - test/dummy/app/views/tests/_form.html.slim
@@ -1,15 +0,0 @@
1
- td.thumb
2
- div.thumb
3
- = image_tag attachment.thumb_url, alt: attachment.file_name
4
-
5
- td.file_info
6
- = link_to attachment.file_name, attachment.file.url
7
- span.mime_type = attachment.file_mime_type
8
- span.size = attachment.file_size
9
-
10
- - if attachment.errors.to_a.any?
11
- td.errors = render 'simple_form_attachments/errors', errors: attachment.errors.to_a
12
-
13
- - else
14
- td.fields
15
- = fields.input :caption