paperclip-meta 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaa72aa228c4f1d2b1efcb50f2cf3b0d04470ad4
4
+ data.tar.gz: 48ba30bf86c2b7a832bf3001466a31b03cdd31f8
5
+ SHA512:
6
+ metadata.gz: c195bfb171c919f72926f4deb4a64b79e8ffab1cc65b653f68d6c3c139fc62044c9a632e888d645655a8608c4ad07be608dff821bcb1993a652de6c8c000f1ac
7
+ data.tar.gz: b5014f6904e9ddcdcc35995d80ef58d29f0adbae1dc6d632e4f37508b78fee4e2ffaa6b79ecefb48736d69feb6063d4374de813d7b193fa4505fd10394fde927
data/.gitignore CHANGED
@@ -3,4 +3,4 @@
3
3
  .rvmrc
4
4
  Gemfile.lock
5
5
  pkg/*
6
- spec/tmp/*/**
6
+ spec/tmp/*/**
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
2
  - 1.9.3
5
- - rbx-18mode
6
- - rbx-19mode
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - rbx
data/Gemfile CHANGED
@@ -1,8 +1,15 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activerecord-jdbcsqlite3-adapter", :platform => "jruby"
3
+ platforms :jruby do
4
+ gem 'activerecord-jdbcsqlite3-adapter'
5
+ end
4
6
 
5
- # Specify your gem's dependencies in paperclip-meta.gemspec
7
+ platforms :rbx do
8
+ gem 'json'
9
+ gem 'rubysl', '~> 2.0'
10
+ end
11
+
12
+ # See paperclip-meta.gemspec
6
13
  gemspec
7
14
 
8
- gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
15
+ gem 'paperclip'
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Paperclip Meta
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)
5
+
6
+ Add width, height, and size to paperclip images.
7
+
8
+ Paperclip Meta gets image dimensions after post_process_styles using paperclips own Geometry.from_file.
9
+ This should make paperclip-meta storage independent.
10
+
11
+ ### Setup
12
+
13
+ Add paperclip-meta to Gemfile:
14
+
15
+ ```ruby
16
+ gem 'paperclip-meta'
17
+ ```
18
+
19
+ Create migration to add a *_meta column:
20
+
21
+ ```ruby
22
+ class AddMetaToAvatar < ActiveRecord::Migration
23
+ def self.up
24
+ add_column :users, :avatar_meta, :text
25
+ end
26
+
27
+ def self.down
28
+ remove_column :users, :avatar_meta
29
+ end
30
+ end
31
+ ```
32
+
33
+ Rebuild all thumbnails to fill meta column if you already have some attachments.
34
+
35
+ Now you can use meta-magic:
36
+
37
+ ```
38
+ <%= image_tag @user.avatar.url, :size => @user.avatar.image_size %>
39
+ <%= image_tag @user.avatar.url(:medium), :size => @user.avatar.image_size(:medium) %>
40
+ <%= image_tag @user.avatar.url(:thumb), :size => @user.avatar.image_size(:thumb) %>
41
+ ```
42
+
43
+ ### Internals
44
+
45
+ The meta column is simple hash:
46
+
47
+ ```ruby
48
+ :style => {
49
+ :width => 100,
50
+ :height => 100,
51
+ :size => 42000
52
+ }
53
+ ```
54
+
55
+ This hash will be marshaled and base64 encoded before writing to model attribute.
56
+
57
+ Meta methods provided:
58
+ - width `@user.avatar.width(:thumb)`
59
+ - height `@user.avatar.height(:medium)`
60
+ - size `@user.avatar.size`
61
+
62
+ You can pass the image style to these methods. If a style is not passed, default_style will be used.
@@ -1,4 +1,3 @@
1
- require "paperclip"
2
- require "paperclip-meta/version"
1
+ require 'paperclip-meta/version'
3
2
  require 'paperclip-meta/railtie'
4
- require 'paperclip-meta/attachment'
3
+ require 'paperclip-meta/attachment'
@@ -1,14 +1,6 @@
1
1
  module Paperclip
2
2
  module Meta
3
3
  module Attachment
4
- # Use Base64 class if aviliable, to prevent
5
- # ActiveSupport deprecation warnings.
6
- begin
7
- require "base64"
8
- rescue LoadError
9
- Base64 = ActiveSupport::Base64
10
- end
11
-
12
4
  def self.included(base)
13
5
  base.send :include, InstanceMethods
14
6
  base.alias_method_chain :save, :meta_data
@@ -17,60 +9,60 @@ module Paperclip
17
9
  end
18
10
 
19
11
  module InstanceMethods
20
-
21
12
  def save_with_meta_data
22
- if (not @queued_for_delete.empty?) and @queued_for_write.empty?
23
- instance_write(:meta, meta_encode({})) if instance.respond_to?(:"#{name}_meta=")
13
+ if @queued_for_delete.any? && @queued_for_write.empty? && instance.respond_to?(:"#{name}_meta=")
14
+ instance_write(:meta, meta_encode({}))
24
15
  end
25
16
  save_without_meta_data
26
17
  end
27
18
 
28
19
  def post_process_styles_with_meta_data(*style_args)
29
20
  post_process_styles_without_meta_data(*style_args)
21
+ return unless instance.respond_to?(:"#{name}_meta=")
30
22
 
31
- if instance.respond_to?(:"#{name}_meta=")
32
- meta = {}
33
- @queued_for_write.each do |style, file|
34
- begin
35
- geo = Geometry.from_file file
36
- meta[style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => file.size }
37
- rescue Paperclip::Errors::NotIdentifiedByImageMagickError => e
38
- meta[style] = {}
39
- end
40
- end
41
-
42
- unless meta == {}
43
- instance.send("#{name}_meta=", meta_encode(meta))
44
- instance.class.update_all({ "#{name}_meta" => meta_encode(meta) }, instance.class.primary_key => instance.id)
23
+ meta = {}
24
+ @queued_for_write.each do |style, file|
25
+ begin
26
+ geo = Geometry.from_file file
27
+ meta[style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => file.size }
28
+ rescue Paperclip::Errors::NotIdentifiedByImageMagickError
29
+ meta[style] = {}
45
30
  end
46
31
  end
32
+
33
+ return if meta == {}
34
+
35
+ instance.send("#{name}_meta=", meta_encode(meta))
36
+ instance.class
37
+ .where(instance.class.primary_key => instance.id)
38
+ .update_all("#{name}_meta" => meta_encode(meta))
47
39
  end
48
40
 
49
- #Use meta info for style if required
41
+ # Use meta info for style if required
50
42
  def size_with_meta_data(passed_style = nil)
51
43
  passed_style ? meta_read(passed_style, :size) : size_without_meta_data
52
44
  end
53
45
 
54
- # Define meta accessors methods
55
- [:width, :height ].each do |meth|
56
- define_method(meth) do |*args|
57
- style = args.first || default_style
58
- meta_read(style, meth)
59
- end
46
+ def height(*args)
47
+ meta_read((args.first || default_style), :height)
48
+ end
49
+
50
+ def width(*args)
51
+ meta_read((args.first || default_style), :width)
60
52
  end
61
53
 
62
- # Returns image dimesions ("WxH") for given style name. If style name not given,
63
- # returns dimesions for default_style.
54
+ # Return image dimesions ("WxH") for given style name. If style name not given,
55
+ # return dimesions for default_style.
64
56
  def image_size(style = default_style)
65
57
  "#{width(style)}x#{height(style)}"
66
58
  end
67
59
 
68
60
  private
69
61
 
70
- # Returns meta data for given style
62
+ # Return meta data for given style
71
63
  def meta_read(style, item)
72
64
  if instance.respond_to?(:"#{name}_meta") && instance_read(:meta)
73
- if meta = meta_decode(instance_read(:meta))
65
+ if (meta = meta_decode(instance_read(:meta)))
74
66
  meta.key?(style) ? meta[style][item] : nil
75
67
  end
76
68
  end
@@ -3,10 +3,9 @@ require 'paperclip-meta'
3
3
  module Paperclip
4
4
  module Meta
5
5
 
6
- if defined? Rails::Railtie
7
- require 'rails'
8
- class Railtie < Rails::Railtie
9
- initializer 'paperclip_meta.insert_into_active_record' do
6
+ if defined? ::Rails::Railtie
7
+ class Railtie < ::Rails::Railtie
8
+ initializer :paperclip_meta do
10
9
  ActiveSupport.on_load :active_record do
11
10
  Paperclip::Meta::Railtie.insert
12
11
  end
@@ -21,4 +20,4 @@ module Paperclip
21
20
  end
22
21
 
23
22
  end
24
- end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Meta
3
- VERSION = "0.4.3"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -5,28 +5,24 @@ require "paperclip-meta/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "paperclip-meta"
7
7
  s.version = Paperclip::Meta::VERSION
8
- s.authors = ["Alexey Bondar"]
9
- s.email = ["y8@ya.ru"]
10
- s.homepage = "http://github.com/y8/paperclip-meta"
11
- s.summary = %q{Thumbnail dimensions for paperclip}
12
- s.description = %q{Add width, height and size methods to paperclip thumbnails}
13
-
14
- s.rubyforge_project = "paperclip-meta"
8
+ s.authors = ["Alexey Bondar", "Tee Parham"]
9
+ s.email = ["y8@ya.ru", "tee@neighborland.com"]
10
+ s.homepage = "http://github.com/teeparham/paperclip-meta"
11
+ s.summary = %q{Add width, height, and size to paperclip images}
12
+ s.description = %q{Add width, height and size methods to paperclip images}
15
13
 
16
14
  s.files = `git ls-files`.split("\n")
17
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
17
  s.require_paths = ["lib"]
20
18
 
21
- # Development depensencies
22
- s.add_development_dependency "bundler", ">= 1.0.0"
19
+ s.required_ruby_version = ">= 1.9.3"
20
+
21
+ s.add_dependency "paperclip", "~> 3.0"
22
+
23
+ s.add_development_dependency "bundler", "~> 1.5"
23
24
  s.add_development_dependency "rake"
24
- s.add_development_dependency "paperclip"
25
25
  s.add_development_dependency "rspec"
26
- s.add_development_dependency "activerecord"
27
- s.add_development_dependency "activerecord-jdbcsqlite3-adapter" if RUBY_PLATFORM == 'java'
28
- s.add_development_dependency "sqlite3-ruby"
29
-
30
- # Runtime dependencies
31
- s.add_runtime_dependency "paperclip"
26
+ s.add_development_dependency "activerecord", "~> 4.0"
27
+ s.add_development_dependency "sqlite3", "~> 1.3"
32
28
  end
data/spec/schema.rb CHANGED
@@ -1,5 +1,5 @@
1
- ActiveRecord::Schema.define :version => 0 do
2
- create_table "images", :force => true do |t|
1
+ ActiveRecord::Schema.define do
2
+ create_table :images do |t|
3
3
  t.string :small_image_file_name
4
4
  t.string :small_image_content_type
5
5
  t.integer :small_image_updated_at
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,14 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
- Bundler.require(:default, :development)
4
-
5
- # Prepare activerecord
2
+ Bundler.require(:default)
6
3
  require "active_record"
7
4
 
8
- # Connect to sqlite
9
5
  ActiveRecord::Base.establish_connection(
10
- "adapter" => "sqlite3",
11
- "database" => ":memory:"
6
+ adapter: "sqlite3",
7
+ database: ":memory:"
12
8
  )
13
9
 
14
- ActiveRecord::Base.logger = Logger.new(nil)
10
+ ActiveRecord::Base.logger = Logger.new(STDERR) if ENV["VERBOSE"]
11
+
15
12
  load(File.join(File.dirname(__FILE__), 'schema.rb'))
16
13
 
17
14
  ActiveRecord::Base.send(:include, Paperclip::Glue)
metadata CHANGED
@@ -1,144 +1,149 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexey Bondar
8
+ - Tee Parham
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2014-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paperclip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: bundler
16
- requirement: &70167845502500 !ruby/object:Gem::Requirement
17
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
18
31
  requirements:
19
- - - ! '>='
32
+ - - "~>"
20
33
  - !ruby/object:Gem::Version
21
- version: 1.0.0
34
+ version: '1.5'
22
35
  type: :development
23
36
  prerelease: false
24
- version_requirements: *70167845502500
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
25
42
  - !ruby/object:Gem::Dependency
26
43
  name: rake
27
- requirement: &70167845499680 !ruby/object:Gem::Requirement
28
- none: false
44
+ requirement: !ruby/object:Gem::Requirement
29
45
  requirements:
30
- - - ! '>='
46
+ - - ">="
31
47
  - !ruby/object:Gem::Version
32
48
  version: '0'
33
49
  type: :development
34
50
  prerelease: false
35
- version_requirements: *70167845499680
36
- - !ruby/object:Gem::Dependency
37
- name: paperclip
38
- requirement: &70167845514480 !ruby/object:Gem::Requirement
39
- none: false
51
+ version_requirements: !ruby/object:Gem::Requirement
40
52
  requirements:
41
- - - ! '>='
53
+ - - ">="
42
54
  - !ruby/object:Gem::Version
43
55
  version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70167845514480
47
56
  - !ruby/object:Gem::Dependency
48
57
  name: rspec
49
- requirement: &70167845512660 !ruby/object:Gem::Requirement
50
- none: false
58
+ requirement: !ruby/object:Gem::Requirement
51
59
  requirements:
52
- - - ! '>='
60
+ - - ">="
53
61
  - !ruby/object:Gem::Version
54
62
  version: '0'
55
63
  type: :development
56
64
  prerelease: false
57
- version_requirements: *70167845512660
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
58
70
  - !ruby/object:Gem::Dependency
59
71
  name: activerecord
60
- requirement: &70167845509000 !ruby/object:Gem::Requirement
61
- none: false
72
+ requirement: !ruby/object:Gem::Requirement
62
73
  requirements:
63
- - - ! '>='
74
+ - - "~>"
64
75
  - !ruby/object:Gem::Version
65
- version: '0'
76
+ version: '4.0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70167845509000
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '4.0'
69
84
  - !ruby/object:Gem::Dependency
70
- name: sqlite3-ruby
71
- requirement: &70167845523120 !ruby/object:Gem::Requirement
72
- none: false
85
+ name: sqlite3
86
+ requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ! '>='
88
+ - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '0'
90
+ version: '1.3'
77
91
  type: :development
78
92
  prerelease: false
79
- version_requirements: *70167845523120
80
- - !ruby/object:Gem::Dependency
81
- name: paperclip
82
- requirement: &70167845521820 !ruby/object:Gem::Requirement
83
- none: false
93
+ version_requirements: !ruby/object:Gem::Requirement
84
94
  requirements:
85
- - - ! '>='
95
+ - - "~>"
86
96
  - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :runtime
89
- prerelease: false
90
- version_requirements: *70167845521820
91
- description: Add width, height and size methods to paperclip thumbnails
97
+ version: '1.3'
98
+ description: Add width, height and size methods to paperclip images
92
99
  email:
93
100
  - y8@ya.ru
101
+ - tee@neighborland.com
94
102
  executables: []
95
103
  extensions: []
96
104
  extra_rdoc_files: []
97
105
  files:
98
- - .gitignore
99
- - .rspec
100
- - .travis.yml
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
101
110
  - Gemfile
102
- - Gemfile.lock
103
- - README.rdoc
111
+ - README.md
104
112
  - Rakefile
105
- - init.rb
106
113
  - lib/paperclip-meta.rb
107
114
  - lib/paperclip-meta/attachment.rb
108
115
  - lib/paperclip-meta/railtie.rb
109
116
  - lib/paperclip-meta/version.rb
110
117
  - paperclip-meta.gemspec
111
- - rails/init.rb
112
118
  - spec/fixtures/big.jpg
113
119
  - spec/fixtures/big.zip
114
120
  - spec/fixtures/small.png
115
121
  - spec/paperclip-meta/paperclip-meta_spec.rb
116
122
  - spec/schema.rb
117
123
  - spec/spec_helper.rb
118
- homepage: http://github.com/y8/paperclip-meta
124
+ homepage: http://github.com/teeparham/paperclip-meta
119
125
  licenses: []
126
+ metadata: {}
120
127
  post_install_message:
121
128
  rdoc_options: []
122
129
  require_paths:
123
130
  - lib
124
131
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
132
  requirements:
127
- - - ! '>='
133
+ - - ">="
128
134
  - !ruby/object:Gem::Version
129
- version: '0'
135
+ version: 1.9.3
130
136
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
137
  requirements:
133
- - - ! '>='
138
+ - - ">="
134
139
  - !ruby/object:Gem::Version
135
140
  version: '0'
136
141
  requirements: []
137
- rubyforge_project: paperclip-meta
138
- rubygems_version: 1.8.10
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.1
139
144
  signing_key:
140
- specification_version: 3
141
- summary: Thumbnail dimensions for paperclip
145
+ specification_version: 4
146
+ summary: Add width, height, and size to paperclip images
142
147
  test_files:
143
148
  - spec/fixtures/big.jpg
144
149
  - spec/fixtures/big.zip
data/README.rdoc DELETED
@@ -1,55 +0,0 @@
1
- =Paperclip Meta {<img src="https://secure.travis-ci.org/y8/paperclip-meta.png" />}[http://travis-ci.org/y8/paperclip-meta]
2
-
3
-
4
- Simple gem to let paperclip play nice with thumbnails width, height and size.
5
-
6
- Paperclip Meta will get image dimensions right after post_process_styles using paperclips own Geometry.from_file. This should make paperclip-meta storage independent.
7
-
8
- ==Quick Start
9
-
10
- Add paperclip-meta to Gemfile:
11
-
12
- gem 'paperclip-meta'
13
-
14
- Create migration:
15
-
16
- class AddMetaToAvatar < ActiveRecord::Migration
17
- def self.up
18
- add_column :users, :avatar_meta, :text
19
- end
20
-
21
- def self.down
22
- remove_column :users, :avatar_meta
23
- end
24
- end
25
-
26
- Rebuild all thumbnails to fill meta column if you already have some attachments.
27
-
28
- Now you can use meta-magic:
29
-
30
- <%= image_tag @user.avatar.url, :size => @user.avatar.image_size %>
31
- <%= image_tag @user.avatar.url(:medium), :size => @user.avatar.image_size(:medium) %>
32
- <%= image_tag @user.avatar.url(:thumb), :size => @user.avatar.image_size(:thumb) %>
33
-
34
- ==Internals
35
-
36
- Meta column is simple hash:
37
-
38
- :style => {
39
- :width => 100,
40
- :height => 100,
41
- :size => 42000
42
- }
43
-
44
- This hash will be marshaled and base64 encoded before writing to model attribute.
45
-
46
- Meta methods provided:
47
- - width `@user.avatar.width(:thumb)`
48
- - height `@user.avatar.height(:medium)`
49
- - size `@user.avatar.size`
50
-
51
- You can pass thumbnail style to all these methods. If style not passed, default_style will be used.
52
-
53
- ==TODO
54
-
55
- * It will be nice to write some tests. :D
data/init.rb DELETED
@@ -1,4 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "lib", "paperclip-meta")
2
- require 'paperclip-meta/railtie'
3
-
4
- Paperclip::Meta::Railtie.insert
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'paperclip-meta/railtie'
2
- Paperclip::Meta::Railtie.insert