simple_form_attachments 0.2.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +118 -113
  5. data/README.md +29 -14
  6. data/app/controllers/simple_form_attachments/upload_controller.rb +3 -1
  7. data/app/models/concerns/simple_form_attachments/attachment.rb +1 -1
  8. data/app/models/concerns/simple_form_attachments/has_attachments.rb +11 -8
  9. data/app/views/layouts/simple_form_attachments/_attachment_layout.html.slim +8 -8
  10. data/app/views/simple_form_attachments/_errors.html.slim +4 -3
  11. data/app/views/simple_form_attachments/attachments/_attachment.hbs.slim +14 -15
  12. data/app/views/simple_form_attachments/attachments/_attachment.html.slim +4 -2
  13. data/config/locales/simple_form_attachments/simple_form_attachments.en.yml +8 -3
  14. data/config/routes.rb +2 -2
  15. data/lib/assets/javascripts/simple_form_attachments/{simple_form_attachments.js.coffee → simple_form_attachments.coffee.erb} +24 -41
  16. data/lib/assets/stylesheets/simple_form_attachments/__attachment.scss.erb +8 -0
  17. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col.scss.erb +1 -0
  18. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__actions.scss.erb +3 -0
  19. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__errors.scss.erb +10 -0
  20. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__fields.scss.erb +4 -0
  21. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__file_info.scss.erb +4 -0
  22. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__handle.scss.erb +6 -0
  23. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__hidden.scss.erb +3 -0
  24. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__progress.scss.erb +14 -0
  25. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__thumb.scss.erb +9 -0
  26. data/lib/assets/stylesheets/simple_form_attachments/__attachment_list.scss.erb +11 -0
  27. data/lib/assets/stylesheets/simple_form_attachments/__button.scss.erb +9 -0
  28. data/lib/assets/stylesheets/simple_form_attachments/__label.scss.erb +3 -0
  29. data/lib/assets/stylesheets/simple_form_attachments/simple_form_attachments.scss.erb +29 -0
  30. data/lib/assets/stylesheets/simple_form_attachments.css +4 -0
  31. data/lib/simple_form_attachments/attachment_input.rb +12 -11
  32. data/lib/simple_form_attachments/version.rb +1 -1
  33. data/lib/simple_form_attachments.rb +12 -0
  34. data/simple_form_attachments.gemspec +2 -1
  35. data/test/controllers/simple_form_attachments/upload_controller_test.rb +53 -57
  36. data/test/dummy/Gemfile +1 -0
  37. data/test/dummy/Gemfile.lock +80 -74
  38. data/test/dummy/app/assets/stylesheets/application.css +5 -0
  39. data/test/dummy/app/models/attachment_image.rb +1 -0
  40. data/test/dummy/app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim +12 -9
  41. data/test/dummy/config/environments/test.rb +2 -2
  42. data/test/dummy/config/mongoid.yml +5 -8
  43. data/test/dummy/config/routes.rb +1 -3
  44. data/test/simple_form_attachments_test.rb +30 -0
  45. data/test/test_helper.rb +5 -1
  46. metadata +46 -16
  47. data/test/dummy/app/assets/stylesheets/application.css.scss +0 -5
  48. data/test/dummy/app/assets/stylesheets/tests.scss +0 -233
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee4c708e8de9ee3b379ebed06b02e1ee276536f8
4
- data.tar.gz: 9624ab7be6b0a93e2a11feb8b22205e1b698f6af
3
+ metadata.gz: 32937e7bfd5b986371b84849e0978f6351f1483c
4
+ data.tar.gz: 90721d27ee39824d4f6aeb3f6a8d32f84d15980a
5
5
  SHA512:
6
- metadata.gz: 69dae6c84f549224206c4b41f96ccf75a9b42340057ad19af509076233c91f652532084d976fdd06b20d3e54a7f5eb6f61f8157348b11647a67e45b772a614a1
7
- data.tar.gz: 3444e12acc217efb705b8c5881020f0a87af37794f932df9bb819372f457fc8e6679c3374719b2bb41365a199fc64946bf5afa8e58cc0f10a824b99d28a2dc80
6
+ metadata.gz: 4faa06b6077c22c05011becf23da50daaaea0bc926097b8d3a2b13527050e538cb6d4c15d2a641fae850ff112b3d8000955e889abdf4bbf4934c3e263a9b0a8b
7
+ data.tar.gz: b23ec5127609dd3b41a45c386e99ea12d24dddbab5a67f294d84e31d35eb4ade677ea83d8b56f950f6d8ca2522ecb4d5324e82ce8debda28f3b63ac99fdc3896
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0
4
+
5
+ * css classes scoped in the `simple_form_attachments` namespace
6
+ * markup changed from `table` to `div` for more flexibility
data/Gemfile CHANGED
@@ -3,3 +3,5 @@ source 'https://rails-assets.org'
3
3
 
4
4
  # Specify your gem's dependencies in simple_form_epic_editor.gemspec
5
5
  gemspec
6
+
7
+ gem 'rb-readline'
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_attachments (0.2.6)
4
+ simple_form_attachments (1.0.0)
5
5
  jquery-ui-rails
6
+ mongoid (> 4.0)
6
7
  rails (>= 4.2)
7
8
  rails-assets-blueimp-file-upload (>= 9.6.0)
8
9
  rails-assets-handlebars
@@ -13,66 +14,68 @@ GEM
13
14
  remote: https://rubygems.org/
14
15
  remote: https://rails-assets.org/
15
16
  specs:
16
- actionmailer (4.2.7.1)
17
- actionpack (= 4.2.7.1)
18
- actionview (= 4.2.7.1)
19
- activejob (= 4.2.7.1)
17
+ actioncable (5.1.1)
18
+ actionpack (= 5.1.1)
19
+ nio4r (~> 2.0)
20
+ websocket-driver (~> 0.6.1)
21
+ actionmailer (5.1.1)
22
+ actionpack (= 5.1.1)
23
+ actionview (= 5.1.1)
24
+ activejob (= 5.1.1)
20
25
  mail (~> 2.5, >= 2.5.4)
21
- rails-dom-testing (~> 1.0, >= 1.0.5)
22
- actionpack (4.2.7.1)
23
- actionview (= 4.2.7.1)
24
- activesupport (= 4.2.7.1)
25
- rack (~> 1.6)
26
- rack-test (~> 0.6.2)
27
- rails-dom-testing (~> 1.0, >= 1.0.5)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (5.1.1)
28
+ actionview (= 5.1.1)
29
+ activesupport (= 5.1.1)
30
+ rack (~> 2.0)
31
+ rack-test (~> 0.6.3)
32
+ rails-dom-testing (~> 2.0)
28
33
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (4.2.7.1)
30
- activesupport (= 4.2.7.1)
34
+ actionview (5.1.1)
35
+ activesupport (= 5.1.1)
31
36
  builder (~> 3.1)
32
- erubis (~> 2.7.0)
33
- rails-dom-testing (~> 1.0, >= 1.0.5)
34
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
35
- activejob (4.2.7.1)
36
- activesupport (= 4.2.7.1)
37
- globalid (>= 0.3.0)
38
- activemodel (4.2.7.1)
39
- activesupport (= 4.2.7.1)
40
- builder (~> 3.1)
41
- activerecord (4.2.7.1)
42
- activemodel (= 4.2.7.1)
43
- activesupport (= 4.2.7.1)
44
- arel (~> 6.0)
45
- activesupport (4.2.7.1)
37
+ erubi (~> 1.4)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
40
+ activejob (5.1.1)
41
+ activesupport (= 5.1.1)
42
+ globalid (>= 0.3.6)
43
+ activemodel (5.1.1)
44
+ activesupport (= 5.1.1)
45
+ activerecord (5.1.1)
46
+ activemodel (= 5.1.1)
47
+ activesupport (= 5.1.1)
48
+ arel (~> 8.0)
49
+ activesupport (5.1.1)
50
+ concurrent-ruby (~> 1.0, >= 1.0.2)
46
51
  i18n (~> 0.7)
47
- json (~> 1.7, >= 1.7.7)
48
52
  minitest (~> 5.1)
49
- thread_safe (~> 0.3, >= 0.3.4)
50
53
  tzinfo (~> 1.1)
51
- addressable (2.4.0)
52
- arel (6.0.4)
53
- bson (3.2.6)
54
- builder (3.2.2)
54
+ addressable (2.5.1)
55
+ public_suffix (~> 2.0, >= 2.0.2)
56
+ arel (8.0.0)
57
+ bson (4.2.1)
58
+ builder (3.2.3)
55
59
  coderay (1.1.1)
56
60
  concurrent-ruby (1.0.5)
57
- connection_pool (2.2.0)
58
- coveralls (0.8.15)
61
+ coveralls (0.8.21)
59
62
  json (>= 1.8, < 3)
60
- simplecov (~> 0.12.0)
63
+ simplecov (~> 0.14.1)
61
64
  term-ansicolor (~> 1.3)
62
- thor (~> 0.19.1)
63
- tins (>= 1.6.0, < 2)
64
- database_cleaner (1.5.3)
65
+ thor (~> 0.19.4)
66
+ tins (~> 1.6)
67
+ database_cleaner (1.6.1)
65
68
  docile (1.1.5)
66
- dragonfly (1.0.12)
69
+ dragonfly (1.1.3)
67
70
  addressable (~> 2.3)
68
71
  multi_json (~> 1.0)
69
- rack (>= 1.3.0)
70
- erubis (2.7.0)
71
- ffi (1.9.14)
72
+ rack (>= 1.3)
73
+ erubi (1.6.0)
74
+ ffi (1.9.18)
72
75
  formatador (0.2.5)
73
- globalid (0.3.7)
74
- activesupport (>= 4.1.0)
75
- guard (2.14.0)
76
+ globalid (0.4.0)
77
+ activesupport (>= 4.2.0)
78
+ guard (2.14.1)
76
79
  formatador (>= 0.2.4)
77
80
  listen (>= 2.7, < 4.0)
78
81
  lumberjack (~> 1.0)
@@ -85,105 +88,103 @@ GEM
85
88
  guard-minitest (2.4.6)
86
89
  guard-compat (~> 1.2)
87
90
  minitest (>= 3.0)
88
- i18n (0.7.0)
91
+ i18n (0.8.4)
89
92
  jquery-ui-rails (6.0.1)
90
93
  railties (>= 3.2.16)
91
- json (1.8.3)
94
+ json (2.1.0)
92
95
  listen (3.1.5)
93
96
  rb-fsevent (~> 0.9, >= 0.9.4)
94
97
  rb-inotify (~> 0.9, >= 0.9.7)
95
98
  ruby_dep (~> 1.2)
96
99
  loofah (2.0.3)
97
100
  nokogiri (>= 1.5.9)
98
- lumberjack (1.0.10)
99
- mail (2.6.4)
101
+ lumberjack (1.0.12)
102
+ mail (2.6.5)
100
103
  mime-types (>= 1.16, < 4)
101
104
  method_source (0.8.2)
102
105
  mime-types (3.1)
103
106
  mime-types-data (~> 3.2015)
104
107
  mime-types-data (3.2016.0521)
105
- mini_portile2 (2.1.0)
106
- minitest (5.9.0)
107
- minitest-rails (2.2.1)
108
- minitest (~> 5.7)
109
- railties (~> 4.1)
110
- mongoid (4.0.0)
111
- activemodel (~> 4.0)
112
- moped (~> 2.0.0)
113
- origin (~> 2.1)
114
- tzinfo (>= 0.3.37)
115
- moped (2.0.7)
116
- bson (~> 3.0)
117
- connection_pool (~> 2.0)
118
- optionable (~> 0.2.0)
108
+ mini_portile2 (2.2.0)
109
+ minitest (5.10.2)
110
+ minitest-rails (3.0.0)
111
+ minitest (~> 5.8)
112
+ railties (~> 5.0)
113
+ mongo (2.4.2)
114
+ bson (>= 4.2.1, < 5.0.0)
115
+ mongoid (6.2.0)
116
+ activemodel (~> 5.1)
117
+ mongo (>= 2.4.1, < 3.0.0)
119
118
  multi_json (1.12.1)
120
119
  nenv (0.3.0)
121
- nokogiri (1.6.8)
122
- mini_portile2 (~> 2.1.0)
123
- pkg-config (~> 1.1.7)
120
+ nio4r (2.1.0)
121
+ nokogiri (1.8.0)
122
+ mini_portile2 (~> 2.2.0)
124
123
  notiffany (0.1.1)
125
124
  nenv (~> 0.1)
126
125
  shellany (~> 0.0)
127
- optionable (0.2.0)
128
- origin (2.2.0)
129
- pkg-config (1.1.7)
130
126
  pry (0.10.4)
131
127
  coderay (~> 1.1.0)
132
128
  method_source (~> 0.8.1)
133
129
  slop (~> 3.4)
134
- rack (1.6.4)
130
+ public_suffix (2.0.5)
131
+ rack (2.0.3)
135
132
  rack-test (0.6.3)
136
133
  rack (>= 1.0)
137
- rails (4.2.7.1)
138
- actionmailer (= 4.2.7.1)
139
- actionpack (= 4.2.7.1)
140
- actionview (= 4.2.7.1)
141
- activejob (= 4.2.7.1)
142
- activemodel (= 4.2.7.1)
143
- activerecord (= 4.2.7.1)
144
- activesupport (= 4.2.7.1)
134
+ rails (5.1.1)
135
+ actioncable (= 5.1.1)
136
+ actionmailer (= 5.1.1)
137
+ actionpack (= 5.1.1)
138
+ actionview (= 5.1.1)
139
+ activejob (= 5.1.1)
140
+ activemodel (= 5.1.1)
141
+ activerecord (= 5.1.1)
142
+ activesupport (= 5.1.1)
145
143
  bundler (>= 1.3.0, < 2.0)
146
- railties (= 4.2.7.1)
147
- sprockets-rails
144
+ railties (= 5.1.1)
145
+ sprockets-rails (>= 2.0.0)
148
146
  rails-assets-blueimp-canvas-to-blob (3.7.0)
149
- rails-assets-blueimp-file-upload (9.17.0)
147
+ rails-assets-blueimp-file-upload (9.18.0)
150
148
  rails-assets-blueimp-canvas-to-blob (>= 2.1.1)
151
149
  rails-assets-blueimp-load-image (>= 1.13.0)
152
150
  rails-assets-blueimp-tmpl (>= 2.5.4)
153
151
  rails-assets-jquery (>= 1.6)
154
152
  rails-assets-blueimp-load-image (2.12.2)
155
153
  rails-assets-blueimp-tmpl (3.8.0)
156
- rails-assets-handlebars (4.0.5)
157
- rails-assets-jquery (3.1.1)
158
- rails-deprecated_sanitizer (1.0.3)
159
- activesupport (>= 4.2.0.alpha)
160
- rails-dom-testing (1.0.7)
161
- activesupport (>= 4.2.0.beta, < 5.0)
162
- nokogiri (~> 1.6.0)
163
- rails-deprecated_sanitizer (>= 1.0.1)
154
+ rails-assets-handlebars (4.0.10)
155
+ rails-assets-jquery (3.2.1)
156
+ rails-controller-testing (1.0.2)
157
+ actionpack (~> 5.x, >= 5.0.1)
158
+ actionview (~> 5.x, >= 5.0.1)
159
+ activesupport (~> 5.x)
160
+ rails-dom-testing (2.0.3)
161
+ activesupport (>= 4.2.0)
162
+ nokogiri (>= 1.6)
164
163
  rails-html-sanitizer (1.0.3)
165
164
  loofah (~> 2.0)
166
- railties (4.2.7.1)
167
- actionpack (= 4.2.7.1)
168
- activesupport (= 4.2.7.1)
165
+ railties (5.1.1)
166
+ actionpack (= 5.1.1)
167
+ activesupport (= 5.1.1)
168
+ method_source
169
169
  rake (>= 0.8.7)
170
170
  thor (>= 0.18.1, < 2.0)
171
171
  rake (10.5.0)
172
- rb-fsevent (0.9.7)
173
- rb-inotify (0.9.7)
172
+ rb-fsevent (0.9.8)
173
+ rb-inotify (0.9.8)
174
174
  ffi (>= 0.5.0)
175
- ruby_dep (1.4.0)
175
+ rb-readline (0.5.4)
176
+ ruby_dep (1.5.0)
176
177
  shellany (0.0.1)
177
- simple_form (3.4.0)
178
- actionpack (> 4, < 5.1)
179
- activemodel (> 4, < 5.1)
180
- simplecov (0.12.0)
178
+ simple_form (3.5.0)
179
+ actionpack (> 4, < 5.2)
180
+ activemodel (> 4, < 5.2)
181
+ simplecov (0.14.1)
181
182
  docile (~> 1.1.0)
182
183
  json (>= 1.8, < 3)
183
184
  simplecov-html (~> 0.10.0)
184
- simplecov-html (0.10.0)
185
- slim (3.0.7)
186
- temple (~> 0.7.6)
185
+ simplecov-html (0.10.1)
186
+ slim (3.0.8)
187
+ temple (>= 0.7.6, < 0.9)
187
188
  tilt (>= 1.3.3, < 2.1)
188
189
  slop (3.6.0)
189
190
  sprockets (3.7.1)
@@ -193,15 +194,18 @@ GEM
193
194
  actionpack (>= 4.0)
194
195
  activesupport (>= 4.0)
195
196
  sprockets (>= 3.0.0)
196
- temple (0.7.7)
197
- term-ansicolor (1.3.2)
197
+ temple (0.8.0)
198
+ term-ansicolor (1.6.0)
198
199
  tins (~> 1.0)
199
- thor (0.19.1)
200
- thread_safe (0.3.5)
201
- tilt (2.0.6)
202
- tins (1.12.0)
203
- tzinfo (1.2.2)
200
+ thor (0.19.4)
201
+ thread_safe (0.3.6)
202
+ tilt (2.0.7)
203
+ tins (1.14.0)
204
+ tzinfo (1.2.3)
204
205
  thread_safe (~> 0.1)
206
+ websocket-driver (0.6.5)
207
+ websocket-extensions (>= 0.1.0)
208
+ websocket-extensions (0.1.2)
205
209
 
206
210
  PLATFORMS
207
211
  ruby
@@ -215,9 +219,10 @@ DEPENDENCIES
215
219
  guard-minitest
216
220
  minitest (~> 5.0)
217
221
  minitest-rails
218
- mongoid (~> 4.0)
222
+ rails-controller-testing
219
223
  rake (~> 10.0)
224
+ rb-readline
220
225
  simple_form_attachments!
221
226
 
222
227
  BUNDLED WITH
223
- 1.13.6
228
+ 1.14.6
data/README.md CHANGED
@@ -127,30 +127,46 @@ Sorting of attachments is turned on by default for `has_many_attachments` relati
127
127
 
128
128
  ### Views
129
129
 
130
- Uploaded attachments are displayed in a `table`. The gem will look for a partial using the normal rails partial lookup (with a fallback to the default partial), this makes it easy to define a partial for each of your attachment models.
130
+ Uploaded attachments are displayed in a `div`. The gem will look for a partial using the normal rails partial lookup (with a fallback to the default partial), this makes it easy to define a partial for each of your attachment models.
131
+
132
+ Here an example partial for a model called `AttachmentImage`:
131
133
 
132
- Here is an example partial for a model called `AttachmentImage`:
133
134
  ```slim
134
135
  / app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim
135
- / Note the simple_form_attachments prefix!
136
+ / (Note the nesting in 'simple_form_attachments' directory.)
136
137
 
137
- td.thumb
138
- div.thumb
139
- = image_tag attachment.thumb_url, alt: attachment.file_name
138
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :thumb])
139
+ = image_tag attachment.thumb_url
140
140
 
141
- td.file_info
142
- = link_to attachment.file_name, attachment.file.url
143
- span.mime_type = attachment.file_mime_type
144
- span.size = attachment.file_size
141
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :file_info])
142
+ span class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :name)
143
+ = link_to attachment.file_name, attachment.file.url
144
+ span class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :mime_type)
145
+ = attachment.file_mime_type
146
+ span class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :size) data-filesize=attachment.file_size
147
+ = attachment.file_size
145
148
 
146
149
  - if attachment.errors.to_a.any?
147
- td.errors = render 'simple_form_attachments/errors', errors: attachment.errors.to_a
150
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :errors])
151
+ = render 'simple_form_attachments/errors', errors: attachment.errors.to_a
148
152
 
149
153
  - else
150
- td.fields
154
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :fields])
151
155
  = fields.input :caption
152
156
  ```
153
157
 
158
+ ### Dom class and CSS
159
+
160
+ The component is isolated in `simple_form_attachments` namespace. This gem comes with its own helper that geners corresponding class names – for example `SimpleFormAttachments.dom_class(:attachment, :file_info)` would generate `simple_form_attachments__file_info`.
161
+
162
+ Basic styling can be achieved by including `simple_form_attachments.js` css in your app:
163
+
164
+ ```css
165
+ /*
166
+ *= require simple_form_attachments
167
+ */
168
+ ```
169
+
154
170
  #### Validation errors
155
171
 
156
172
  If you want to show validation errors in your partial, simply include the `simple_form_attachments/errors` partial as shown above.
@@ -166,12 +182,11 @@ class AttachmentsController < SimpleFormAttachments::UploadController
166
182
  # The default controller uses the attachment type passed from the form input
167
183
  # to determine which Attachment class to create.
168
184
  #
169
- # This can be easily overriden, for instance if you want to determine
185
+ # This can be easily overridden, for instance if you want to infer
170
186
  # the class from the `mime type` of the file:
171
187
  #
172
188
  def attachment_class
173
189
  mime_type = params[:attachment][:file].content_type
174
- # TODO: very smart code to determine the class from the mime_type
175
190
  end
176
191
  end
177
192
  ```
@@ -1,5 +1,7 @@
1
1
  module SimpleFormAttachments
2
2
  class UploadController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+
3
5
  def show
4
6
  @attachment = attachment_class.find(params[:id])
5
7
  render json: { html: attachment_html(@attachment) }, status: :ok
@@ -11,7 +13,7 @@ module SimpleFormAttachments
11
13
  render json: { html: attachment_html(@attachment) }, status: (res ? :ok : :unprocessable_entity)
12
14
  end
13
15
 
14
- private # =============================================================
16
+ private
15
17
 
16
18
  def new_attachment
17
19
  attachment_class.new(attachment_params).tap do |att|
@@ -12,7 +12,7 @@ module SimpleFormAttachments
12
12
  end
13
13
 
14
14
  def to_simple_form_partial_path
15
- ['simple_form_attachments', to_partial_path].join('/')
15
+ File.join('simple_form_attachments', to_partial_path)
16
16
  end
17
17
  end
18
18
  end
@@ -15,9 +15,9 @@ module SimpleFormAttachments
15
15
  attachment_accessor_names << accessor_name
16
16
 
17
17
  options = {
18
- class_name: opts[:class_name] || 'SimpleFormAttachments::Attachment',
19
- dependent: opts[:dependent],
20
- inverse_of: nil
18
+ class_name: opts.fetch(:class_name, nil),
19
+ dependent: opts.fetch(:dependent, nil),
20
+ inverse_of: opts.fetch(:inverse_of, nil),
21
21
  }
22
22
 
23
23
  has_and_belongs_to_many accessor_name, options do
@@ -27,14 +27,16 @@ module SimpleFormAttachments
27
27
  # or at least we maintain the query and sort on the db level,
28
28
  # but as of not it is not possible to provide custom sort function to mongodb
29
29
  #
30
- define_method 'sorted' do
31
- target.sort_by { |attachment| base.send("#{accessor_name.to_s.singularize}_ids").index(attachment.id) }
30
+ define_method :sorted do
31
+ target.sort_by do |attachment|
32
+ base.send("#{accessor_name.to_s.singularize}_ids").index(attachment.id)
33
+ end
32
34
  end
33
35
  end
34
36
 
35
37
  accepts_nested_attributes_for accessor_name
36
38
 
37
- define_method "mark_#{accessor_name}_permanent" do
39
+ define_method :"mark_#{accessor_name}_permanent" do
38
40
  send(accessor_name).update_all(temporary: false)
39
41
  end
40
42
  end
@@ -45,8 +47,9 @@ module SimpleFormAttachments
45
47
  attachment_accessor_names << accessor_name
46
48
 
47
49
  options = {
48
- class_name: opts[:class_name] || 'SimpleFormAttachments::Attachment',
49
- dependent: opts[:dependent]
50
+ class_name: opts.fetch(:class_name, nil),
51
+ dependent: opts.fetch(:dependent, nil),
52
+ optional: opts.fetch(:optional, true)
50
53
  }
51
54
 
52
55
  belongs_to accessor_name, options
@@ -1,14 +1,14 @@
1
- tr.attachment class=('uploaded' if attachment.present? && attachment.errors.to_a.blank?)
2
- td.handle
1
+ div class=[SimpleFormAttachments.dom_class(:attachment), (SimpleFormAttachments.dom_class(:attachment, :is_uploaded) if attachment.present? && attachment.errors.to_a.blank?)]
2
+
3
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :handle])
3
4
 
4
5
  = yield
5
6
 
6
- td.hidden
7
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :hidden])
7
8
  = fields.hidden_field :id
8
9
  = form.hidden_field(relation_key, multiple: multiple, value: attachment.id) if attachment.errors.empty?
9
10
 
10
- td.cancel.delete.close
11
- - if attachment.errors.to_a.any?
12
- button.button.close = I18n.t(:close, scope: 'simple_form_attachments.buttons')
13
- - else
14
- button.button.delete = I18n.t(:delete, scope: 'simple_form_attachments.buttons')
11
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :actions])
12
+ - button_type = attachment.errors.to_a.any? ? :close : :delete
13
+ button class=SimpleFormAttachments.dom_class([:button, button_type])
14
+ = I18n.t(button_type, scope: 'simple_form_attachments.buttons')
@@ -1,4 +1,5 @@
1
1
  = I18n.t(:errors, scope: :simple_form_attachments, count: errors.to_a.length)
2
- ul.errors
3
- - errors.map{ |k, v| "#{k} #{v}" }.each do |error|
4
- li.error = error
2
+
3
+ ul
4
+ - errors.map { |k, v| [k, v].join(' ') }.each do |error|
5
+ li = error
@@ -1,17 +1,16 @@
1
- tr.attachment
2
- td.handle
3
- td.thumb
4
- td.file_info
5
- span.name
6
- | {{ name }}
7
- span.mime_type
8
- | {{ mime_type }}
9
- span.size
10
- | {{ size }}
1
+ div class=SimpleFormAttachments.dom_class(:attachment)
2
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :handle])
3
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :thumb])
11
4
 
12
- td.progress
13
- div.progress.container
14
- div.progress.bar
5
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :file_info])
6
+ div class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :name) {{ name }}
7
+ div class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :mime_type) {{ mime_type }}
8
+ div class=SimpleFormAttachments.dom_class(:attachment, :col, :file_info, :size) data-filesize='{{ size }}' {{ size }}
15
9
 
16
- td.cancel.delete.close
17
- button.button.cancel = I18n.t(:cancel, scope: 'simple_form_attachments.buttons')
10
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :progress])
11
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :progress, :container])
12
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :progress, :bar])
13
+
14
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :actions])
15
+ button class=SimpleFormAttachments.dom_class([:button, :cancel])
16
+ = I18n.t(:cancel, scope: 'simple_form_attachments.buttons')
@@ -1,4 +1,6 @@
1
1
  - if attachment.errors.to_a.any?
2
- td.errors = render 'simple_form_attachments/errors', errors: attachment.errors.to_a
2
+ div class=SimpleFormAttachments.dom_class(:attachment, [:col, :errors])
3
+ = render 'simple_form_attachments/errors', errors: attachment.errors.to_a
4
+
3
5
  - else
4
- td
6
+ div
@@ -3,9 +3,14 @@ en:
3
3
  buttons:
4
4
  delete: Delete
5
5
  cancel: Cancel
6
- close: ''
7
- disabled: Uploading …
8
- file_field: Select files
6
+ close: 'Close'
7
+ disabled: 'Uploading …'
8
+ file_field: 'Select files'
9
9
  errors:
10
10
  one: 'There was %{count} error:'
11
11
  other: 'There were %{count} errors:'
12
+ links:
13
+ choose_file:
14
+ zero: 'Choose file'
15
+ one: 'Choose file'
16
+ other: 'Choose files'
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  SimpleFormAttachments::Engine.routes.draw do
2
2
  scope module: :simple_form_attachments do
3
- get "attachments/:id" => "upload#show", as: :attachment
4
- post "attachments" => "upload#create", as: :attachments
3
+ get 'attachments/:id' => 'upload#show', as: :attachment
4
+ post 'attachments' => 'upload#create', as: :attachments
5
5
  end
6
6
  end