light_resizer 0.0.1 → 0.0.2
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 +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +1 -1
- data/README.md +3 -0
- data/lib/light_resizer/carrierwave_resize.rb +6 -1
- data/lib/light_resizer/image_loader/original_image.rb +39 -0
- data/lib/light_resizer/image_loader/resize_image.rb +50 -0
- data/lib/light_resizer/image_loader.rb +48 -0
- data/lib/light_resizer/middleware/path.rb +49 -0
- data/lib/light_resizer/middleware/resizer.rb +46 -0
- data/lib/light_resizer/middleware.rb +22 -79
- data/lib/light_resizer/version.rb +1 -1
- data/lib/light_resizer.rb +1 -1
- data/light_resizer.gemspec +3 -2
- data/spec/integration/middleware_spec.rb +8 -5
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/image_loader_original_spec.rb +29 -0
- data/spec/unit/image_loader_resized_spec.rb +45 -0
- data/spec/unit/image_loader_spec.rb +23 -0
- data/spec/unit/middleware_path_spec.rb +45 -0
- data/spec/unit/middleware_resizer_spec.rb +35 -0
- metadata +35 -4
- data/spec/unit/middleware_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5e96f10cbc75a2c4f51fe257b25a9b33285d79a
|
4
|
+
data.tar.gz: 5bcdb15b74a9af11c1b3f7ef8df6dff97ec7c177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e0565d872d65fe21da6fbaab44208d9b5c347f64c58250acdc8a6a70fa264d1bd00606da62dac1fb763c9010be3b181e4c75f816bea22e5e4c6c9c21b267876
|
7
|
+
data.tar.gz: 22bf31bc915d97b05fde9db94fa5d903860fbba7b95b2e931190be791d74787d9fd96e5f400a7f50c680b869892241f3621bcbaaea72df8007972daf8c8556dc
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module LightResizer
|
2
2
|
module CarrierWaveResize
|
3
3
|
def resize(width, height)
|
4
|
-
start = "/
|
4
|
+
start = "/resize_image/#{width}x#{height}"
|
5
|
+
File.join(start, url)
|
6
|
+
end
|
7
|
+
|
8
|
+
def resize_crop(width, height)
|
9
|
+
start = "/resize_image_crop/#{width}x#{height}"
|
5
10
|
File.join(start, url)
|
6
11
|
end
|
7
12
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LightResizer
|
3
|
+
class ImageLoader
|
4
|
+
class OriginalImage
|
5
|
+
|
6
|
+
attr_accessor :relative_path
|
7
|
+
|
8
|
+
def initialize(root_dir)
|
9
|
+
@root_dir = root_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
# Full original image path /{root}/some_dir/image.png
|
13
|
+
def full_path
|
14
|
+
File.join(@root_dir, relative_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Absolute store /{root}/some_dir
|
18
|
+
def dir_path
|
19
|
+
File.dirname( full_path ).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
# Requested filename /image.png
|
23
|
+
def filename
|
24
|
+
File.basename( full_path ).to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
# Relative file store dir /some_dir/
|
28
|
+
def relative_dir
|
29
|
+
dir_path.gsub(@root_dir, '')
|
30
|
+
end
|
31
|
+
|
32
|
+
# {Bool} original image exist
|
33
|
+
def image_exist?
|
34
|
+
File.exist? full_path
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LightResizer
|
3
|
+
class ImageLoader
|
4
|
+
class ResizeImage
|
5
|
+
|
6
|
+
STORE_RESIZE_DIR = 'resize' #todo move to config option
|
7
|
+
|
8
|
+
attr_accessor :original_filename, :original_relative_dir, :resize_prefix
|
9
|
+
|
10
|
+
def initialize(root_dir)
|
11
|
+
@root_dir = root_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
def resize_prefix_dir
|
15
|
+
STORE_RESIZE_DIR
|
16
|
+
end
|
17
|
+
|
18
|
+
# Resized file name '150x150_image.png'
|
19
|
+
def filename
|
20
|
+
resize_prefix + '_' + original_filename
|
21
|
+
end
|
22
|
+
|
23
|
+
# Relative resize image path '/some_dir/resize/150x150_image.png'
|
24
|
+
def relative_path
|
25
|
+
File.join(original_relative_dir, STORE_RESIZE_DIR, filename)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Absolute image path
|
29
|
+
def full_path
|
30
|
+
File.join(@root_dir, relative_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Absolute resize path {root}/some_dir/resize
|
34
|
+
def dir_path
|
35
|
+
File.dirname full_path
|
36
|
+
end
|
37
|
+
|
38
|
+
# {Bool} returns true if resize dir exist?
|
39
|
+
def dir_exist?
|
40
|
+
Dir.exist? dir_path
|
41
|
+
end
|
42
|
+
|
43
|
+
# {Bool} returns true if resize image exist?
|
44
|
+
def image_exist?
|
45
|
+
File.exist? full_path
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'light_resizer/image_loader/original_image'
|
3
|
+
require 'light_resizer/image_loader/resize_image'
|
4
|
+
|
5
|
+
module LightResizer
|
6
|
+
class ImageLoader
|
7
|
+
|
8
|
+
attr_reader :original, :resized
|
9
|
+
|
10
|
+
def initialize(root_dir)
|
11
|
+
@original = ImageLoader::OriginalImage.new(root_dir)
|
12
|
+
@resized = ImageLoader::ResizeImage.new(root_dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
def original_image_path=(path)
|
16
|
+
#todo refresh @original image
|
17
|
+
@original.relative_path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def resize_prefix=(prefix)
|
21
|
+
#todo clear resize prefix
|
22
|
+
@resized.original_filename = @original.filename
|
23
|
+
@resized.original_relative_dir = @original.relative_dir
|
24
|
+
@resized.resize_prefix = prefix
|
25
|
+
end
|
26
|
+
|
27
|
+
def original_path
|
28
|
+
@original.full_path
|
29
|
+
end
|
30
|
+
|
31
|
+
def original_image_exist?
|
32
|
+
@original.image_exist?
|
33
|
+
end
|
34
|
+
|
35
|
+
def resize_path
|
36
|
+
@resized.full_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def resized_image_relative_path
|
40
|
+
@resized.relative_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def resized_image_exist?
|
44
|
+
@resized.image_exist?
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LightResizer
|
3
|
+
class Middleware
|
4
|
+
class Path
|
5
|
+
|
6
|
+
attr_reader :request_path
|
7
|
+
|
8
|
+
def request_path=(path)
|
9
|
+
@request_path = path
|
10
|
+
@segments = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
# {Bool} returns true if request path begins with 'image'
|
14
|
+
def image_path?
|
15
|
+
segments[1].start_with?('resize_image')
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# {Bool} returns true if image should be croped on resize
|
20
|
+
def crop_path?
|
21
|
+
segments[1].end_with?('crop')
|
22
|
+
end
|
23
|
+
|
24
|
+
# {String} last part of request – relative path
|
25
|
+
def image_path
|
26
|
+
'/' + segments[3..-1].join('/')
|
27
|
+
end
|
28
|
+
|
29
|
+
# {Array} returns required dimensions of image. Like a 200x200
|
30
|
+
def dimensions
|
31
|
+
#todo validate params!
|
32
|
+
segments[2]
|
33
|
+
end
|
34
|
+
|
35
|
+
# {String} returns prefix of resized image name
|
36
|
+
# image.png => 200x200_crop_image.png
|
37
|
+
def prefix
|
38
|
+
crop_prefix = crop_path? ? '_crop' : ''
|
39
|
+
|
40
|
+
dimensions + crop_prefix
|
41
|
+
end
|
42
|
+
|
43
|
+
def segments
|
44
|
+
@segments ||= request_path.split('/')
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LightResizer
|
3
|
+
class Middleware
|
4
|
+
class Resizer
|
5
|
+
|
6
|
+
def resize(dimensions, original_path, resize_path, crop)
|
7
|
+
check_resized_dir(resize_path)
|
8
|
+
store_image(dimensions, original_path, resize_path, crop)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def check_resized_dir(resize_path)
|
13
|
+
dir_name = File.dirname resize_path
|
14
|
+
Dir.mkdir dir_name unless Dir.exist? dir_name
|
15
|
+
#todo permissions?
|
16
|
+
end
|
17
|
+
|
18
|
+
def store_image(dimensions, original_path, resize_path, crop)
|
19
|
+
@image = MiniMagick::Image.open original_path
|
20
|
+
|
21
|
+
crop ? set_crop_options(dimensions) : set_options(dimensions)
|
22
|
+
|
23
|
+
@image.write resize_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_options(dimensions)
|
27
|
+
@image.combine_options do |c|
|
28
|
+
c.resize dimensions
|
29
|
+
c.unsharp '0x1'
|
30
|
+
c.add_command 'extent', dimensions
|
31
|
+
c.gravity 'center'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_crop_options(dimensions)
|
36
|
+
@image.combine_options do |c|
|
37
|
+
c.resize dimensions+'^'
|
38
|
+
c.unsharp '0x1'
|
39
|
+
c.add_command 'extent', dimensions
|
40
|
+
c.gravity 'center'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,98 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'light_resizer/image_loader'
|
3
|
+
require 'light_resizer/middleware/path'
|
4
|
+
require 'light_resizer/middleware/resizer'
|
5
|
+
|
1
6
|
module LightResizer
|
2
7
|
class Middleware
|
8
|
+
|
3
9
|
def initialize(app, root, folder='public')
|
4
|
-
@app_root = root
|
5
|
-
@public_folder = folder
|
6
10
|
@app = app
|
11
|
+
@image_loader = LightResizer::ImageLoader.new File.join(root, folder)
|
12
|
+
@path = LightResizer::Middleware::Path.new
|
13
|
+
@resizer = LightResizer::Middleware::Resizer.new
|
7
14
|
end
|
8
15
|
|
9
16
|
def call(env)
|
10
|
-
@path =
|
11
|
-
@splited_path = nil
|
12
|
-
@env = env
|
13
|
-
handle
|
14
|
-
|
15
|
-
status, headers, response = @app.call(@env)
|
16
|
-
|
17
|
-
[status, headers, response]
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# Handle request.
|
23
|
-
# resizes images and
|
24
|
-
# modificates env
|
25
|
-
def handle
|
26
|
-
if is_image_path?
|
27
|
-
resize! unless image_exist
|
28
|
-
|
29
|
-
modify_path!
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# creates new resized verion of requested image
|
34
|
-
def resize!
|
35
|
-
image = MiniMagick::Image.open(original_path)
|
36
|
-
image.combine_options do |c|
|
37
|
-
c.resize dimensions+'^'
|
38
|
-
c.unsharp '0x1'
|
39
|
-
c.add_command('extent', dimensions)
|
40
|
-
c.gravity 'center'
|
41
|
-
end
|
42
|
-
image.write resized_image_filepath
|
43
|
-
end
|
17
|
+
@path.request_path = env['PATH_INFO']
|
44
18
|
|
45
|
-
|
46
|
-
def image_exist
|
47
|
-
File.exist?(resized_image_filepath)
|
48
|
-
end
|
19
|
+
env['PATH_INFO'] = resize_image_path if @path.image_path? and resize_request?
|
49
20
|
|
50
|
-
|
51
|
-
def modify_path!
|
52
|
-
@env['PATH_INFO'] = resized_image_path
|
21
|
+
@app.call( env )
|
53
22
|
end
|
54
23
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
dir = File.dirname(File.join(splited_path[3..-1]))
|
59
|
-
filename = File.basename(File.join(splited_path[3..-1]))
|
60
|
-
|
61
|
-
dir = '/' if dir == '.'
|
62
|
-
filename = dimensions + '_' + filename
|
63
|
-
|
64
|
-
File.join(dir, filename)
|
65
|
-
end
|
66
|
-
|
67
|
-
# {String} returns full path to resized image
|
68
|
-
# /image/200x200/.../image.png => {APP_ROOT}/{@public_folder}/.../200x200_image.png
|
69
|
-
def resized_image_filepath
|
70
|
-
File.join(@app_root, @public_folder, resized_image_path)
|
71
|
-
end
|
24
|
+
def resize_request?
|
25
|
+
@image_loader.original_image_path = @path.image_path
|
26
|
+
@image_loader.resize_prefix = @path.prefix
|
72
27
|
|
73
|
-
|
74
|
-
def original_path
|
75
|
-
File.join(@app_root, @public_folder, splited_path[3..-1])
|
28
|
+
@image_loader.original_image_exist?
|
76
29
|
end
|
77
30
|
|
78
|
-
|
79
|
-
def path
|
80
|
-
@path ||= @env['PATH_INFO']
|
81
|
-
end
|
82
|
-
|
83
|
-
# {Bool} returns true if request path begins with 'image'
|
84
|
-
def is_image_path?
|
85
|
-
splited_path[1] == 'image'
|
86
|
-
end
|
31
|
+
private
|
87
32
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
33
|
+
def resize_image_path
|
34
|
+
unless @image_loader.resized_image_exist?
|
35
|
+
@resizer.resize(@path.dimensions, @image_loader.original_path, @image_loader.resize_path, @path.crop_path?)
|
36
|
+
end
|
37
|
+
@image_loader.resized_image_relative_path
|
92
38
|
end
|
93
39
|
|
94
|
-
def splited_path
|
95
|
-
@splited_path ||= path.split('/')
|
96
|
-
end
|
97
40
|
end
|
98
41
|
end
|
data/lib/light_resizer.rb
CHANGED
data/light_resizer.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'light_resizer/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "light_resizer"
|
8
8
|
spec.version = LightResizer::VERSION
|
9
|
-
spec.authors = ["Denis Sergienko"]
|
10
|
-
spec.email = ["olol.toor@gmail.com"]
|
9
|
+
spec.authors = ["Denis Sergienko", "Vladislav Melanitskiy"]
|
10
|
+
spec.email = ["olol.toor@gmail.com", "co@rademade.com"]
|
11
11
|
spec.summary = %q{Tiny rack middleware for image resizing.}
|
12
12
|
spec.description = %q{}
|
13
13
|
spec.homepage = "http://github.com/Rademade/light_resizer"
|
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "coveralls"
|
27
28
|
end
|
@@ -3,22 +3,25 @@ require 'spec_helper'
|
|
3
3
|
describe LightResizer::Middleware do
|
4
4
|
let(:app) { AppEmulator.new }
|
5
5
|
let(:resizer) { described_class.new(app, ROOT, 'fixtures') }
|
6
|
-
let(:env) { { 'PATH_INFO' => '/
|
7
|
-
|
6
|
+
let(:env) { { 'PATH_INFO' => '/resize_image/100x160/avatar.png' } }
|
7
|
+
|
8
|
+
let(:resize_relative_path) { '/resize/100x160_avatar.png' } #todo depends for many constant
|
9
|
+
let(:resize_full_path) { File.join(ROOT, 'fixtures', resize_relative_path) }
|
8
10
|
|
9
11
|
after do
|
10
|
-
File.delete
|
12
|
+
File.delete resize_full_path
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'should create resized image' do
|
14
16
|
resizer.call(env)
|
15
17
|
|
16
|
-
expect(
|
18
|
+
expect(resizer.resize_request?).to eq(true)
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'should return right path' do
|
20
22
|
resizer.call(env)
|
21
23
|
|
22
|
-
expect(app.env['PATH_INFO']).to eq(
|
24
|
+
expect(app.env['PATH_INFO']).to eq( resize_relative_path )
|
23
25
|
end
|
26
|
+
|
24
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LightResizer::ImageLoader::OriginalImage do
|
4
|
+
|
5
|
+
let(:root_dir) { File.join(ROOT, 'fixtures') }
|
6
|
+
let(:store_dir) { '/some/dir' }
|
7
|
+
let(:filename) { 'image.png' }
|
8
|
+
let(:image_full_path) { File.join(root_dir, store_dir, filename) }
|
9
|
+
let(:original_image) { described_class.new root_dir }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
original_image.relative_path = File.join(store_dir, filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'path methods' do
|
16
|
+
|
17
|
+
it { expect(original_image.send(:full_path)).to eq(image_full_path) }
|
18
|
+
|
19
|
+
it { expect(original_image.send(:dir_path)).to eq( File.join(root_dir, store_dir) ) }
|
20
|
+
|
21
|
+
it { expect(original_image.send(:filename)).to eq( filename ) }
|
22
|
+
|
23
|
+
it { expect(original_image.send(:relative_dir)).to eq(store_dir) }
|
24
|
+
|
25
|
+
it { expect(original_image.send(:image_exist?)).to eq(false) }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LightResizer::ImageLoader::ResizeImage do
|
4
|
+
|
5
|
+
let(:root_dir) { File.join(ROOT, 'fixtures') }
|
6
|
+
let(:store_dir) { '/some/dir' }
|
7
|
+
let(:original_filename) { 'image.png' }
|
8
|
+
let(:resized_prefix) { '20x20' }
|
9
|
+
let(:resized_image) { described_class.new root_dir }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
resized_image.original_filename = original_filename
|
13
|
+
resized_image.original_relative_dir = store_dir
|
14
|
+
resized_image.resize_prefix = resized_prefix
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'path methods' do
|
18
|
+
|
19
|
+
it {
|
20
|
+
expected_filename = [resized_prefix, '_', original_filename].join('')
|
21
|
+
expect(resized_image.send(:filename)).to eq( expected_filename )
|
22
|
+
}
|
23
|
+
|
24
|
+
it {
|
25
|
+
expected_path = File.join(store_dir, resized_image.resize_prefix_dir, resized_image.filename)
|
26
|
+
expect(resized_image.send(:relative_path)).to eq( expected_path )
|
27
|
+
}
|
28
|
+
|
29
|
+
it {
|
30
|
+
expected_path = File.join(root_dir, resized_image.relative_path )
|
31
|
+
expect(resized_image.send(:full_path)).to eq( expected_path )
|
32
|
+
}
|
33
|
+
|
34
|
+
it {
|
35
|
+
expected_path = File.join(root_dir, store_dir, resized_image.resize_prefix_dir )
|
36
|
+
expect(resized_image.send(:dir_path)).to eq( expected_path )
|
37
|
+
}
|
38
|
+
|
39
|
+
it { expect(resized_image.send(:dir_exist?)).to eq(false) }
|
40
|
+
|
41
|
+
it { expect(resized_image.send(:image_exist?)).to eq(false) }
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LightResizer::ImageLoader do
|
4
|
+
|
5
|
+
let(:root_dir) { File.join(ROOT, 'fixtures') }
|
6
|
+
let(:image_loader) { described_class.new root_dir }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
image_loader.original_image_path = '/some/dir/image.png'
|
10
|
+
image_loader.resize_prefix = '20x20'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'image loader methods' do
|
14
|
+
|
15
|
+
it { expect(image_loader.send(:original_image_exist?)).to eq(false) }
|
16
|
+
|
17
|
+
it { expect(image_loader.send(:resized_image_relative_path)).to eq('/some/dir/resize/20x20_image.png') }
|
18
|
+
|
19
|
+
it { expect(image_loader.send(:resized_image_exist?)).to eq(false) }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LightResizer::Middleware::Path do
|
4
|
+
|
5
|
+
let(:path) { described_class.new }
|
6
|
+
|
7
|
+
context 'valid path methods' do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
path.request_path = '/resize_image/150x150/some_dir/image.png'
|
11
|
+
end
|
12
|
+
|
13
|
+
it { expect(path.image_path?).to eq(true) }
|
14
|
+
|
15
|
+
it { expect(path.image_path).to eq('/some_dir/image.png') }
|
16
|
+
|
17
|
+
it { expect(path.dimensions).to eq('150x150') }
|
18
|
+
|
19
|
+
it { expect(path.prefix).to eq('150x150') }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'resize with crop' do
|
24
|
+
before(:each) do
|
25
|
+
path.request_path = '/resize_image_crop/150x150/some_dir/image.png'
|
26
|
+
end
|
27
|
+
|
28
|
+
it { expect(path.crop_path?).to be_true }
|
29
|
+
|
30
|
+
it { expect(path.dimensions).to eq('150x150') }
|
31
|
+
|
32
|
+
it { expect(path.prefix).to eq('150x150_crop') }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'wrong path methods' do
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
path.request_path = '/asdada/123acad/some_dir/imdage.png'
|
39
|
+
end
|
40
|
+
|
41
|
+
it { expect(path.image_path?).to eq(false) }
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LightResizer::Middleware::Resizer do
|
4
|
+
|
5
|
+
let(:resizer) { described_class.new }
|
6
|
+
let(:image_path) { File.join(ROOT, 'fixtures', 'avatar.png') }
|
7
|
+
let(:resize_image_path) { File.join(ROOT, 'fixtures', 'resize', image_name) }
|
8
|
+
|
9
|
+
context 'resize' do
|
10
|
+
|
11
|
+
after do
|
12
|
+
File.delete( resize_image_path )
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without crop' do
|
16
|
+
let(:image_name) { '50x50_avatar.png' }
|
17
|
+
|
18
|
+
it 'should create resized image file' do
|
19
|
+
resizer.resize('50x50', image_path, resize_image_path, false)
|
20
|
+
expect(File.exist?(resize_image_path)).to eq(true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with crop' do
|
25
|
+
let(:image_name) { '50x50_crop_avatar.png' }
|
26
|
+
|
27
|
+
it 'should create resized image file' do
|
28
|
+
resizer.resize('50x50', image_path, resize_image_path, true)
|
29
|
+
expect(File.exist?(resize_image_path)).to eq(true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light_resizer
|
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
|
- Denis Sergienko
|
8
|
+
- Vladislav Melanitskiy
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: mini_magick
|
@@ -80,28 +81,54 @@ dependencies:
|
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: coveralls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
83
98
|
description: ''
|
84
99
|
email:
|
85
100
|
- olol.toor@gmail.com
|
101
|
+
- co@rademade.com
|
86
102
|
executables: []
|
87
103
|
extensions: []
|
88
104
|
extra_rdoc_files: []
|
89
105
|
files:
|
106
|
+
- ".coveralls.yml"
|
90
107
|
- ".gitignore"
|
91
108
|
- ".rspec"
|
109
|
+
- ".travis.yml"
|
92
110
|
- Gemfile
|
93
111
|
- LICENSE.txt
|
94
112
|
- README.md
|
95
113
|
- Rakefile
|
96
114
|
- lib/light_resizer.rb
|
97
115
|
- lib/light_resizer/carrierwave_resize.rb
|
116
|
+
- lib/light_resizer/image_loader.rb
|
117
|
+
- lib/light_resizer/image_loader/original_image.rb
|
118
|
+
- lib/light_resizer/image_loader/resize_image.rb
|
98
119
|
- lib/light_resizer/middleware.rb
|
120
|
+
- lib/light_resizer/middleware/path.rb
|
121
|
+
- lib/light_resizer/middleware/resizer.rb
|
99
122
|
- lib/light_resizer/version.rb
|
100
123
|
- light_resizer.gemspec
|
101
124
|
- spec/fixtures/avatar.png
|
102
125
|
- spec/integration/middleware_spec.rb
|
103
126
|
- spec/spec_helper.rb
|
104
|
-
- spec/unit/
|
127
|
+
- spec/unit/image_loader_original_spec.rb
|
128
|
+
- spec/unit/image_loader_resized_spec.rb
|
129
|
+
- spec/unit/image_loader_spec.rb
|
130
|
+
- spec/unit/middleware_path_spec.rb
|
131
|
+
- spec/unit/middleware_resizer_spec.rb
|
105
132
|
homepage: http://github.com/Rademade/light_resizer
|
106
133
|
licenses:
|
107
134
|
- MIT
|
@@ -130,5 +157,9 @@ test_files:
|
|
130
157
|
- spec/fixtures/avatar.png
|
131
158
|
- spec/integration/middleware_spec.rb
|
132
159
|
- spec/spec_helper.rb
|
133
|
-
- spec/unit/
|
160
|
+
- spec/unit/image_loader_original_spec.rb
|
161
|
+
- spec/unit/image_loader_resized_spec.rb
|
162
|
+
- spec/unit/image_loader_spec.rb
|
163
|
+
- spec/unit/middleware_path_spec.rb
|
164
|
+
- spec/unit/middleware_resizer_spec.rb
|
134
165
|
has_rdoc:
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe LightResizer::Middleware do
|
4
|
-
let(:app) { AppEmulator.new }
|
5
|
-
let(:resizer) { described_class.new(app, ROOT, 'fixtures') }
|
6
|
-
let(:path) { File.join(ROOT, 'fixtures', '20x20_avatar.png') }
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
resizer.call(env)
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'path methods' do
|
13
|
-
after do
|
14
|
-
File.delete(path)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:env) { { 'PATH_INFO' => '/image/20x20/avatar.png' } }
|
18
|
-
|
19
|
-
it { expect(resizer.send(:splited_path)).to eq(['', 'image', '20x20', 'avatar.png']) }
|
20
|
-
|
21
|
-
it { expect(resizer.send(:dimensions)).to eq('20x20') }
|
22
|
-
|
23
|
-
it { expect(resizer.send(:is_image_path?)).to eq(true) }
|
24
|
-
|
25
|
-
it { expect(resizer.send(:path)).to eq('/image/20x20/avatar.png') }
|
26
|
-
|
27
|
-
it { expect(resizer.send(:original_path)).to eq(File.join(ROOT, 'fixtures', 'avatar.png')) }
|
28
|
-
|
29
|
-
it { expect(resizer.send(:resized_image_filepath)).to eq(path) }
|
30
|
-
|
31
|
-
it { expect(resizer.send(:resized_image_path)).to eq('/20x20_avatar.png') }
|
32
|
-
|
33
|
-
it { expect(resizer.send(:image_exist)).to eq(true) }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with non image path' do
|
37
|
-
|
38
|
-
let(:env) { { 'PATH_INFO' => '/lalala/20x20/avatar.png' } }
|
39
|
-
|
40
|
-
it { expect(resizer.send(:is_image_path?)).to eq(false) }
|
41
|
-
end
|
42
|
-
end
|