paperclip-meta 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/README.md +25 -0
- data/Rakefile +6 -3
- data/lib/paperclip-meta/version.rb +1 -1
- data/paperclip-meta.gemspec +3 -2
- data/spec/{paperclip-meta/paperclip-meta_spec.rb → attachment_spec.rb} +27 -21
- data/spec/gemfiles/Gemfile.paperclip-3 +15 -0
- data/spec/gemfiles/Gemfile.paperclip-4 +15 -0
- data/spec/spec_helper.rb +29 -8
- metadata +35 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f6874af5f0ccd6241f7bfb4377733e5ac3c0a3
|
4
|
+
data.tar.gz: 0fec2a2421336b03906be6ed5e8ddcf738fa744e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9309a1f582b6065ea645b3baa731c2a554b4f3ff13efeb21c6daaba00bbb6deab35376545b184e089cc3658812b6f20b5e3fa83a1dd808e65a6710f478efd3d
|
7
|
+
data.tar.gz: 750638ff3e27067e02adc6782643d3fe83d64afd4100ee6b685846204dc02442c7e2b4982d896a95e1a0649cf7ed3ffe6ecc2131ed7432325f14a7995d922911
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,8 @@ Add width, height, and size to paperclip images.
|
|
7
7
|
|
8
8
|
Paperclip Meta gets image dimensions after `post_process_styles` using paperclip's `Geometry.from_file`.
|
9
9
|
|
10
|
+
Paperclip Meta works with paperclip versions 3.x and 4.x.
|
11
|
+
|
10
12
|
### Setup
|
11
13
|
|
12
14
|
Add paperclip-meta to Gemfile:
|
@@ -65,3 +67,26 @@ You can pass the image style to these methods. If a style is not passed, the def
|
|
65
67
|
### Alternatives
|
66
68
|
|
67
69
|
https://github.com/thoughtbot/paperclip/wiki/Extracting-image-dimensions
|
70
|
+
|
71
|
+
### Development
|
72
|
+
|
73
|
+
Test:
|
74
|
+
|
75
|
+
```sh
|
76
|
+
bundle
|
77
|
+
rake
|
78
|
+
```
|
79
|
+
|
80
|
+
Test paperclip 3.x:
|
81
|
+
|
82
|
+
```sh
|
83
|
+
BUNDLE_GEMFILE=./spec/gemfiles/Gemfile.paperclip-3 bundle
|
84
|
+
BUNDLE_GEMFILE=./spec/gemfiles/Gemfile.paperclip-3 rake
|
85
|
+
```
|
86
|
+
|
87
|
+
Test paperclip 4.x:
|
88
|
+
|
89
|
+
```sh
|
90
|
+
BUNDLE_GEMFILE=./spec/gemfiles/Gemfile.paperclip-4 bundle
|
91
|
+
BUNDLE_GEMFILE=./spec/gemfiles/Gemfile.paperclip-4 rake
|
92
|
+
```
|
data/Rakefile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require '
|
3
|
-
require 'rspec/core/rake_task'
|
2
|
+
require 'rake/testtask'
|
4
3
|
|
5
|
-
|
4
|
+
Rake::TestTask.new(:spec) do |t|
|
5
|
+
t.libs << 'spec'
|
6
|
+
t.test_files = %w(spec/**/*_spec.rb)
|
7
|
+
t.verbose = false
|
8
|
+
end
|
6
9
|
|
7
10
|
task default: :spec
|
data/paperclip-meta.gemspec
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.required_ruby_version = ">= 1.9.3"
|
20
20
|
|
21
|
-
s.add_dependency "paperclip", "
|
21
|
+
s.add_dependency "paperclip", ">= 3.0.2", "< 5.0"
|
22
22
|
|
23
23
|
s.add_development_dependency "bundler", "~> 1.5"
|
24
24
|
s.add_development_dependency "rake", "~> 10.1"
|
25
|
-
s.add_development_dependency "
|
25
|
+
s.add_development_dependency "minitest", "~> 4.7"
|
26
|
+
s.add_development_dependency "mocha", "~> 1.0"
|
26
27
|
s.add_development_dependency "activerecord", "~> 4.0"
|
27
28
|
s.add_development_dependency "sqlite3", "~> 1.3"
|
28
29
|
end
|
@@ -5,14 +5,14 @@ describe "Attachment" do
|
|
5
5
|
img = Image.create(small_image: small_image)
|
6
6
|
img.reload
|
7
7
|
geometry = geometry_for(small_path)
|
8
|
-
img.small_image.width
|
9
|
-
img.small_image.height
|
8
|
+
assert_equal geometry.width, img.small_image.width
|
9
|
+
assert_equal geometry.height, img.small_image.height
|
10
10
|
end
|
11
11
|
|
12
12
|
it "saves geometry for styles" do
|
13
13
|
img = Image.create(small_image: small_image, big_image: big_image)
|
14
|
-
img.big_image.width(:thumb)
|
15
|
-
img.big_image.height(:thumb)
|
14
|
+
assert_equal 100, img.big_image.width(:thumb)
|
15
|
+
assert_equal 100, img.big_image.height(:thumb)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "sets geometry on update" do
|
@@ -20,8 +20,8 @@ describe "Attachment" do
|
|
20
20
|
img.small_image = small_image
|
21
21
|
img.save
|
22
22
|
geometry = geometry_for(small_path)
|
23
|
-
img.small_image.width
|
24
|
-
img.small_image.height
|
23
|
+
assert_equal geometry.width, img.small_image.width
|
24
|
+
assert_equal geometry.height, img.small_image.height
|
25
25
|
end
|
26
26
|
|
27
27
|
describe 'file size' do
|
@@ -30,42 +30,48 @@ describe "Attachment" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should save file size with meta data ' do
|
33
|
-
path = File.join(File.dirname(__FILE__), "
|
33
|
+
path = File.join(File.dirname(__FILE__), "tmp/fixtures/tmp/thumb/#{@image.id}.jpg")
|
34
34
|
size = File.stat(path).size
|
35
|
-
@image.big_image.size(:thumb)
|
35
|
+
assert_equal size, @image.big_image.size(:thumb)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should access normal paperclip method when no style passed' do
|
39
|
-
@image.big_image.
|
40
|
-
@image.big_image.size
|
39
|
+
@image.big_image.expects size_without_meta_data: 1234
|
40
|
+
assert_equal 1234, @image.big_image.size
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should have access to original file size' do
|
44
|
-
@image.big_image.size
|
44
|
+
assert_equal 37042, @image.big_image.size
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
it "clears geometry fields when image is destroyed" do
|
49
49
|
img = Image.create(small_image: small_image, big_image: big_image)
|
50
|
-
img.big_image.width(:thumb)
|
51
|
-
|
50
|
+
assert_equal 100, img.big_image.width(:thumb)
|
52
51
|
img.big_image = nil
|
53
52
|
img.save!
|
54
|
-
|
55
|
-
img.big_image.width(:thumb).should be_nil
|
53
|
+
assert_nil img.big_image.width(:thumb)
|
56
54
|
end
|
57
55
|
|
58
|
-
it "does not
|
56
|
+
it "does not save when file is not an image" do
|
59
57
|
img = Image.new
|
60
58
|
img.small_image = not_image
|
61
|
-
|
62
|
-
img.small_image.width
|
59
|
+
refute img.save
|
60
|
+
assert_nil img.small_image.width
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns nil attributes when file is not an image" do
|
64
|
+
img = ImageWithNoValidation.new
|
65
|
+
img.small_image = not_image
|
66
|
+
img.save!
|
67
|
+
assert_nil img.small_image.width
|
68
|
+
assert_nil img.small_image.height
|
63
69
|
end
|
64
70
|
|
65
71
|
private
|
66
72
|
|
67
73
|
def small_path
|
68
|
-
File.join(File.dirname(__FILE__), '
|
74
|
+
File.join(File.dirname(__FILE__), 'fixtures', 'small.png')
|
69
75
|
end
|
70
76
|
|
71
77
|
def small_image
|
@@ -77,10 +83,10 @@ describe "Attachment" do
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def big_image
|
80
|
-
File.open(File.join(File.dirname(__FILE__), '
|
86
|
+
File.open(File.join(File.dirname(__FILE__), 'fixtures', 'big.jpg'))
|
81
87
|
end
|
82
88
|
|
83
89
|
def not_image
|
84
|
-
File.open(File.join(File.dirname(__FILE__), '
|
90
|
+
File.open(File.join(File.dirname(__FILE__), 'fixtures', 'big.zip'))
|
85
91
|
end
|
86
92
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
platforms :jruby do
|
4
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
5
|
+
end
|
6
|
+
|
7
|
+
platforms :rbx do
|
8
|
+
gem 'json'
|
9
|
+
gem 'rubysl', '~> 2.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
# See paperclip-meta.gemspec
|
13
|
+
gemspec path: '../..'
|
14
|
+
|
15
|
+
gem 'paperclip', '~> 3.5'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
platforms :jruby do
|
4
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
5
|
+
end
|
6
|
+
|
7
|
+
platforms :rbx do
|
8
|
+
gem 'json'
|
9
|
+
gem 'rubysl', '~> 2.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
# See paperclip-meta.gemspec
|
13
|
+
gemspec path: '../..'
|
14
|
+
|
15
|
+
gem 'paperclip', '~> 4.0'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
Bundler.require(:default)
|
3
|
-
require
|
3
|
+
require 'active_record'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'mocha/setup'
|
4
6
|
|
5
7
|
ActiveRecord::Base.establish_connection(
|
6
8
|
adapter: "sqlite3",
|
@@ -18,15 +20,34 @@ load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
|
18
20
|
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
19
21
|
Paperclip::Meta::Railtie.insert
|
20
22
|
|
23
|
+
I18n.enforce_available_locales = true
|
24
|
+
|
21
25
|
class Image < ActiveRecord::Base
|
22
26
|
has_attached_file :small_image,
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
27
|
+
storage: :filesystem,
|
28
|
+
path: "./spec/tmp/:style/:id.:extension",
|
29
|
+
url: "./spec/tmp/:style/:id.extension"
|
26
30
|
|
27
31
|
has_attached_file :big_image,
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
+
storage: :filesystem,
|
33
|
+
path: "./spec/tmp/fixtures/tmp/:style/:id.:extension",
|
34
|
+
url: "./spec/tmp/fixtures/tmp/:style/:id.extension",
|
35
|
+
styles: { thumb: "100x100#" }
|
36
|
+
|
37
|
+
# paperclip 4.0 requires a validator
|
38
|
+
validates_attachment_content_type :small_image, content_type: /\Aimage/
|
39
|
+
validates_attachment_content_type :big_image, content_type: /\Aimage/
|
40
|
+
end
|
41
|
+
|
42
|
+
class ImageWithNoValidation < ActiveRecord::Base
|
43
|
+
self.table_name = :images
|
44
|
+
|
45
|
+
has_attached_file :small_image,
|
46
|
+
storage: :filesystem,
|
47
|
+
path: "./spec/tmp/:style/:id.:extension",
|
48
|
+
url: "./spec/tmp/:style/:id.extension"
|
49
|
+
|
50
|
+
if Paperclip::VERSION >= "4.0"
|
51
|
+
do_not_validate_attachment_file_type :small_image
|
52
|
+
end
|
32
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Bondar
|
@@ -9,22 +9,28 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.0.2
|
21
|
+
- - "<"
|
19
22
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
23
|
+
version: '5.0'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.0.2
|
31
|
+
- - "<"
|
26
32
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
33
|
+
version: '5.0'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: bundler
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,19 +60,33 @@ dependencies:
|
|
54
60
|
- !ruby/object:Gem::Version
|
55
61
|
version: '10.1'
|
56
62
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
63
|
+
name: minitest
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.7'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: mocha
|
58
78
|
requirement: !ruby/object:Gem::Requirement
|
59
79
|
requirements:
|
60
80
|
- - "~>"
|
61
81
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
82
|
+
version: '1.0'
|
63
83
|
type: :development
|
64
84
|
prerelease: false
|
65
85
|
version_requirements: !ruby/object:Gem::Requirement
|
66
86
|
requirements:
|
67
87
|
- - "~>"
|
68
88
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
89
|
+
version: '1.0'
|
70
90
|
- !ruby/object:Gem::Dependency
|
71
91
|
name: activerecord
|
72
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,10 +135,12 @@ files:
|
|
115
135
|
- lib/paperclip-meta/railtie.rb
|
116
136
|
- lib/paperclip-meta/version.rb
|
117
137
|
- paperclip-meta.gemspec
|
138
|
+
- spec/attachment_spec.rb
|
118
139
|
- spec/fixtures/big.jpg
|
119
140
|
- spec/fixtures/big.zip
|
120
141
|
- spec/fixtures/small.png
|
121
|
-
- spec/
|
142
|
+
- spec/gemfiles/Gemfile.paperclip-3
|
143
|
+
- spec/gemfiles/Gemfile.paperclip-4
|
122
144
|
- spec/schema.rb
|
123
145
|
- spec/spec_helper.rb
|
124
146
|
homepage: http://github.com/teeparham/paperclip-meta
|
@@ -145,9 +167,11 @@ signing_key:
|
|
145
167
|
specification_version: 4
|
146
168
|
summary: Add width, height, and size to paperclip images
|
147
169
|
test_files:
|
170
|
+
- spec/attachment_spec.rb
|
148
171
|
- spec/fixtures/big.jpg
|
149
172
|
- spec/fixtures/big.zip
|
150
173
|
- spec/fixtures/small.png
|
151
|
-
- spec/
|
174
|
+
- spec/gemfiles/Gemfile.paperclip-3
|
175
|
+
- spec/gemfiles/Gemfile.paperclip-4
|
152
176
|
- spec/schema.rb
|
153
177
|
- spec/spec_helper.rb
|