attachy 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +77 -12
- data/lib/assets/javascripts/attachy.js +16 -5
- data/lib/attachy/helpers/attachy/view_helper.rb +5 -5
- data/lib/attachy/models/attachy/viewer.rb +7 -7
- data/lib/attachy/version.rb +1 -1
- data/spec/factories/attachy/file.rb +1 -2
- data/spec/models/attachy/viewer/image_spec.rb +16 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a029ab515bf4b323047c5231ecfe7e30d90e552e
|
4
|
+
data.tar.gz: f1454ca82ee9055a1214562d743d9ff0db114e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b349429b795c329775229fe57f2ade6f7dd12b49458a63354c688b74aeb1fe5b1b6e3aacf34acad947d6082b8fee611d579b7e412f3049dc4acee66dea146c81
|
7
|
+
data.tar.gz: 47f608b456d919a95b0bbb555788c972ef86d861b7f3c0abcc10b8267771cd031372c1782b54fc4c4fb7a4639621bbecd2b72195527fd232cfed927f1b8feec0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.1.2
|
2
|
+
|
3
|
+
- Added `ruby-version`;
|
4
|
+
- Added `ruby-gemset`;
|
5
|
+
- Fix the possibility to pass the button label options;
|
6
|
+
- Now an empty message can be showed or hidden.
|
7
|
+
|
1
8
|
# 0.1.1
|
2
9
|
|
3
10
|
- When a blank value is assigned on attachment relation, it is skipped to avoid error on JSON parser.
|
data/README.md
CHANGED
@@ -83,32 +83,97 @@ public_id: default
|
|
83
83
|
version: 42
|
84
84
|
```
|
85
85
|
|
86
|
-
##
|
86
|
+
## Transformations
|
87
87
|
|
88
|
-
|
88
|
+
To know more about transformations, check the [Cloudinary Doc](http://cloudinary.com/documentation/image_transformations).
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
## Helpers
|
91
|
+
|
92
|
+
### Attachy
|
93
|
+
|
94
|
+
```
|
95
|
+
<%= f.attachy :avatar,
|
96
|
+
t: { width: 160, height: 160, crop: :fill },
|
97
|
+
tl: { width: 800, height: 600, crop: :scale },
|
98
|
+
button: { html: { text: 'Upload' } }
|
99
|
+
%>
|
92
100
|
```
|
93
101
|
|
94
|
-
|
102
|
+
+ `t`: image transformations;
|
103
|
+
+ `tl`: linked image transformations;
|
104
|
+
+ `button.html`: button html attributes.
|
95
105
|
|
96
|
-
|
106
|
+
```
|
107
|
+
<div class="attachy">
|
108
|
+
<ul class="attachy__content">
|
109
|
+
<li class="attachy__node">
|
110
|
+
<a class="attachy__link" href="">
|
111
|
+
<img src="">
|
112
|
+
</a>
|
97
113
|
|
98
|
-
|
114
|
+
<span class="attachy__remove">×</span>
|
115
|
+
</li>
|
116
|
+
</ul>
|
99
117
|
|
118
|
+
<div class="attachy__button">
|
119
|
+
<span>...</span>
|
120
|
+
|
121
|
+
<input type="file" class="attachy__fileupload">
|
122
|
+
|
123
|
+
<input value="[]" type="hidden">
|
124
|
+
</div>
|
125
|
+
</div>
|
100
126
|
```
|
101
|
-
|
127
|
+
|
128
|
+
+ `attachy`: wrapper;
|
129
|
+
+ `attachy__content`: the file content;
|
130
|
+
+ `attachy__node`: each file of the content;
|
131
|
+
+ `attachy__link`: the link of some file;
|
132
|
+
+ `img`: the uploaded file;
|
133
|
+
+ `attachy__remove`: button to remove the image;
|
134
|
+
+ `attachy__button`: pseudo button to access the upload file button;
|
135
|
+
+ `span`: the label of the button;
|
136
|
+
+ `attachy__fileupload`: the upload file field;
|
137
|
+
+ `hidden`: the field that keeps hidden the files metadata as JSON.
|
138
|
+
|
139
|
+
## Link
|
140
|
+
|
141
|
+
It draws the link with the image inside:
|
142
|
+
|
143
|
+
```
|
144
|
+
<%= attachy_link :avatar, @object
|
145
|
+
t: { width: 160, height: 160, crop: :fill },
|
146
|
+
tl: { width: 800, height: 600, crop: :scale },
|
147
|
+
html: { class: :added_custom }
|
148
|
+
%>
|
102
149
|
```
|
103
150
|
|
104
|
-
|
151
|
+
+ `t`: image transformations;
|
152
|
+
+ `tl`: linked image transformations;
|
153
|
+
+ `html`: link html attributes.
|
154
|
+
|
155
|
+
```
|
156
|
+
<a class="attachy__link" href="">
|
157
|
+
<img src="">
|
158
|
+
</a>
|
159
|
+
```
|
160
|
+
|
161
|
+
### Image
|
162
|
+
|
163
|
+
It draws the link with the image inside:
|
105
164
|
|
106
|
-
|
165
|
+
```
|
166
|
+
<%= attachy_image :avatar, @object
|
167
|
+
t: { width: 160, height: 160, crop: :fill },
|
168
|
+
html: { alt: :me }
|
169
|
+
%>
|
170
|
+
```
|
107
171
|
|
108
|
-
|
172
|
+
+ `t`: image transformations;
|
173
|
+
+ `html`: link html attributes.
|
109
174
|
|
110
175
|
```
|
111
|
-
|
176
|
+
<img src="https://res.cloudinary.com/account/image/upload/secret/version/hash.format">
|
112
177
|
```
|
113
178
|
|
114
179
|
## Test
|
@@ -5,7 +5,7 @@
|
|
5
5
|
*
|
6
6
|
* @author : Washington Botelho
|
7
7
|
* @doc : http://wbotelhos.com/attachy
|
8
|
-
* @version : 0.1.
|
8
|
+
* @version : 0.1.2
|
9
9
|
*
|
10
10
|
*/
|
11
11
|
|
@@ -109,6 +109,8 @@
|
|
109
109
|
link = that.link(file, image, json),
|
110
110
|
remove = that.removeButton();
|
111
111
|
|
112
|
+
that.hideEmpty();
|
113
|
+
|
112
114
|
if (that.multiple) {
|
113
115
|
var node = $('<li />', { html: link, 'class': 'attachy__node' }).append(remove);
|
114
116
|
|
@@ -119,6 +121,10 @@
|
|
119
121
|
});
|
120
122
|
},
|
121
123
|
|
124
|
+
hideEmpty: function() {
|
125
|
+
this.empty.hide();
|
126
|
+
},
|
127
|
+
|
122
128
|
image: function(file, json) {
|
123
129
|
var
|
124
130
|
config = this.imageConfig(file),
|
@@ -222,9 +228,9 @@
|
|
222
228
|
|
223
229
|
this.updateHidden();
|
224
230
|
|
225
|
-
|
226
|
-
|
227
|
-
|
231
|
+
if (!this.files.length) {
|
232
|
+
this.showEmpty();
|
233
|
+
}
|
228
234
|
},
|
229
235
|
|
230
236
|
onUploading: function() {
|
@@ -274,11 +280,16 @@
|
|
274
280
|
this.wrapper = this.field.closest('.attachy');
|
275
281
|
this.button = this.wrapper.find('.attachy__button span');
|
276
282
|
this.content = this.wrapper.find('.attachy__content');
|
277
|
-
this.
|
283
|
+
this.empty = this.wrapper.find('.attachy__empty');
|
284
|
+
this.hidden = this.wrapper.find('input[type="hidden"]');
|
278
285
|
this.remove = this.wrapper.find('.attachy__remove');
|
279
286
|
this.submit = this.wrapper.closest('form').find(':submit');
|
280
287
|
},
|
281
288
|
|
289
|
+
showEmpty: function() {
|
290
|
+
this.empty.show();
|
291
|
+
},
|
292
|
+
|
282
293
|
updateHidden: function() {
|
283
294
|
this.hidden.val(JSON.stringify(this.files));
|
284
295
|
}
|
@@ -8,23 +8,23 @@ module Attachy
|
|
8
8
|
viewer.field
|
9
9
|
end
|
10
10
|
|
11
|
-
def attachy_content(method, object, options)
|
11
|
+
def attachy_content(method, object, options = {})
|
12
12
|
Viewer.new(method, object, options, self).content
|
13
13
|
end
|
14
14
|
|
15
|
-
def attachy_file_field(method, object, options)
|
15
|
+
def attachy_file_field(method, object, options = {})
|
16
16
|
Viewer.new(method, object, options, self).file_field
|
17
17
|
end
|
18
18
|
|
19
|
-
def attachy_image(method, object, options)
|
19
|
+
def attachy_image(method, object, options = {})
|
20
20
|
Viewer.new(method, object, options, self).image
|
21
21
|
end
|
22
22
|
|
23
|
-
def attachy_link(method, object, options)
|
23
|
+
def attachy_link(method, object, options = {})
|
24
24
|
Viewer.new(method, object, options, self).link
|
25
25
|
end
|
26
26
|
|
27
|
-
def attachy_node(method, object, options)
|
27
|
+
def attachy_node(method, object, options = {})
|
28
28
|
Viewer.new(method, object, options, self).node
|
29
29
|
end
|
30
30
|
end
|
@@ -17,8 +17,8 @@ module Attachy
|
|
17
17
|
{ text: '...' }
|
18
18
|
end
|
19
19
|
|
20
|
-
def button_label(html:
|
21
|
-
html =
|
20
|
+
def button_label(html: htm(:button))
|
21
|
+
html = button_label_options.merge(html)
|
22
22
|
|
23
23
|
@view.content_tag :span, html.delete(:text), html
|
24
24
|
end
|
@@ -103,7 +103,7 @@ module Attachy
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def link(file = criteria, t: transform, tl: { crop: :none }, html: {})
|
106
|
-
html =
|
106
|
+
html = link_options.merge(data: tl).merge(html)
|
107
107
|
|
108
108
|
return yield(html, attachments) if block_given?
|
109
109
|
|
@@ -155,16 +155,16 @@ module Attachy
|
|
155
155
|
attachments.size == 1 && attachments.last.public_id == Attachy::File.default.public_id
|
156
156
|
end
|
157
157
|
|
158
|
-
def htm(
|
159
|
-
@options.dig(
|
158
|
+
def htm(path = [])
|
159
|
+
@options.dig(*[path, :html].flatten) || {}
|
160
160
|
end
|
161
161
|
|
162
162
|
def metadata
|
163
163
|
@metadata ||= @object.send("#{@method}_metadata")
|
164
164
|
end
|
165
165
|
|
166
|
-
def transform(path = [
|
167
|
-
@options.dig(*path) || {}
|
166
|
+
def transform(path = [])
|
167
|
+
@options.dig(*[path, :t].flatten) || {}
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
data/lib/attachy/version.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rails_helper'
|
|
3
3
|
RSpec.describe Attachy::Viewer, '.image' do
|
4
4
|
let!(:method) { :avatar }
|
5
5
|
let!(:object) { create :user }
|
6
|
-
let!(:viewer) { described_class.new method, object, options }
|
7
6
|
let!(:default_html) { { alt: :image, height: 50, width: 150 } }
|
8
7
|
let!(:default_t) { { height: 100, width: 200 } }
|
9
8
|
let!(:options) { { t: default_t, html: default_html } }
|
@@ -14,6 +13,8 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
14
13
|
create :file, attachable: object
|
15
14
|
end
|
16
15
|
|
16
|
+
subject { described_class.new method, object, options }
|
17
|
+
|
17
18
|
context 'when :html is present' do
|
18
19
|
let!(:html_attributes) { { alt: :alt, invalid: :invalid, height: 11, width: 22 } }
|
19
20
|
|
@@ -25,7 +26,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'adds all attributes on image' do
|
28
|
-
el =
|
29
|
+
el = subject.image(t: t_attributes, html: html_attributes)
|
29
30
|
|
30
31
|
expect(el).to have_tag 'img', with: html_attributes
|
31
32
|
end
|
@@ -37,7 +38,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
37
38
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(t_attributes) { 'http://example.org' } }
|
38
39
|
|
39
40
|
it 'gives priority to :html' do
|
40
|
-
el =
|
41
|
+
el = subject.image(t: t_attributes, html: html_attributes)
|
41
42
|
|
42
43
|
expect(el).to have_tag 'img', with: html_attributes
|
43
44
|
end
|
@@ -47,7 +48,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
47
48
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(default_t) { 'http://example.org' } }
|
48
49
|
|
49
50
|
it 'uses the :html attributes and transform with default :t' do
|
50
|
-
el =
|
51
|
+
el = subject.image(html: html_attributes)
|
51
52
|
|
52
53
|
expect(el).to have_tag 'img', with: {
|
53
54
|
'data-crop' => 'fill',
|
@@ -76,7 +77,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
76
77
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(t_attributes) { 'http://example.org' } }
|
77
78
|
|
78
79
|
it 'adds only the default transformation with file attributes' do
|
79
|
-
el =
|
80
|
+
el = subject.image(t: t_attributes, html: html_attributes)
|
80
81
|
|
81
82
|
expect(el).to have_tag 'img', with: {
|
82
83
|
'data-format' => file.format,
|
@@ -93,7 +94,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
93
94
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(t_attributes) { 'http://example.org' } }
|
94
95
|
|
95
96
|
it 'adds the :t attributes on html attributes with default data' do
|
96
|
-
el =
|
97
|
+
el = subject.image(t: t_attributes, html: html_attributes)
|
97
98
|
|
98
99
|
expect(el).to have_tag 'img', with: {
|
99
100
|
'data-format' => file.format,
|
@@ -113,10 +114,10 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
113
114
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(default_t) { 'http://example.org' } }
|
114
115
|
|
115
116
|
it 'uses the default :html with default :t' do
|
116
|
-
el =
|
117
|
+
el = subject.image
|
117
118
|
|
118
119
|
expect(el).to have_tag 'img', with: {
|
119
|
-
'alt' => '
|
120
|
+
'alt' => 'image',
|
120
121
|
'data-crop' => 'fill',
|
121
122
|
'data-format' => file.format,
|
122
123
|
'data-height' => 100,
|
@@ -125,9 +126,9 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
125
126
|
'data-sign-url' => true,
|
126
127
|
'data-version' => file.version,
|
127
128
|
'data-width' => 200,
|
128
|
-
'height' =>
|
129
|
+
'height' => 50,
|
129
130
|
'src' => 'http://example.org',
|
130
|
-
'width' =>
|
131
|
+
'width' => 150
|
131
132
|
}
|
132
133
|
end
|
133
134
|
end
|
@@ -138,10 +139,10 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
138
139
|
before { allow_any_instance_of(Attachy::File).to receive(:url).with(t_attributes) { 'http://example.org' } }
|
139
140
|
|
140
141
|
it 'uses the default :html with given :t overriding the default :t' do
|
141
|
-
el =
|
142
|
+
el = subject.image(t: t_attributes)
|
142
143
|
|
143
144
|
expect(el).to have_tag 'img', with: {
|
144
|
-
'alt' => '
|
145
|
+
'alt' => 'image',
|
145
146
|
'data-crop' => 'fill',
|
146
147
|
'data-format' => file.format,
|
147
148
|
'data-height' => 1,
|
@@ -150,9 +151,9 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
150
151
|
'data-sign-url' => true,
|
151
152
|
'data-version' => file.version,
|
152
153
|
'data-width' => 2,
|
153
|
-
'height' =>
|
154
|
+
'height' => 50,
|
154
155
|
'src' => 'http://example.org',
|
155
|
-
'width' =>
|
156
|
+
'width' => 150
|
156
157
|
}
|
157
158
|
end
|
158
159
|
end
|
@@ -164,7 +165,7 @@ RSpec.describe Attachy::Viewer, '.image' do
|
|
164
165
|
it 'is used' do
|
165
166
|
expect(file).to receive(:url).with(default_t) { 'http://example.org' }
|
166
167
|
|
167
|
-
|
168
|
+
subject.image file
|
168
169
|
end
|
169
170
|
end
|
170
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloudinary
|