acts-as-assetable 0.0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Lance Pollard (lancejpollard@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ # ActsAsAssetable
2
+
3
+ ## Usage
4
+
5
+ ### Install
6
+
7
+ sudo gem install acts-as-assetable
8
+
9
+ ### Basics
10
+
11
+ class Post < ActiveRecord::Base
12
+ acts_as_assetable_on :images do
13
+ styles :medium => "300x300>",
14
+ :thumb => "120x120#",
15
+ :tiny => "50x50#",
16
+ :micro => "20x20#"
17
+ storage do
18
+ s3 => {:key => "my_key", :secret => "my_secret"}
19
+ end
20
+ end
21
+
22
+ acts_as_assetable_on :videos do
23
+ storage do
24
+ vimeo => {:key => "my_key", :secret => "my_secret"}
25
+ youtube => {:key => "my_key", :secret => "my_secret"}
26
+ end
27
+ end
28
+ end
29
+
30
+ ### Helpful Links
31
+
32
+ http://github.com/nathancolgate/s3-swf-upload-plugin
33
+ http://www.therailsway.com/2009/4/23/uploading-files
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ require 'rake'
2
+ require "rake/rdoctask"
3
+ require 'rake/gempackagetask'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = "acts-as-assetable"
7
+ s.authors = ["Lance Pollard"]
8
+ s.version = "0.0.1.5"
9
+ s.summary = "ActAsAssetable: Super DRY Asset Manipulation and Storage for Rails and Paperclip"
10
+ s.homepage = "http://github.com/viatropos/acts-as-assetable"
11
+ s.email = "lancejpollard@gmail.com"
12
+ s.description = "Super DRY Asset Manipulation and Storage for Rails and Paperclip"
13
+ s.has_rdoc = false
14
+ s.rubyforge_project = "acts-as-assetable"
15
+ s.platform = Gem::Platform::RUBY
16
+ s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
17
+ s.require_path = "lib"
18
+ end
19
+
20
+ Rake::GemPackageTask.new(spec) do |pkg|
21
+ pkg.gem_spec = spec
22
+ pkg.package_dir = "pkg"
23
+ end
24
+
25
+ desc 'run unit tests'
26
+ task :test do
27
+ Dir["test/**/*"].each do |file|
28
+ next unless File.basename(file) =~ /test_/
29
+ next unless File.extname(file) == ".rb"
30
+ system "ruby #{file}"
31
+ end
32
+ end
33
+
34
+ desc "Create .gemspec file (useful for github)"
35
+ task :gemspec do
36
+ File.open("pkg/#{spec.name}.gemspec", "w") do |f|
37
+ f.puts spec.to_ruby
38
+ end
39
+ end
40
+
41
+ desc "Build the gem into the current directory"
42
+ task :gem => :gemspec do
43
+ `gem build pkg/#{spec.name}.gemspec`
44
+ end
45
+
46
+ desc "Publish gem to rubygems"
47
+ task :publish => [:package] do
48
+ %x[gem push pkg/#{spec.name}-#{spec.version}.gem]
49
+ end
50
+
51
+ desc "Print a list of the files to be put into the gem"
52
+ task :manifest do
53
+ File.open("Manifest", "w") do |f|
54
+ spec.files.each do |file|
55
+ f.puts file
56
+ end
57
+ end
58
+ end
59
+
60
+ desc "Install the gem locally"
61
+ task :install => [:package] do
62
+ File.mkdir("pkg") unless File.exists?("pkg")
63
+ command = "gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc"
64
+ command = "sudo #{command}" if ENV["SUDO"] == true
65
+ sh %{#{command}}
66
+ end
67
+
68
+ desc "Generate the rdoc"
69
+ Rake::RDocTask.new do |rdoc|
70
+ files = ["README.markdown", "lib/**/*.rb"]
71
+ rdoc.rdoc_files.add(files)
72
+ rdoc.main = "README.markdown"
73
+ rdoc.title = spec.summary
74
+ end
75
+
76
+ task :yank do
77
+ `gem yank #{spec.name} -v #{spec.version}`
78
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,40 @@
1
+ module ActsAsAssetable
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+
8
+ def acts_as_assetable_on(*args)
9
+ options = args.extract_options!
10
+ styles = args
11
+ acts_as_joinable_on :assets, :contexts => styles
12
+ self.class_eval do
13
+ styles.each do |k,v|
14
+ name = "#{k.to_s}_image"
15
+ define_method name do
16
+ join_for(k)
17
+ end
18
+
19
+ define_method "#{name}_id" do
20
+ result = join_for(k)
21
+ result ? result.id : nil
22
+ end
23
+
24
+ define_method "#{name}=" do |asset|
25
+ set_joined(k, asset)
26
+ end
27
+
28
+ define_method "#{name}_id=" do |id|
29
+ set_joined(k, id)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def acts_as_assetable(*args)
36
+ acts_as_assetable_on(*args)
37
+ end
38
+ end
39
+
40
+ end
data/lib/asset.rb ADDED
@@ -0,0 +1,25 @@
1
+ class Asset < ActiveRecord::Base
2
+ has_friendly_id :title, :use_slug => true, :cache_column => :permalink
3
+ acts_as_taggable_on :tags, :categories
4
+ acts_as_joinable
5
+
6
+ has_attached_file :data,
7
+ :styles => {
8
+ :medium => "300x300>",
9
+ :thumb => "120x120#",
10
+ :tiny => "50x50#",
11
+ :micro => "20x20#"
12
+ },
13
+ :storage => :s3,
14
+ :s3_credentials => {
15
+ :access_key_id => Settings("s3.key"),
16
+ :secret_access_key => Settings("s3.secret")
17
+ },
18
+ :path => Settings("s3.permalink"),
19
+ :bucket => Settings("s3.bucket")
20
+
21
+ def url(style = nil)
22
+ data.url(style || data.default_style)
23
+ end
24
+
25
+ end
data/lib/document.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Document < ActiveRecord::Base
2
+
3
+ end
data/lib/image.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Image < Asset
2
+
3
+ end
data/lib/pdf.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Pdf < ActiveRecord::Base
2
+
3
+ end
data/lib/video.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Video < ActiveRecord::Base
2
+
3
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'acts-as-assetable'
2
+
3
+ ActiveRecord::Base.send :include, ActsAsAssetable
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'acts_as_categorizable'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts-as-assetable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 65
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - 5
11
+ version: 0.0.1.5
12
+ platform: ruby
13
+ authors:
14
+ - Lance Pollard
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-20 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Super DRY Asset Manipulation and Storage for Rails and Paperclip
24
+ email: lancejpollard@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - README.markdown
33
+ - Rakefile
34
+ - init.rb
35
+ - MIT-LICENSE
36
+ - lib/acts-as-assetable.rb
37
+ - lib/asset.rb
38
+ - lib/document.rb
39
+ - lib/image.rb
40
+ - lib/pdf.rb
41
+ - lib/video.rb
42
+ - rails/init.rb
43
+ - test/helper.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/viatropos/acts-as-assetable
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project: acts-as-assetable
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: "ActAsAssetable: Super DRY Asset Manipulation and Storage for Rails and Paperclip"
78
+ test_files: []
79
+