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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +118 -113
- data/README.md +29 -14
- data/app/controllers/simple_form_attachments/upload_controller.rb +3 -1
- data/app/models/concerns/simple_form_attachments/attachment.rb +1 -1
- data/app/models/concerns/simple_form_attachments/has_attachments.rb +11 -8
- data/app/views/layouts/simple_form_attachments/_attachment_layout.html.slim +8 -8
- data/app/views/simple_form_attachments/_errors.html.slim +4 -3
- data/app/views/simple_form_attachments/attachments/_attachment.hbs.slim +14 -15
- data/app/views/simple_form_attachments/attachments/_attachment.html.slim +4 -2
- data/config/locales/simple_form_attachments/simple_form_attachments.en.yml +8 -3
- data/config/routes.rb +2 -2
- data/lib/assets/javascripts/simple_form_attachments/{simple_form_attachments.js.coffee → simple_form_attachments.coffee.erb} +24 -41
- data/lib/assets/stylesheets/simple_form_attachments/__attachment.scss.erb +8 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col.scss.erb +1 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__actions.scss.erb +3 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__errors.scss.erb +10 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__fields.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__file_info.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__handle.scss.erb +6 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__hidden.scss.erb +3 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__progress.scss.erb +14 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__thumb.scss.erb +9 -0
- data/lib/assets/stylesheets/simple_form_attachments/__attachment_list.scss.erb +11 -0
- data/lib/assets/stylesheets/simple_form_attachments/__button.scss.erb +9 -0
- data/lib/assets/stylesheets/simple_form_attachments/__label.scss.erb +3 -0
- data/lib/assets/stylesheets/simple_form_attachments/simple_form_attachments.scss.erb +29 -0
- data/lib/assets/stylesheets/simple_form_attachments.css +4 -0
- data/lib/simple_form_attachments/attachment_input.rb +12 -11
- data/lib/simple_form_attachments/version.rb +1 -1
- data/lib/simple_form_attachments.rb +12 -0
- data/simple_form_attachments.gemspec +2 -1
- data/test/controllers/simple_form_attachments/upload_controller_test.rb +53 -57
- data/test/dummy/Gemfile +1 -0
- data/test/dummy/Gemfile.lock +80 -74
- data/test/dummy/app/assets/stylesheets/application.css +5 -0
- data/test/dummy/app/models/attachment_image.rb +1 -0
- data/test/dummy/app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim +12 -9
- data/test/dummy/config/environments/test.rb +2 -2
- data/test/dummy/config/mongoid.yml +5 -8
- data/test/dummy/config/routes.rb +1 -3
- data/test/simple_form_attachments_test.rb +30 -0
- data/test/test_helper.rb +5 -1
- metadata +46 -16
- data/test/dummy/app/assets/stylesheets/application.css.scss +0 -5
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32937e7bfd5b986371b84849e0978f6351f1483c
|
4
|
+
data.tar.gz: 90721d27ee39824d4f6aeb3f6a8d32f84d15980a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4faa06b6077c22c05011becf23da50daaaea0bc926097b8d3a2b13527050e538cb6d4c15d2a641fae850ff112b3d8000955e889abdf4bbf4934c3e263a9b0a8b
|
7
|
+
data.tar.gz: b23ec5127609dd3b41a45c386e99ea12d24dddbab5a67f294d84e31d35eb4ade677ea83d8b56f950f6d8ca2522ecb4d5324e82ce8debda28f3b63ac99fdc3896
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_form_attachments (0.
|
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
|
-
|
17
|
-
actionpack (=
|
18
|
-
|
19
|
-
|
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 (~>
|
22
|
-
actionpack (
|
23
|
-
actionview (=
|
24
|
-
activesupport (=
|
25
|
-
rack (~>
|
26
|
-
rack-test (~> 0.6.
|
27
|
-
rails-dom-testing (~>
|
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 (
|
30
|
-
activesupport (=
|
34
|
+
actionview (5.1.1)
|
35
|
+
activesupport (= 5.1.1)
|
31
36
|
builder (~> 3.1)
|
32
|
-
|
33
|
-
rails-dom-testing (~>
|
34
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
35
|
-
activejob (
|
36
|
-
activesupport (=
|
37
|
-
globalid (>= 0.3.
|
38
|
-
activemodel (
|
39
|
-
activesupport (=
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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.
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
58
|
-
coveralls (0.8.15)
|
61
|
+
coveralls (0.8.21)
|
59
62
|
json (>= 1.8, < 3)
|
60
|
-
simplecov (~> 0.
|
63
|
+
simplecov (~> 0.14.1)
|
61
64
|
term-ansicolor (~> 1.3)
|
62
|
-
thor (~> 0.19.
|
63
|
-
tins (
|
64
|
-
database_cleaner (1.
|
65
|
+
thor (~> 0.19.4)
|
66
|
+
tins (~> 1.6)
|
67
|
+
database_cleaner (1.6.1)
|
65
68
|
docile (1.1.5)
|
66
|
-
dragonfly (1.
|
69
|
+
dragonfly (1.1.3)
|
67
70
|
addressable (~> 2.3)
|
68
71
|
multi_json (~> 1.0)
|
69
|
-
rack (>= 1.3
|
70
|
-
|
71
|
-
ffi (1.9.
|
72
|
+
rack (>= 1.3)
|
73
|
+
erubi (1.6.0)
|
74
|
+
ffi (1.9.18)
|
72
75
|
formatador (0.2.5)
|
73
|
-
globalid (0.
|
74
|
-
activesupport (>= 4.
|
75
|
-
guard (2.14.
|
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.
|
91
|
+
i18n (0.8.4)
|
89
92
|
jquery-ui-rails (6.0.1)
|
90
93
|
railties (>= 3.2.16)
|
91
|
-
json (1.
|
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.
|
99
|
-
mail (2.6.
|
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.
|
106
|
-
minitest (5.
|
107
|
-
minitest-rails (
|
108
|
-
minitest (~> 5.
|
109
|
-
railties (~>
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
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 (
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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 (=
|
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.
|
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.
|
157
|
-
rails-assets-jquery (3.
|
158
|
-
rails-
|
159
|
-
|
160
|
-
|
161
|
-
activesupport (
|
162
|
-
|
163
|
-
|
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 (
|
167
|
-
actionpack (=
|
168
|
-
activesupport (=
|
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.
|
173
|
-
rb-inotify (0.9.
|
172
|
+
rb-fsevent (0.9.8)
|
173
|
+
rb-inotify (0.9.8)
|
174
174
|
ffi (>= 0.5.0)
|
175
|
-
|
175
|
+
rb-readline (0.5.4)
|
176
|
+
ruby_dep (1.5.0)
|
176
177
|
shellany (0.0.1)
|
177
|
-
simple_form (3.
|
178
|
-
actionpack (> 4, < 5.
|
179
|
-
activemodel (> 4, < 5.
|
180
|
-
simplecov (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.
|
185
|
-
slim (3.0.
|
186
|
-
temple (
|
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.
|
197
|
-
term-ansicolor (1.
|
197
|
+
temple (0.8.0)
|
198
|
+
term-ansicolor (1.6.0)
|
198
199
|
tins (~> 1.0)
|
199
|
-
thor (0.19.
|
200
|
-
thread_safe (0.3.
|
201
|
-
tilt (2.0.
|
202
|
-
tins (1.
|
203
|
-
tzinfo (1.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
|
-
|
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.
|
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 `
|
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
|
136
|
+
/ (Note the nesting in 'simple_form_attachments' directory.)
|
136
137
|
|
137
|
-
|
138
|
-
|
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
|
-
|
142
|
-
=
|
143
|
-
|
144
|
-
span
|
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
|
-
|
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
|
-
|
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
|
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|
|
@@ -15,9 +15,9 @@ module SimpleFormAttachments
|
|
15
15
|
attachment_accessor_names << accessor_name
|
16
16
|
|
17
17
|
options = {
|
18
|
-
class_name: opts
|
19
|
-
dependent: opts
|
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
|
31
|
-
target.sort_by
|
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
|
49
|
-
dependent: opts
|
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
|
-
|
2
|
-
|
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
|
-
|
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
|
-
|
11
|
-
-
|
12
|
-
|
13
|
-
|
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,17 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
13
|
-
div.
|
14
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
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
|
-
|
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
|
4
|
-
post
|
3
|
+
get 'attachments/:id' => 'upload#show', as: :attachment
|
4
|
+
post 'attachments' => 'upload#create', as: :attachments
|
5
5
|
end
|
6
6
|
end
|