image-resizer-rails 0.1.0
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 +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +104 -0
- data/app/assets/javascripts/image_resizer.js.erb +201 -0
- data/app/helpers/image/resizer/rails/ir_helper.rb +16 -0
- data/lib/image/resizer/rails.rb +94 -0
- data/lib/image/resizer/rails/engine.rb +11 -0
- data/lib/image/resizer/rails/helper.rb +148 -0
- data/lib/image/resizer/rails/version.rb +8 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7f3b34eae19c26e7c26b3570b05dbcb714bedd2
|
4
|
+
data.tar.gz: ac1091c70204326457f4f87ccbc9d8590bc1dc6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ff4a0274a131dae9ddc321f7beed480fc4a7858002423abff4a07d6a0bd3c56dca349fc2db0e9ff0911aa5830642f31c973ccdc93da616c55c52ab41d474b6e
|
7
|
+
data.tar.gz: ee48413805594fb9f60dfedd18df8e1df1ce1b12e46f3caf139ebe238402c2eea3a46cf57ed3046f82d21059769693ba0e5c58b4c3a28c17c9c0ba5854d77312
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 James Nicol
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# Image::Resizer::Rails
|
2
|
+
|
3
|
+
This gem includes helpers to build the appropriate URLs for images served via an [image-resizer](https://github.com/jimmynicol/image-resizer) instance.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'image-resizer-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install image-resizer-rails
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
Configuring this gem is done via:
|
21
|
+
|
22
|
+
Image::Resizer::Rails.configure do |config|
|
23
|
+
# add your configuration here...
|
24
|
+
end
|
25
|
+
|
26
|
+
For a rails project this is best done via an [initializer](http://guides.rubyonrails.org/configuring.html).
|
27
|
+
|
28
|
+
The available config options are:
|
29
|
+
|
30
|
+
### CDN
|
31
|
+
This is a required setting.
|
32
|
+
|
33
|
+
config.cdn = 'https://my.cdn.com'
|
34
|
+
|
35
|
+
|
36
|
+
### Modifiers
|
37
|
+
This gem comes with all the available modifiers that are supported natively by `image-resizer` but also allows you add your own modifier strings if you have built custom options into your own implementation.
|
38
|
+
|
39
|
+
# config.add_modifier(key, alias='', values=[])
|
40
|
+
config.add_modifiers(:x, :xtra, ['one', 'two'])
|
41
|
+
|
42
|
+
### Sources
|
43
|
+
As with modifiers you can add more external source options. Natively Facebook, Twitter, Youtube and Vimeo are supported but should you chose to add another to that list you can configure the gem with them
|
44
|
+
|
45
|
+
# config.add_source(name, option)
|
46
|
+
config.add_source(:myspace, :ms_id)
|
47
|
+
|
48
|
+
### Ruby method aliases
|
49
|
+
If you need for whatever reason to alias the helper methods provided you can do that via config aswell.
|
50
|
+
|
51
|
+
config.add_alias :ir_image_tag, :something_else
|
52
|
+
|
53
|
+
### Javascript aliases
|
54
|
+
You can also override any of the JS method names, including the global object name.
|
55
|
+
|
56
|
+
config.add_js_alias :js_class, 'MyAwesomeResizer'
|
57
|
+
config.add_js_alias :js)image_tag, 'something'
|
58
|
+
|
59
|
+
## Usage
|
60
|
+
|
61
|
+
The functionality in this gem has two parts, a ruby view helper and a javascript helper.
|
62
|
+
|
63
|
+
### Ruby View Helper
|
64
|
+
|
65
|
+
You can generate an image tag in the same way the regular [helper](http://guides.rubyonrails.org/layouts_and_rendering.html#asset-tag-helpers) does, just with adding a valid set of modifiers
|
66
|
+
|
67
|
+
<div class="content">
|
68
|
+
<%= ir_image_tag('https://s3.amazonaws.com/sample.bucket/path/to/image.jpg', h:200, w:300) %>
|
69
|
+
<%= ir_image_tag(fb_uid: 'missnine', s:100) %>
|
70
|
+
</div>
|
71
|
+
|
72
|
+
You can generate a background image string
|
73
|
+
|
74
|
+
<div style="<%= ir_background('https://s3.amazonaws.com/sample.bucket/path/to/image.jpg', h:200, w:300) %>"></div>
|
75
|
+
|
76
|
+
Or just return the url as needed
|
77
|
+
|
78
|
+
<div class="content">
|
79
|
+
<%= ir_url('https://s3.amazonaws.com/sample.bucket/path/to/image.jpg', h:200, w:300) %>
|
80
|
+
</div>
|
81
|
+
|
82
|
+
### Javascript Helper
|
83
|
+
|
84
|
+
The Javascript helper is generated from the config data as an `.erb` file on load. So all of the new modifiers or sources added will be reflected, as well as any aliases set.
|
85
|
+
|
86
|
+
The JS helper (`image_resizer.js`) is either attached as a global, or can be loaded via AMD or CommonJS if you are using those techniques. It has the same helper methods as the ruby helper.
|
87
|
+
|
88
|
+
<script>
|
89
|
+
var imgUrl = 'https://s3.amazonaws.com/sample.bucket/path/to/image.jpg';
|
90
|
+
$('#image-tag').append(ImageResizer.irImageTag(imgUrl, {s:200}));
|
91
|
+
$('#image-bg').attr('style', ImageResizer.irBackground(imgUrl, {s:200}));
|
92
|
+
$('#image-url').text(ImageResizer.irImageTag(imgUrl, {s:200}));
|
93
|
+
</script>
|
94
|
+
<div id="image-tag"></div>
|
95
|
+
<div id="image-bg"></div>
|
96
|
+
<div id="image-url"></div>
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create new Pull Request
|
@@ -0,0 +1,201 @@
|
|
1
|
+
/**
|
2
|
+
Javascript helper for building `image-resizer` url endpoints
|
3
|
+
- this file is partially built via the parent ruby process to include the
|
4
|
+
available modifiers and custom class/method names.
|
5
|
+
*/
|
6
|
+
(function(root, factory) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
// AMD: import Backbone and underscore into the factory
|
10
|
+
if (typeof define === 'function' && define.amd) {
|
11
|
+
define([], function(){
|
12
|
+
return factory(root);
|
13
|
+
});
|
14
|
+
|
15
|
+
// CommonJS: for Node.js or Browserify
|
16
|
+
} else if (typeof exports !== 'undefined') {
|
17
|
+
module.exports = factory(root);
|
18
|
+
|
19
|
+
// Finally, as a browser global.
|
20
|
+
} else {
|
21
|
+
root.<%= Image::Resizer::Rails.js_class %> = factory(root);
|
22
|
+
}
|
23
|
+
|
24
|
+
}(this, function(root){
|
25
|
+
'use strict';
|
26
|
+
|
27
|
+
// Private methods
|
28
|
+
function parseArgs(){
|
29
|
+
var source, modifiers;
|
30
|
+
source = typeof arguments[0] === 'string' ? arguments[0] : null;
|
31
|
+
if (source){
|
32
|
+
modifiers = arguments[1];
|
33
|
+
} else {
|
34
|
+
modifiers = arguments[0];
|
35
|
+
}
|
36
|
+
return { source: source, modifiers: modifiers };
|
37
|
+
};
|
38
|
+
|
39
|
+
function generateEndpoint(source, modifiers){
|
40
|
+
var uri, cdn, mods, path;
|
41
|
+
|
42
|
+
uri = source ? URI(source) : null;
|
43
|
+
cdn = IR.CDN.replace(/\/$/, '');
|
44
|
+
mods = modStr(uri, modifiers);
|
45
|
+
path = buildPath(uri, modifiers);
|
46
|
+
|
47
|
+
return cdn + mods + path;
|
48
|
+
};
|
49
|
+
|
50
|
+
function modSet(key){
|
51
|
+
var k, v;
|
52
|
+
for (k in IR.modifiers){
|
53
|
+
v = IR.modifiers[k];
|
54
|
+
if (k === key || v.alias === key){
|
55
|
+
return v;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return null;
|
59
|
+
};
|
60
|
+
|
61
|
+
function sourceOption(key){
|
62
|
+
var mods = IR.modifiers.e.values
|
63
|
+
for (var k in mods){
|
64
|
+
if (key === mods[k]){
|
65
|
+
return [k, mods[k]];
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return null;
|
69
|
+
};
|
70
|
+
|
71
|
+
function modStr(uri, modifiers){
|
72
|
+
var modArr = [];
|
73
|
+
if (modifiers){
|
74
|
+
modArr = buildModArr(modifiers);
|
75
|
+
}
|
76
|
+
if (uri && urlDomain(uri.hostname) === 'facebook'){
|
77
|
+
modArr.push('efacebook');
|
78
|
+
}
|
79
|
+
return modArr.length > 0 ? '/' + modArr.join('-') : '';
|
80
|
+
};
|
81
|
+
|
82
|
+
function buildModArr(modifiers){
|
83
|
+
var modArr, k, v, mSet, src;
|
84
|
+
|
85
|
+
modArr = [];
|
86
|
+
for (k in modifiers){
|
87
|
+
v = modifiers[k];
|
88
|
+
mSet = modSet(k);
|
89
|
+
src = sourceOption(k);
|
90
|
+
if (mSet){
|
91
|
+
if (mSet.values){
|
92
|
+
if (mSet.values[v]){
|
93
|
+
modArr.push(k + v);
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
modArr.push(k + v);
|
97
|
+
}
|
98
|
+
} else if (src) {
|
99
|
+
modArr.push('e' + src[0]);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
return modArr;
|
104
|
+
};
|
105
|
+
|
106
|
+
function buildPath(uri, modifiers){
|
107
|
+
if(uri){
|
108
|
+
switch(urlDomain(uri.hostname)){
|
109
|
+
case 's3':
|
110
|
+
return s3Object(uri);
|
111
|
+
break;
|
112
|
+
case 'facebook':
|
113
|
+
return fbUid(uri);
|
114
|
+
break;
|
115
|
+
default:
|
116
|
+
''
|
117
|
+
}
|
118
|
+
} else {
|
119
|
+
for (var k in modifiers){
|
120
|
+
if (sourceOption(k)){
|
121
|
+
return '/' + modifiers[k] + '.jpg';
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
function urlDomain(host){
|
128
|
+
var domain = 'other';
|
129
|
+
if (/s3.amazonaws.com/i.test(host)){
|
130
|
+
domain = 's3';
|
131
|
+
}
|
132
|
+
if (/facebook.com/i.test(host)){
|
133
|
+
domain = 'facebook';
|
134
|
+
}
|
135
|
+
return domain;
|
136
|
+
};
|
137
|
+
|
138
|
+
function s3Object(uri){
|
139
|
+
if (uri.hostname === 's3.amazonaws.com'){
|
140
|
+
return '/' + uri.pathname.split('/').slice(2).join('/');
|
141
|
+
} else {
|
142
|
+
return uri.pathname;
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
function URI(url){
|
147
|
+
var parser = document.createElement('a');
|
148
|
+
parser.href = url;
|
149
|
+
return parser;
|
150
|
+
};
|
151
|
+
|
152
|
+
function fbUid(uri){
|
153
|
+
return uri.pathname.split('/')[1];
|
154
|
+
};
|
155
|
+
|
156
|
+
function altTag(url){
|
157
|
+
return url.split('/').pop().split('.')[0];
|
158
|
+
};
|
159
|
+
|
160
|
+
function IR(){}
|
161
|
+
|
162
|
+
// Public methods
|
163
|
+
IR.irImageTag = function(){
|
164
|
+
var args = parseArgs.apply(this, arguments),
|
165
|
+
url = generateEndpoint(args.source, args.modifiers),
|
166
|
+
alt = altTag(url);
|
167
|
+
|
168
|
+
return '<img alt="' + alt + '" src="' + url + '" />';
|
169
|
+
};
|
170
|
+
|
171
|
+
IR.irBackground = function(){
|
172
|
+
var args = parseArgs.apply(this, arguments),
|
173
|
+
url = generateEndpoint(args.source, args.modifiers);
|
174
|
+
return 'background-image:url(' + url + ')';
|
175
|
+
};
|
176
|
+
|
177
|
+
IR.irUrl = function(){
|
178
|
+
var args = parseArgs.apply(this, arguments);
|
179
|
+
return generateEndpoint(args.source, args.modifiers);
|
180
|
+
};
|
181
|
+
|
182
|
+
// Public constants
|
183
|
+
IR.modifiers = <%= Image::Resizer::Rails.modifiers.to_json %>;
|
184
|
+
|
185
|
+
IR.CDN = <%= Image::Resizer::Rails.cdn.to_json %>;
|
186
|
+
|
187
|
+
IR.VERSION = <%= Image::Resizer::Rails::VERSION.to_json %>;
|
188
|
+
|
189
|
+
// Alias any methods that have been listed in the config
|
190
|
+
<% unless Image::Resizer::Rails.js_image_tag.nil? %>
|
191
|
+
IR.<%= Image::Resizer::Rails.js_image_tag %> = IR.irImageTag;
|
192
|
+
<% end %>
|
193
|
+
<% unless Image::Resizer::Rails.js_background.nil? %>
|
194
|
+
IR.<%= Image::Resizer::Rails.js_background %> = IR.irBackground;
|
195
|
+
<% end %>
|
196
|
+
<% unless Image::Resizer::Rails.js_url.nil? %>
|
197
|
+
IR.<%= Image::Resizer::Rails.js_url %> = IR.irUrl;
|
198
|
+
<% end %>
|
199
|
+
|
200
|
+
return IR;
|
201
|
+
}));
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'image/resizer/rails/helper'
|
2
|
+
|
3
|
+
module Image
|
4
|
+
module Resizer
|
5
|
+
module Rails
|
6
|
+
# Series of view helpers building url strings for image-resizer endpoints
|
7
|
+
module IrHelper
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
include ::Image::Resizer::Rails::Helper
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'image/resizer/rails/version'
|
2
|
+
require 'image/resizer/rails/helper'
|
3
|
+
require 'image/resizer/rails/engine' if defined?(Rails)
|
4
|
+
|
5
|
+
module Image
|
6
|
+
module Resizer
|
7
|
+
# Top-level module for the image-resizer code
|
8
|
+
module Rails
|
9
|
+
class << self
|
10
|
+
attr_accessor :cdn
|
11
|
+
attr_reader :js_class, :js_image_tag, :js_background, :js_url
|
12
|
+
|
13
|
+
def configure(&block)
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset_config
|
18
|
+
@cdn = nil
|
19
|
+
@ir_image_tag = nil
|
20
|
+
@ir_background = nil
|
21
|
+
@ir_url = nil
|
22
|
+
@js_class = 'ImageResizer'
|
23
|
+
@js_image_tag = nil
|
24
|
+
@js_background = nil
|
25
|
+
@js_url = nil
|
26
|
+
@modifiers = default_modifiers
|
27
|
+
end
|
28
|
+
|
29
|
+
def modifiers
|
30
|
+
@modifiers ||= default_modifiers
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_modifier(key, img_tag = '', values = [])
|
34
|
+
@modifiers[key.to_sym] = { alias: img_tag, values: values }
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_source(name, option)
|
38
|
+
@modifiers[:e][:values][name.to_sym] = option.to_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
def js_class
|
42
|
+
@js_class ||= 'ImageResizer'
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_alias(type, name)
|
46
|
+
Helper.class_eval do |base|
|
47
|
+
base.send(:alias_method, name.to_sym, type.to_sym)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_js_alias(type, name)
|
52
|
+
instance_variable_set "@#{type.to_s}", name
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_hash
|
56
|
+
{
|
57
|
+
cdn: cdn,
|
58
|
+
ir_image_tag: ir_image_tag,
|
59
|
+
ir_background: ir_background,
|
60
|
+
ir_url: ir_url,
|
61
|
+
js_class: js_class,
|
62
|
+
js_image_tag: js_image_tag,
|
63
|
+
js_background: js_background,
|
64
|
+
js_url: js_url,
|
65
|
+
modifiers: modifiers
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def default_modifiers
|
72
|
+
{
|
73
|
+
w: { alias: :width }, h: { alias: :height },
|
74
|
+
s: { alias: :square },
|
75
|
+
c: { alias: :crop, values: %w(fit fill cut scale) },
|
76
|
+
g: { alias: :gravity, values: %w(c n s e w ne nw se sw) },
|
77
|
+
y: { alias: :top }, x: { alias: :left },
|
78
|
+
e: { alias: :external, values: default_sources },
|
79
|
+
f: { alias: :filter }
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def default_sources
|
84
|
+
{
|
85
|
+
facebook: :fb_uid,
|
86
|
+
twitter: :tw_uid,
|
87
|
+
youtube: :youtube_id,
|
88
|
+
vimeo: :vimeo_id
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Image
|
4
|
+
module Resizer
|
5
|
+
module Rails
|
6
|
+
# Series of view helpers building url strings for image-resizer endpoints
|
7
|
+
module Helper
|
8
|
+
def ir_image_tag(*args)
|
9
|
+
src = generate_ir_endpoint(args)
|
10
|
+
if respond_to?(:image_tag)
|
11
|
+
image_tag src
|
12
|
+
else
|
13
|
+
"<img src='#{src}' />"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def ir_background(*args)
|
18
|
+
url = generate_ir_endpoint(args)
|
19
|
+
"background-image:url(#{url})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def ir_url(*args)
|
23
|
+
generate_ir_endpoint(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_arguments(args)
|
29
|
+
if args[0].is_a?(String)
|
30
|
+
[args[0], args[1..-1]]
|
31
|
+
else
|
32
|
+
[nil, args]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cdn
|
37
|
+
::Image::Resizer::Rails.cdn
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.img_tag_name
|
41
|
+
::Image::Resizer::Rails.image_tag_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def mods
|
45
|
+
::Image::Resizer::Rails.modifiers
|
46
|
+
end
|
47
|
+
|
48
|
+
def mod_set(key)
|
49
|
+
mods.each do |k, v|
|
50
|
+
return v if key == k || v[:alias] == key
|
51
|
+
end
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def sources
|
56
|
+
mods[:e][:values]
|
57
|
+
end
|
58
|
+
|
59
|
+
def source_option(key)
|
60
|
+
sources.each do |k, v|
|
61
|
+
return [k, v] if key == v
|
62
|
+
end
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def generate_ir_endpoint(args)
|
67
|
+
fail NoCDNException if cdn.nil?
|
68
|
+
|
69
|
+
source, modifiers = parse_arguments(args)
|
70
|
+
uri = source ? URI(source) : nil
|
71
|
+
modifier_str = mod_str(uri, modifiers)
|
72
|
+
path = build_path(uri, modifiers)
|
73
|
+
|
74
|
+
"#{cdn.gsub(/\/$/, '')}#{modifier_str}#{path}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def mod_str(uri, modifiers)
|
78
|
+
mod_arr = []
|
79
|
+
unless modifiers.nil? || modifiers[0].nil?
|
80
|
+
mod_arr = build_mod_arr(modifiers)
|
81
|
+
end
|
82
|
+
mod_arr << 'efacebook' if uri && url_domain(uri.host) == :facebook
|
83
|
+
mod_arr.compact
|
84
|
+
mod_arr.length > 0 ? "/#{mod_arr.join('-')}" : ''
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_mod_arr(modifiers)
|
88
|
+
modifiers[0].map do |k, v|
|
89
|
+
mset = mod_set(k)
|
90
|
+
src = source_option(k)
|
91
|
+
if mset
|
92
|
+
if mset.include? :values
|
93
|
+
mset[:values].include?(v) ? "#{k}#{v}" : nil
|
94
|
+
else
|
95
|
+
"#{k}#{v}"
|
96
|
+
end
|
97
|
+
elsif src
|
98
|
+
"e#{src.first}"
|
99
|
+
else
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_path(uri, modifiers)
|
106
|
+
if uri
|
107
|
+
case url_domain(uri.host)
|
108
|
+
when :s3
|
109
|
+
s3_object uri
|
110
|
+
when :facebook
|
111
|
+
"/#{fb_uid(uri)}.jpg"
|
112
|
+
else
|
113
|
+
end
|
114
|
+
else
|
115
|
+
modifiers[0].each do |k, v|
|
116
|
+
return "/#{v}.jpg" if source_option(k)
|
117
|
+
end
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def url_domain(host)
|
123
|
+
return :s3 if /s3.amazonaws.com/i =~ host
|
124
|
+
return :facebook if /facebook.com/i =~ host
|
125
|
+
:other
|
126
|
+
end
|
127
|
+
|
128
|
+
def s3_object(uri)
|
129
|
+
# test to see which type of s3 url we have
|
130
|
+
if uri.host == 's3.amazonaws.com'
|
131
|
+
# this version has the bucket at the first part of the path
|
132
|
+
"/#{uri.path.split('/')[2..-1].join('/')}"
|
133
|
+
else
|
134
|
+
# this version has the bucket included in the host
|
135
|
+
uri.path
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def fb_uid(uri)
|
140
|
+
uri.path.split('/')[1]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class NoCDNException < Exception; end
|
145
|
+
class NotS3SourceException < Exception; end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image-resizer-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Nicol
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jasmine
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awesome_print
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Helpers for use with image-resizer service
|
112
|
+
email:
|
113
|
+
- james.andrew.nicol@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- app/assets/javascripts/image_resizer.js.erb
|
119
|
+
- app/helpers/image/resizer/rails/ir_helper.rb
|
120
|
+
- lib/image/resizer/rails/engine.rb
|
121
|
+
- lib/image/resizer/rails/helper.rb
|
122
|
+
- lib/image/resizer/rails/version.rb
|
123
|
+
- lib/image/resizer/rails.rb
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
homepage: https://github.com/jimmynicol/image-resizer-rails
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.0.3
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: View helpers and JS file
|
150
|
+
test_files: []
|