paperclip-defaults 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3@frontend --create
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ notifications:
2
+ recipients:
3
+ - mark@socialreferral.com
4
+ - andre@socialreferral.com
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
8
+ script: "bundle exec rake test"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in paperclip-defaults.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'minitest' do
7
+ watch(%r|^test/test_(.*)\.rb|)
8
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
9
+ watch(%r|^test/test_helper\.rb|) { "test" }
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by SocialReferral
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ Paperclip::Defaults [![Build Status](http://travis-ci.org/socialreferral/paperclip-defaults.png)](http://travis-ci.org/socialreferral/paperclip-defaults)
2
+ ==============
3
+ Configurable Rails application wide defaults for Paperclip.
4
+
5
+ This gem requires Ruby 1.9.2 or 1.9.3
6
+
7
+ Usage
8
+ -----
9
+ Please read the [Paperclip documentation](https://github.com/thoughtbot/paperclip) to learn how to use Paperclip.
10
+
11
+ To use Paperclip::Defaults simply add it to your Gemfile and update config/application.rb or one of your config/environments/ files. In these files you can set the default options Hash for has_attached_file like so:
12
+
13
+ ``` ruby
14
+ config.paperclip_defaults = {default_url: "http://www.example.com/missing.png"}
15
+ ```
16
+
17
+ In addition to allowing you to seet the defaults for Paperclip has_attached_file now accepts a new option: default_asset_url
18
+ When default_asset_url is passed in has_attached_file will determine the URL of the image through the Rails asset pipeline (making use of an asset host if you have set one for your Rails application).
19
+
20
+ Development
21
+ -----------
22
+ - Source hosted on [GitHub](https://github.com)
23
+ - Please report issues and feature requests using [GitHub issues](https://github.com/socialreferral/paperclip-defaults/issues)
24
+
25
+ Pull requests are welcome, please make sure your patches are well tested before contributing. When sending a pull request:
26
+ - Use a topic branch for your change
27
+ - Add tests for your changes using MiniTest::Unit
28
+ - Do not change the version number in the gemspec
29
+
30
+ License
31
+ -------
32
+ Paperclip::Defaults is released under the MIT license.
33
+
34
+ Author
35
+ ------
36
+ [Mark Kremer](https://github.com/mkremer)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/test_*\.rb'
8
+ end
9
+
@@ -0,0 +1,7 @@
1
+ module Paperclip
2
+ module Defaults
3
+ class Raitlie < Rails::Railtie
4
+ config.paperclip_defaults = ActiveSupport::OrderedOptions.new
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Paperclip
2
+ module Defaults
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require "paperclip-defaults/version"
2
+ require "bundler/setup"
3
+
4
+ Bundler.require(:default)
5
+
6
+ require 'paperclip'
7
+
8
+ module Paperclip
9
+ module Defaults
10
+ end
11
+
12
+ module ClassMethods
13
+ alias_method :has_attached_file_without_defaults, :has_attached_file
14
+ def has_attached_file_with_defaults(name, options = {})
15
+ if options[:default_asset_url]
16
+ options[:default_url] = ActionController::Base.new.view_context.asset_path(options[:default_asset_url])
17
+ options.delete(:default_asset_url)
18
+ end
19
+ paperclip_options = ::Rails.application.config.paperclip_defaults.merge(options)
20
+ has_attached_file_without_defaults(name, paperclip_options)
21
+ end
22
+ alias_method :has_attached_file, :has_attached_file_with_defaults
23
+ end
24
+ end
25
+
26
+ require "paperclip-defaults/railtie" if defined?(Rails::Railtie)
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "paperclip-defaults/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "paperclip-defaults"
7
+ s.version = Paperclip::Defaults::VERSION
8
+ s.authors = ["Mark Kremer"]
9
+ s.email = ["mark@socialreferral.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Configurable application wide defaults for Paperclip}
12
+ s.description = %q{Configurable application wide defaults for Paperclip}
13
+
14
+ s.required_ruby_version = '~> 1.9.2'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "minitest"
22
+ s.add_development_dependency "mocha"
23
+ s.add_development_dependency "guard"
24
+ s.add_development_dependency "guard-bundler"
25
+ s.add_development_dependency "guard-minitest"
26
+ s.add_development_dependency "rb-inotify" if RbConfig::CONFIG['target_os'] == 'linux'
27
+ s.add_development_dependency "libnotify" if RbConfig::CONFIG['target_os'] == 'linux'
28
+ s.add_development_dependency "activerecord"
29
+ s.add_development_dependency "sqlite3"
30
+ s.add_development_dependency "rake"
31
+
32
+ s.add_runtime_dependency "paperclip"
33
+ s.add_runtime_dependency "activesupport"
34
+ s.add_runtime_dependency "rails"
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'paperclip-defaults'
2
+ require 'minitest/autorun'
3
+ require 'active_record'
4
+ require 'mocha'
5
+
6
+ include Mocha::API
7
+
8
+ # Define action controller namespace if it does not exist already
9
+ unless defined?(ActionController)
10
+ module ActionController
11
+ end
12
+ end
13
+
14
+ # Create a mock for ActionController::Base unless it already exists
15
+ ActionController.const_set(:Base, mock('action_controller')) unless defined?(ActionController::Base)
16
+
17
+ # Create a mock for Rails unless it already exists
18
+ Object.const_set(:Rails, mock('rails')) unless defined?(Rails)
19
+
20
+ # Include Paperclip in ActiveRecord::Base (this will happen automatically in Rails)
21
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
@@ -0,0 +1,42 @@
1
+ require_relative 'test_helper'
2
+
3
+ class TestPaperclipDefaults < MiniTest::Unit::TestCase
4
+ def setup
5
+ Rails.stubs(:application).returns(mock('application'))
6
+ Rails.application.stubs(:config).returns(mock('config'))
7
+ Rails.application.config.stubs(:paperclip_defaults).returns({})
8
+ end
9
+
10
+ def test_has_attached_file_sets_defaults
11
+ Rails.application.config.stubs(:paperclip_defaults).returns({storage: :fog})
12
+ model = Class.new(ActiveRecord::Base) do
13
+ has_attached_file :image1, default_url: "/unknown.png"
14
+ end
15
+
16
+ expect = {validations: [], default_url: "/unknown.png", storage: :fog}
17
+ assert_equal expect, model.attachment_definitions[:image1]
18
+ end
19
+
20
+ def test_default_asset_url_will_use_action_controller_view_context_to_decide_default_url
21
+ ActionController::Base.stubs(:new).returns(mock('new_action_controller'))
22
+ ActionController::Base.new.stubs(:view_context).returns(mock('view_context'))
23
+ ActionController::Base.new.view_context.stubs(:asset_path).returns('http://www.example.com/unknown.png')
24
+
25
+ model = Class.new(ActiveRecord::Base) do
26
+ has_attached_file :image1, default_asset_url: "unknown.png"
27
+ end
28
+
29
+ expect = {validations: [], default_url: "http://www.example.com/unknown.png"}
30
+ assert_equal expect, model.attachment_definitions[:image1]
31
+ end
32
+
33
+ def test_defaults_will_not_overwrite_explicit_options
34
+ Rails.application.config.stubs(:paperclip_defaults).returns({storage: :fog})
35
+ model = Class.new(ActiveRecord::Base) do
36
+ has_attached_file :image1, default_url: "/unknown.png", storage: :filesystem
37
+ end
38
+
39
+ expect = {validations: [], default_url: "/unknown.png", storage: :filesystem}
40
+ assert_equal expect, model.attachment_definitions[:image1]
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-defaults
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Kremer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &14665200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *14665200
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &14664560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *14664560
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard
38
+ requirement: &14663920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *14663920
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-bundler
49
+ requirement: &14663500 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *14663500
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-minitest
60
+ requirement: &14663000 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *14663000
69
+ - !ruby/object:Gem::Dependency
70
+ name: rb-inotify
71
+ requirement: &14662260 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *14662260
80
+ - !ruby/object:Gem::Dependency
81
+ name: libnotify
82
+ requirement: &14661200 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *14661200
91
+ - !ruby/object:Gem::Dependency
92
+ name: activerecord
93
+ requirement: &14660060 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *14660060
102
+ - !ruby/object:Gem::Dependency
103
+ name: sqlite3
104
+ requirement: &14658000 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *14658000
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake
115
+ requirement: &15287440 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *15287440
124
+ - !ruby/object:Gem::Dependency
125
+ name: paperclip
126
+ requirement: &15286320 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *15286320
135
+ - !ruby/object:Gem::Dependency
136
+ name: activesupport
137
+ requirement: &15285320 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: *15285320
146
+ - !ruby/object:Gem::Dependency
147
+ name: rails
148
+ requirement: &15283940 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :runtime
155
+ prerelease: false
156
+ version_requirements: *15283940
157
+ description: Configurable application wide defaults for Paperclip
158
+ email:
159
+ - mark@socialreferral.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .gitignore
165
+ - .rvmrc
166
+ - .travis.yml
167
+ - Gemfile
168
+ - Guardfile
169
+ - LICENSE
170
+ - README.md
171
+ - Rakefile
172
+ - lib/paperclip-defaults.rb
173
+ - lib/paperclip-defaults/railtie.rb
174
+ - lib/paperclip-defaults/version.rb
175
+ - paperclip-defaults.gemspec
176
+ - test/test_helper.rb
177
+ - test/test_paperclip-defaults.rb
178
+ homepage: ''
179
+ licenses: []
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 1.9.2
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ segments:
197
+ - 0
198
+ hash: -2063001517990650323
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 1.8.6
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: Configurable application wide defaults for Paperclip
205
+ test_files: []