thumbor-versionable 0.2.3 → 0.2.4
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/.rubocop.yml +0 -31
- data/README.md +1 -1
- data/lib/versionable/version.rb +22 -4
- data/lib/versionable.rb +2 -2
- data/spec/image_spec.rb +5 -5
- data/spec/version_spec.rb +26 -9
- 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: 6f82b68991d1d6f29cb3153c40fd9305374ed286
|
4
|
+
data.tar.gz: bf1c30ea332c410b95a854ea094ff1d9855f6a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 211c0713a1e5ee18d498c68cd0f0a4b65176b96f45fbd2e201a202572cc0a19826a4804c9575c2d53c469812d04fd79565fc0d80c129fe1049e39c381d4cb6b3
|
7
|
+
data.tar.gz: 881fb2d23a4f37f1bb56bb27e8f536e569b1d11a5589d1a1ec4be893e5cecf729af932fbd29b247a2508a0b59be638856abd1a683457a8cb0a32d5392cb98c4a
|
data/.rubocop.yml
CHANGED
@@ -3,10 +3,6 @@ AllCops:
|
|
3
3
|
- 'vendor/**/*'
|
4
4
|
- 'spec/fixtures/**/*'
|
5
5
|
|
6
|
-
Style/AlignHash:
|
7
|
-
EnforcedHashRocketStyle: separator
|
8
|
-
EnforcedColonStyle: separator
|
9
|
-
|
10
6
|
Style/CollectionMethods:
|
11
7
|
# Mapping from undesired method to desired_method
|
12
8
|
# e.g. to use `detect` over `find`:
|
@@ -21,11 +17,6 @@ Style/CollectionMethods:
|
|
21
17
|
detect: 'find'
|
22
18
|
select: 'find_all'
|
23
19
|
|
24
|
-
Style/GuardClause:
|
25
|
-
Description: "Check for conditionals that can be replaced with guard clauses"
|
26
|
-
StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals"
|
27
|
-
Enabled: true
|
28
|
-
|
29
20
|
# I don't want to write documentation for every class
|
30
21
|
Style/Documentation:
|
31
22
|
Description: "Document classes and non-namespace modules."
|
@@ -62,33 +53,11 @@ Style/ClassCheck:
|
|
62
53
|
Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.'
|
63
54
|
Enabled: false
|
64
55
|
|
65
|
-
Metrics/AbcSize:
|
66
|
-
Description: >-
|
67
|
-
A calculated magnitude based on number of assignments,
|
68
|
-
branches, and conditions.
|
69
|
-
Enabled: false
|
70
|
-
|
71
|
-
Metrics/LineLength:
|
72
|
-
Description: 'Limit lines to 100 characters.'
|
73
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
|
74
|
-
Enabled: true
|
75
|
-
Max: 100
|
76
|
-
|
77
|
-
Style/AlignHash:
|
78
|
-
Description: >-
|
79
|
-
Align the elements of a hash literal if they span more than
|
80
|
-
one line.
|
81
|
-
Enabled: false
|
82
|
-
|
83
56
|
Style/TrailingBlankLines:
|
84
57
|
Description: 'Checks trailing blank lines and final newline.'
|
85
58
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof'
|
86
59
|
Enabled: false
|
87
60
|
|
88
|
-
Style/IndentHash:
|
89
|
-
Description: 'Checks the indentation of the first key in a hash literal.'
|
90
|
-
Enabled: false
|
91
|
-
|
92
61
|
Lint/UnusedMethodArgument:
|
93
62
|
Description: 'Checks for unused method arguments.'
|
94
63
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ thumbor-versionable can be installed to use with any Ruby web framework. The fir
|
|
22
22
|
Or include it in your project's Gemfile with Bundler:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
gem 'thumbor-versionable',
|
25
|
+
gem 'thumbor-versionable', '~> 0.2.3'
|
26
26
|
```
|
27
27
|
|
28
28
|
If you are using rails, that's it! if you are using anything else you will have to require the gem whenever you want to use it.
|
data/lib/versionable/version.rb
CHANGED
@@ -8,6 +8,8 @@ module Versionable
|
|
8
8
|
SMART = 'smart'.freeze
|
9
9
|
UNSAFE = 'unsafe'.freeze
|
10
10
|
META = 'meta'.freeze
|
11
|
+
HALIGNEMENTS = %w(left center right).freeze
|
12
|
+
VALIGNEMENTS = %w(top middle bottom).freeze
|
11
13
|
|
12
14
|
attr_reader :width, :height
|
13
15
|
def initialize(image, parameters, &blk)
|
@@ -32,10 +34,8 @@ module Versionable
|
|
32
34
|
|
33
35
|
def calculate_metadata
|
34
36
|
{
|
35
|
-
|
36
|
-
|
37
|
-
height: @height = height != 0 ? height : (image.height * width) / \
|
38
|
-
image.width
|
37
|
+
width: calculate_width,
|
38
|
+
height: calculate_height
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
@@ -43,12 +43,22 @@ module Versionable
|
|
43
43
|
|
44
44
|
attr_reader :image, :fit_in, :smart, :filters
|
45
45
|
|
46
|
+
def calculate_width
|
47
|
+
@width = width != 0 ? width : (image.width * height) / image.height
|
48
|
+
end
|
49
|
+
|
50
|
+
def calculate_height
|
51
|
+
@height = height != 0 ? height : (image.height * width) / image.width
|
52
|
+
end
|
53
|
+
|
46
54
|
def options_url
|
47
55
|
[
|
48
56
|
meta,
|
49
57
|
crop,
|
50
58
|
fit_in,
|
51
59
|
measurements,
|
60
|
+
horizontal_align,
|
61
|
+
vertical_align,
|
52
62
|
smart,
|
53
63
|
filters,
|
54
64
|
decoded_url
|
@@ -69,6 +79,14 @@ module Versionable
|
|
69
79
|
@filters << { name => values }
|
70
80
|
end
|
71
81
|
|
82
|
+
def horizontal_align(value = nil)
|
83
|
+
value && HALIGNEMENTS.include?("#{value}") ? @halign = value : @halign
|
84
|
+
end
|
85
|
+
|
86
|
+
def vertical_align(value = nil)
|
87
|
+
value && VALIGNEMENTS.include?("#{value}") ? @valign = value : @valign
|
88
|
+
end
|
89
|
+
|
72
90
|
# Serves as getter and setter.
|
73
91
|
def crop(hash = {})
|
74
92
|
if hash.empty?
|
data/lib/versionable.rb
CHANGED
@@ -3,7 +3,7 @@ module Versionable
|
|
3
3
|
attr_reader :config
|
4
4
|
|
5
5
|
def version
|
6
|
-
'0.2.
|
6
|
+
'0.2.4'
|
7
7
|
end
|
8
8
|
|
9
9
|
def configure(&blk)
|
@@ -21,7 +21,7 @@ module Versionable
|
|
21
21
|
def versionable(accessor, column, &blk)
|
22
22
|
instance_eval <<-EOF
|
23
23
|
define_method(accessor) do
|
24
|
-
@#{accessor} ||=
|
24
|
+
@#{accessor} ||= Image.new(self, :#{column}, :#{accessor}, &blk)
|
25
25
|
end
|
26
26
|
EOF
|
27
27
|
end
|
data/spec/image_spec.rb
CHANGED
@@ -25,11 +25,11 @@ describe Versionable::Image do
|
|
25
25
|
it 'should be rendered as a json' do
|
26
26
|
expect(image).to respond_to(:to_json)
|
27
27
|
expect(image.to_json).to eq(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
'{"url":"https://s3.amazonaws.com/ksr/assets/moo.png","form_thumbnail":' \
|
29
|
+
'{"url":"http://thumbor_server.net/JCvCnwX3k3NBcHOF_HICTy9dEk8=/100x150' \
|
30
|
+
'/filters:quality(50)/https://s3.amazonaws.com/ksr/assets/moo.png"},"fo' \
|
31
|
+
'rm_thumbnail_2":{"url":"http://thumbor_server.net/pzNWZlQuWGNjwy2Ix-83' \
|
32
|
+
'Nc4gswY=/100x150/https://s3.amazonaws.com/ksr/assets/moo.png"}}')
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'when the image is valid' do
|
data/spec/version_spec.rb
CHANGED
@@ -1,26 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Versionable::Version do
|
4
|
-
let(:
|
4
|
+
let(:version_full) do
|
5
5
|
described_class.new OpenStruct.new(
|
6
6
|
url: 'https://s3.amazonaws.com/ksr/assets/moo.png'
|
7
|
-
|
7
|
+
), width: 100, height: 150 do
|
8
|
+
crop from: { x: 10, y: 35 }, to: { x: 34, y: 50 }
|
9
|
+
horizontal_align :center
|
10
|
+
vertical_align :top
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
let(:version_empty) do
|
15
|
+
described_class.new OpenStruct.new(
|
16
|
+
url: 'https://s3.amazonaws.com/ksr/assets/moo.png'
|
17
|
+
), {}
|
12
18
|
end
|
13
19
|
|
14
|
-
it '
|
15
|
-
expect(
|
16
|
-
|
17
|
-
|
20
|
+
it 'respond to :url' do
|
21
|
+
expect(version_full).to respond_to(:url)
|
22
|
+
expect(version_empty).to respond_to(:url)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'constructs the url' do
|
26
|
+
expect(version_empty.url).to eq('http://thumbor_server.net/' \
|
27
|
+
'rJFxkUxO6j6rXB3HpjAQN2nNS0g=/0x0/https://s3.amazonaws.co' \
|
28
|
+
'm/ksr/assets/moo.png'
|
29
|
+
)
|
30
|
+
|
31
|
+
expect(version_full.url).to eq(
|
32
|
+
'http://thumbor_server.net/2k_eIg_cVtazzmoB3o_8q4hUlx0=/10x35:' \
|
33
|
+
'34x50/100x150/center/top/https://s3.amazonaws.com/ksr/assets/' \
|
34
|
+
'moo.png'
|
18
35
|
)
|
19
36
|
end
|
20
37
|
|
21
38
|
context 'when the image is valid' do
|
22
39
|
it 'correctly calculate it metadata' do
|
23
|
-
expect(
|
40
|
+
expect(version_full.calculate_metadata).to eq(
|
24
41
|
width: 100, height: 150
|
25
42
|
)
|
26
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thumbor-versionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Justo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|