middleman-image-uploader-tag 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +17 -3
- data/lib/middleman/image-uploader-tag/cdns/cloudinary.rb +3 -2
- data/lib/middleman/image-uploader-tag/extension.rb +13 -9
- data/lib/middleman/image-uploader-tag/version.rb +1 -1
- data/test/lib/middleman/image-uploader-tag/cdns/cloudinary_test.rb +6 -3
- data/test/lib/middleman/image-uploader-tag/extension_test.rb +45 -7
- 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: e09ba1cd1ec0c3bb7494f10d3193573dec5c3a89
|
4
|
+
data.tar.gz: e76f501dd36d68c2be1ca359852f1581abf6eda1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872f682fd1a9e2abc211598d27cabba775d1a018e6d22547e1625e0e9a2dc4430aa16e2ba4ac22d72b0f0314ce6085fca5d75e3c82520cc0cc7954d0e16aa53d
|
7
|
+
data.tar.gz: 94838cbd8cf5a81ced39ac281d8c855a8f50e555ed8c65ffde6fde68a7d19e43659d2ad033d2d01731ab6ec8ebccae09805a9ab4308a9a4aeb9fbcb6b190a575
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -41,7 +41,9 @@ Also you can install the latest code directly from repository with:
|
|
41
41
|
|
42
42
|
## Configuration
|
43
43
|
|
44
|
-
|
44
|
+
In you `config.rb`:
|
45
|
+
|
46
|
+
Activate extension, providing credentials for remote provider:
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
activate :image_uploader_tag do |e|
|
@@ -58,9 +60,21 @@ activate :image_uploader_tag do |e|
|
|
58
60
|
end
|
59
61
|
```
|
60
62
|
|
61
|
-
|
63
|
+
Add ignore option to prevent remote images uploading during deploy:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
ignore '/images/remote_images/*'
|
67
|
+
```
|
68
|
+
|
69
|
+
Also you could add a line in your `.gitignore` file, to prevent uploading images during development too:
|
70
|
+
|
71
|
+
```
|
72
|
+
source/images/remote_images
|
73
|
+
```
|
74
|
+
|
75
|
+
Note: the `remote_images_dir` sets the only folder images would remote uploaded.
|
62
76
|
|
63
|
-
It is optional and by default has the value `'remote_images'`. You can change it but be sure to place it
|
77
|
+
It is optional and by default has the value `'remote_images'`. You can change it but be sure to place it within the images directory of the Middleman.
|
64
78
|
|
65
79
|
## Usage
|
66
80
|
|
@@ -14,10 +14,11 @@ module Middleman
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def get_remote_link(image_path)
|
17
|
+
def get_remote_link(image_path, secure = false)
|
18
18
|
raise NotFound if !image_path || !File.exist?(image_path.to_s)
|
19
19
|
|
20
|
-
upload_to_cloud(image_path)
|
20
|
+
image_attributes = upload_to_cloud(image_path)
|
21
|
+
secure ? image_attributes[:secure_url] : image_attributes[:url]
|
21
22
|
end
|
22
23
|
|
23
24
|
def upload_to_cloud(file, options = {})
|
@@ -25,19 +25,19 @@ module Middleman
|
|
25
25
|
end
|
26
26
|
|
27
27
|
helpers do
|
28
|
-
def remote_image_tag(image_name, params = {})
|
29
|
-
image_tag remote_image_tag_link(image_name), params
|
28
|
+
def remote_image_tag(image_name, secure = false, params = {})
|
29
|
+
image_tag remote_image_tag_link(image_name, secure), params
|
30
30
|
end
|
31
31
|
|
32
|
-
def remote_image_tag_link(image_name)
|
32
|
+
def remote_image_tag_link(image_name, secure = false)
|
33
33
|
klass = ::Middleman::ImageUploaderTag::Extension
|
34
34
|
|
35
|
-
klass.get_remote_path image_name
|
35
|
+
klass.get_remote_path image_name, secure
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.image_location(image_path)
|
40
|
-
File.join(app.root, 'source', remote_images_dir, image_path)
|
40
|
+
File.join(app.root, 'source', app.images_dir, remote_images_dir, image_path)
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.provider
|
@@ -49,14 +49,18 @@ module Middleman
|
|
49
49
|
).new(provider_options.provider_config)
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.get_remote_path(image_name)
|
52
|
+
def self.get_remote_path(image_name, secure = false)
|
53
53
|
image_path = image_location(image_name)
|
54
54
|
raise NotFound unless File.exist?(image_path)
|
55
55
|
|
56
56
|
if app.config.environment == :build
|
57
|
-
provider.
|
57
|
+
if provider.instance_of? ::Middleman::ImageUploaderTag::CloudinaryCDN
|
58
|
+
provider.get_remote_link image_path, secure
|
59
|
+
else
|
60
|
+
provider.get_remote_link image_path
|
61
|
+
end
|
58
62
|
else
|
59
|
-
image_name
|
63
|
+
File.join('/', app.images_dir, remote_images_dir, image_name)
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
@@ -73,7 +77,7 @@ module Middleman
|
|
73
77
|
end
|
74
78
|
|
75
79
|
def self.create_images_dir!
|
76
|
-
img_dir = File.join(app.root, 'source', remote_images_dir)
|
80
|
+
img_dir = File.join(app.root, 'source', app.images_dir, remote_images_dir)
|
77
81
|
|
78
82
|
Dir.mkdir(img_dir) unless Dir.exist?(img_dir)
|
79
83
|
end
|
@@ -101,11 +101,12 @@ class CloudinaryCDNTest < Minitest::Test
|
|
101
101
|
|
102
102
|
Cloudinary::Uploader.instance_eval do
|
103
103
|
def upload(file, options)
|
104
|
-
{ 'secure_url': 'http://cdn.com/test.jpg' }
|
104
|
+
{ 'secure_url': 'https://cdn.com/test.jpg', 'url': 'http://cdn.com/test.jpg' }
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
assert_equal '
|
108
|
+
assert_equal 'https://cdn.com/test.jpg', cdn.new(config).get_remote_link(image_path, true)
|
109
|
+
assert_equal 'http://cdn.com/test.jpg', cdn.new(config).get_remote_link(image_path, false)
|
109
110
|
end
|
110
111
|
|
111
112
|
private
|
@@ -126,7 +127,9 @@ class CloudinaryCDNTest < Minitest::Test
|
|
126
127
|
end
|
127
128
|
|
128
129
|
def extension
|
129
|
-
|
130
|
+
app = Class.new(Middleman::Application)
|
131
|
+
app.config.images_dir = 'images'
|
132
|
+
Middleman::ImageUploaderTag::Extension.new(app).class
|
130
133
|
end
|
131
134
|
end
|
132
135
|
|
@@ -7,6 +7,7 @@ class ExtensionTest < Minitest::Test
|
|
7
7
|
|
8
8
|
def setup
|
9
9
|
@application = Class.new(Middleman::Application)
|
10
|
+
set_app_config({ images_dir: 'images' })
|
10
11
|
@ext_instance = Middleman::ImageUploaderTag::Extension.new(@application)
|
11
12
|
@ext_instance.app = @application
|
12
13
|
@ext_class = @ext_instance.class
|
@@ -33,7 +34,7 @@ class ExtensionTest < Minitest::Test
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_create_images_dir!
|
36
|
-
remote_images_dir = File.join(application.root, 'source', ext_class.remote_images_dir)
|
37
|
+
remote_images_dir = File.join(application.root, 'source', application.images_dir, ext_class.remote_images_dir)
|
37
38
|
|
38
39
|
assert Dir.exists?(remote_images_dir)
|
39
40
|
|
@@ -71,6 +72,13 @@ class ExtensionTest < Minitest::Test
|
|
71
72
|
|
72
73
|
assert_equal true, called
|
73
74
|
assert_equal image, name_called
|
75
|
+
|
76
|
+
called = false
|
77
|
+
application.stub :remote_image_tag_link, image do
|
78
|
+
application.remote_image_tag 'test.jpg', true, alt: 'hello'
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_equal true, called
|
74
82
|
end
|
75
83
|
|
76
84
|
def test_remote_image_tag_link_helper
|
@@ -78,17 +86,27 @@ class ExtensionTest < Minitest::Test
|
|
78
86
|
image = ext_class.image_location('test.jpg')
|
79
87
|
|
80
88
|
mock = Minitest::Mock.new
|
81
|
-
mock.expect :get_remote_path, image, ['test.jpg']
|
89
|
+
mock.expect :get_remote_path, image, ['test.jpg', false]
|
82
90
|
|
83
91
|
::Middleman::ImageUploaderTag.stub_const(:Extension, mock) do
|
84
92
|
application.remote_image_tag_link 'test.jpg'
|
85
93
|
end
|
86
94
|
|
87
95
|
mock.verify
|
96
|
+
|
97
|
+
mock = Minitest::Mock.new
|
98
|
+
mock.expect :get_remote_path, image, ['test.jpg', true]
|
99
|
+
|
100
|
+
::Middleman::ImageUploaderTag.stub_const(:Extension, mock) do
|
101
|
+
application.remote_image_tag_link 'test.jpg', true
|
102
|
+
end
|
103
|
+
|
104
|
+
mock.verify
|
88
105
|
end
|
89
106
|
|
90
107
|
def test_image_location
|
91
|
-
remote_images_dir = File.join(application.root, 'source',
|
108
|
+
remote_images_dir = File.join(application.root, 'source',
|
109
|
+
application.images_dir, ext_class.remote_images_dir)
|
92
110
|
|
93
111
|
assert_equal remote_images_dir + '/test.jpg', ext_class.image_location('test.jpg')
|
94
112
|
assert_equal remote_images_dir + '/test.jpg', ext_class.image_location('/test.jpg')
|
@@ -102,14 +120,15 @@ class ExtensionTest < Minitest::Test
|
|
102
120
|
end
|
103
121
|
|
104
122
|
def test_get_remote_path_during_development
|
123
|
+
remote_images_dir = File.join(application.images_dir, ext_class.remote_images_dir)
|
105
124
|
create_fake_image!('test.jpg')
|
106
125
|
create_fake_image!('test/test.jpg')
|
107
126
|
|
108
127
|
set_app_config environment: :development
|
109
128
|
|
110
|
-
assert_equal 'test.jpg', ext_class.get_remote_path('test.jpg')
|
111
|
-
assert_equal '/test.jpg', ext_class.get_remote_path('/test.jpg')
|
112
|
-
assert_equal 'test/test.jpg', ext_class.get_remote_path('test/test.jpg')
|
129
|
+
assert_equal File.join('/', remote_images_dir, 'test.jpg'), ext_class.get_remote_path('test.jpg')
|
130
|
+
assert_equal File.join('/', remote_images_dir, '/test.jpg'), ext_class.get_remote_path('/test.jpg')
|
131
|
+
assert_equal File.join('/', remote_images_dir, 'test/test.jpg'), ext_class.get_remote_path('test/test.jpg')
|
113
132
|
end
|
114
133
|
|
115
134
|
def test_get_remote_path_raises_exception_for_absent_image
|
@@ -127,12 +146,31 @@ class ExtensionTest < Minitest::Test
|
|
127
146
|
image = ext_class.image_location('test.jpg')
|
128
147
|
|
129
148
|
mock = Minitest::Mock.new
|
130
|
-
mock.expect :
|
149
|
+
mock.expect :instance_of?, true, [::Middleman::ImageUploaderTag::CloudinaryCDN]
|
150
|
+
mock.expect :get_remote_link, image, [image, false]
|
131
151
|
|
132
152
|
ext_class.stub :provider, mock do
|
133
153
|
ext_class.get_remote_path 'test.jpg'
|
134
154
|
end
|
135
155
|
mock.verify
|
156
|
+
|
157
|
+
mock = Minitest::Mock.new
|
158
|
+
mock.expect :instance_of?, true, [::Middleman::ImageUploaderTag::CloudinaryCDN]
|
159
|
+
mock.expect :get_remote_link, image, [image, true]
|
160
|
+
|
161
|
+
ext_class.stub :provider, mock do
|
162
|
+
ext_class.get_remote_path 'test.jpg', true
|
163
|
+
end
|
164
|
+
mock.verify
|
165
|
+
|
166
|
+
mock = Minitest::Mock.new
|
167
|
+
mock.expect :instance_of?, false, [::Middleman::ImageUploaderTag::CloudinaryCDN]
|
168
|
+
mock.expect :get_remote_link, image, [image]
|
169
|
+
|
170
|
+
ext_class.stub :provider, mock do
|
171
|
+
ext_class.get_remote_path 'test.jpg', true
|
172
|
+
end
|
173
|
+
mock.verify
|
136
174
|
end
|
137
175
|
|
138
176
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-image-uploader-tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Buhayeu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|