paperclip-meta 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87d602bc919395b882cfca317ccfb2ab02b69e98
4
- data.tar.gz: c47a819d68995c5a2023bf4c6c68ad2a821a9713
3
+ metadata.gz: 7e36414c9d1d67bd4c52d90b1ebef4e61dacaa3d
4
+ data.tar.gz: 404a380bcfba1fb3a592022d2b9a1d7e25e0a512
5
5
  SHA512:
6
- metadata.gz: 003cca26c110f4b95373db5500d0257523d0006d1508b880ec063d1590f69bead4b3ad326805a1e5bb0507101db9ad63b891f1458a182c234ee626e1988becdb
7
- data.tar.gz: c4a1a5c6778cbf778614542641c5382473f17a861eb719d0bf3c580e4e08c57fe09daf3c9c990b8437966b67dd4f8b585a69da718d70825ce68828318ebd0383
6
+ metadata.gz: 09d94966b9b47d6299fbd31f57811cfc8bb7c40973e89d37aea473ca38d34cb91646790bde29f1dde7f5fc3e6f9a9a7c5bb4362411db6faa29a1ede87f6d9fb9
7
+ data.tar.gz: f3c1adadc65147c11b6d6e08da2d9183e69f75eb47075c510845c449689857e978c31d7810e7b0e607113eac5cc9341be56683146f0655758e04108a52b07a8a
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .bundle
2
+ .ruby-version
2
3
  Gemfile.lock
3
4
  pkg/*
4
5
  spec/gemfiles/*.lock
data/.travis.yml CHANGED
@@ -1,11 +1,13 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
1
4
  rvm:
5
+ - 2.2
2
6
  - 2.1
3
7
  - 2.0.0
4
8
  - 1.9.3
5
- - rbx-2
6
9
  gemfile:
7
10
  - spec/gemfiles/Gemfile.paperclip-4
8
11
  - spec/gemfiles/Gemfile.paperclip-3
9
- matrix:
10
- allow_failures:
11
- - rvm: rbx-2
12
+ install:
13
+ - bundle install --retry=3
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Paperclip Meta
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/paperclip-meta.png)](http://badge.fury.io/rb/paperclip-meta)
4
- [![Build Status](https://travis-ci.org/teeparham/paperclip-meta.png)](https://travis-ci.org/teeparham/paperclip-meta)
3
+ [![Gem Version](https://badge.fury.io/rb/paperclip-meta.svg)](http://rubygems.org/gems/paperclip-meta)
4
+ [![Build Status](https://travis-ci.org/teeparham/paperclip-meta.svg?branch=master)](https://travis-ci.org/teeparham/paperclip-meta)
5
5
 
6
6
  Add width, height, and size to paperclip images.
7
7
 
@@ -31,10 +31,10 @@ Rebuild all thumbnails to populate the meta column if you already have some atta
31
31
 
32
32
  Now you can grab the size from the paperclip attachment:
33
33
 
34
- ```
35
- <%= image_tag user.avatar.url, size: user.avatar.image_size %>
36
- <%= image_tag user.avatar.url(:medium), size: user.avatar.image_size(:medium) %>
37
- <%= image_tag user.avatar.url(:thumb), size: user.avatar.image_size(:thumb) %>
34
+ ```ruby
35
+ image_tag user.avatar.url, size: user.avatar.image_size
36
+ image_tag user.avatar.url(:medium), size: user.avatar.image_size(:medium)
37
+ image_tag user.avatar.url(:thumb), size: user.avatar.image_size(:thumb)
38
38
  ```
39
39
 
40
40
  ### Internals
@@ -51,15 +51,17 @@ style: {
51
51
 
52
52
  This hash will be marshaled and base64 encoded before writing to model attribute.
53
53
 
54
- `height`, `width`, and `size` methods are provided:
54
+ `height`, `width`, `image_size` and `aspect_ratio` methods are provided:
55
55
 
56
56
  ```ruby
57
57
  user.avatar.width(:thumb)
58
58
  => 100
59
59
  user.avatar.height(:medium)
60
60
  => 200
61
- user.avatar.size
61
+ user.avatar.image_size
62
62
  => '60x70'
63
+ user.avatar.aspect_ratio
64
+ => 1.5
63
65
  ```
64
66
 
65
67
  You can pass the image style to these methods. If a style is not passed, the default style will be used.
@@ -39,6 +39,10 @@ module Paperclip
39
39
  read_meta style, :width
40
40
  end
41
41
 
42
+ def aspect_ratio(style = default_style)
43
+ width(style).to_f / height(style).to_f
44
+ end
45
+
42
46
  # Return image dimesions ("WxH") for given style name. If style name not given,
43
47
  # return dimesions for default_style.
44
48
  def image_size(style = default_style)
@@ -1,23 +1,23 @@
1
1
  require 'paperclip-meta'
2
2
 
3
3
  module Paperclip
4
- module Meta
5
-
6
- if defined? ::Rails::Railtie
7
- class Railtie < ::Rails::Railtie
8
- initializer :paperclip_meta do
9
- ActiveSupport.on_load :active_record do
10
- Paperclip::Meta::Railtie.insert
11
- end
4
+ module Meta
5
+
6
+ if defined? ::Rails::Railtie
7
+ class Railtie < ::Rails::Railtie
8
+ initializer :paperclip_meta do
9
+ ActiveSupport.on_load :active_record do
10
+ Paperclip::Meta::Railtie.insert
12
11
  end
13
12
  end
14
13
  end
14
+ end
15
15
 
16
- class Railtie
17
- def self.insert
18
- Paperclip::Attachment.send(:include, Paperclip::Meta::Attachment)
19
- end
16
+ class Railtie
17
+ def self.insert
18
+ Paperclip::Attachment.send(:include, Paperclip::Meta::Attachment)
20
19
  end
20
+ end
21
21
 
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Meta
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -23,8 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency "bundler", "~> 1.5"
25
25
  s.add_development_dependency "rake", "~> 10.1"
26
- s.add_development_dependency "minitest", "~> 4.7"
27
26
  s.add_development_dependency "mocha", "~> 1.0"
28
- s.add_development_dependency "activerecord", "~> 4.0"
29
- s.add_development_dependency "sqlite3", "~> 1.3"
27
+ s.add_development_dependency "activerecord", ">= 4.0"
28
+ s.add_development_dependency "sqlite3", ">= 1.3.10"
30
29
  end
@@ -8,6 +8,7 @@ describe "Attachment" do
8
8
  assert_equal geometry.width, img.small_image.width
9
9
  assert_equal geometry.height, img.small_image.height
10
10
  assert_equal "50x64", img.small_image.image_size
11
+ assert_equal (50.0 / 64.0), img.small_image.aspect_ratio
11
12
  end
12
13
 
13
14
  it "saves geometry for styles" do
@@ -116,6 +117,9 @@ describe "Attachment" do
116
117
  assert_equal "50x64", img.big_image.image_size
117
118
  assert_equal "100x100", img.big_image.image_size(:thumb)
118
119
  assert_equal "500x500", img.big_image.image_size(:large)
120
+ assert_equal (50.0 / 64.0), img.big_image.aspect_ratio
121
+ assert_equal (100.0 / 100.0), img.big_image.aspect_ratio(:thumb)
122
+ assert_equal (500.0 / 500.0), img.big_image.aspect_ratio(:large)
119
123
  end
120
124
 
121
125
  private
@@ -12,4 +12,6 @@ end
12
12
  # See paperclip-meta.gemspec
13
13
  gemspec path: '../..'
14
14
 
15
+ gem 'activerecord', '~> 4.0.0'
16
+ gem 'minitest', '~> 4.7'
15
17
  gem 'paperclip', '~> 3.5'
@@ -12,4 +12,6 @@ end
12
12
  # See paperclip-meta.gemspec
13
13
  gemspec path: '../..'
14
14
 
15
+ gem 'activerecord', '~> 4.1'
16
+ gem 'minitest', '~> 5.3'
15
17
  gem 'paperclip', '~> 4.0'
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: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Bondar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-27 00:00:00.000000000 Z
12
+ date: 2015-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -59,20 +59,6 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.1'
62
- - !ruby/object:Gem::Dependency
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
62
  - !ruby/object:Gem::Dependency
77
63
  name: mocha
78
64
  requirement: !ruby/object:Gem::Requirement
@@ -91,30 +77,30 @@ dependencies:
91
77
  name: activerecord
92
78
  requirement: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '4.0'
97
83
  type: :development
98
84
  prerelease: false
99
85
  version_requirements: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - "~>"
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
89
  version: '4.0'
104
90
  - !ruby/object:Gem::Dependency
105
91
  name: sqlite3
106
92
  requirement: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - "~>"
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: '1.3'
96
+ version: 1.3.10
111
97
  type: :development
112
98
  prerelease: false
113
99
  version_requirements: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - "~>"
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
- version: '1.3'
103
+ version: 1.3.10
118
104
  description: Add width, height and size methods to paperclip images
119
105
  email:
120
106
  - y8@ya.ru
@@ -124,7 +110,6 @@ extensions: []
124
110
  extra_rdoc_files: []
125
111
  files:
126
112
  - ".gitignore"
127
- - ".ruby-version"
128
113
  - ".travis.yml"
129
114
  - Gemfile
130
115
  - LICENSE.txt
@@ -163,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
148
  version: '0'
164
149
  requirements: []
165
150
  rubyforge_project:
166
- rubygems_version: 2.2.2
151
+ rubygems_version: 2.4.6
167
152
  signing_key:
168
153
  specification_version: 4
169
154
  summary: Add width, height, and size to paperclip images
@@ -176,4 +161,3 @@ test_files:
176
161
  - spec/gemfiles/Gemfile.paperclip-4
177
162
  - spec/schema.rb
178
163
  - spec/spec_helper.rb
179
- has_rdoc:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.1.1