Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #48 from radiant/fog

fog for cloud storage
  • Loading branch information...
commit fd14b61d2795be87418c2d193fbaf139d37fe1a0 2 parents 760d058 + ab2c0ba
@will-r will-r authored
View
2  README.md
@@ -28,7 +28,7 @@ At the moment I think uploads probably don't work in IE7. See github for more is
## Requirements
-The `paperclip`, `uuidtools` and `acts_as_list` gems are required. For S3 storage you need the `aws-s3` gem.
+The `paperclip`, `uuidtools` and `acts_as_list` gems are required. For cloud storage you need the `fog` gem.
Paperclip's post-processors require ImageMagick. PDF-thumbnailing also requires ghostscript, which is usually
installed with ImageMagick anyway, and if you want to generate thumbnails from video clips then you also need FFmpeg.
View
20 app/models/asset.rb
@@ -39,15 +39,17 @@ class Asset < ActiveRecord::Base
asset.paperclip_processors
},
:whiny => false,
- :storage => Radiant.config["paperclip.storage"] == "s3" ? :s3 : :filesystem,
- :s3_credentials => {
- :access_key_id => Radiant.config["paperclip.s3.key"],
- :secret_access_key => Radiant.config["paperclip.s3.secret"]
- },
- :s3_host_alias => Radiant.config["paperclip.s3.host_alias"] || Radiant.config["paperclip.s3.bucket"],
- :bucket => Radiant.config["paperclip.s3.bucket"],
- :url => Radiant.config["paperclip.url"],
- :path => Radiant.config["paperclip.path"]
+ :storage => RadiantClippedExtension::Cloud.storage ||
+ :filesystem,
+ :path => Radiant.config["paperclip.path"],
+ :fog_credentials => RadiantClippedExtension::Cloud.credentials,
+ :fog_directory => Radiant.config["paperclip.fog.directory"] ||
+ Radiant.config["paperclip.s3.bucket"],
+ :fog_public => Radiant.config["paperclip.fog.public?"] ||
+ true,
+ :fog_host => Radiant.config["paperclip.fog.host"] ||
+ "http://#{Radiant.config['paperclip.s3.host_alias']}" ||
+ "http://#{Radiant.config['paperclip.url']}"
before_save :assign_title
before_save :assign_uuid
View
1  clipped_extension.rb
@@ -1,6 +1,7 @@
require 'radiant-clipped-extension'
require 'acts_as_list'
require 'uuidtools'
+require 'cloud'
class ClippedExtension < Radiant::Extension
version RadiantClippedExtension::VERSION
View
41 config/initializers/radiant_config.rb
@@ -3,16 +3,49 @@
pc.define 'url', :default => '/:class/:id/:basename:no_original_style.:extension'
pc.define 'path', :default => ':rails_root/public/:class/:id/:basename:no_original_style.:extension', :allow_change => true
pc.define 'skip_filetype_validation', :default => true, :type => :boolean
- pc.define 'storage', :default => 'filesystem',
- :select_from => {'File System' => 'filesystem', 'Amazon S3' => 's3'},
- :allow_blank => false,
+ pc.define 'storage', :default => 'filesystem',
+ :select_from => {
+ 'File System' => 'filesystem',
+ 'Amazon S3' => 'fog',
+ 'Google Storage' => 'fog',
+ 'Rackspace Cloud Files' => 'fog'
+ },
+ :allow_blank => false,
:allow_display => false
-
+
+ pc.namespace 'fog' do |fog|
+ fog.define 'provider', :select_from => {
+ 'Amazon S3' => 'AWS',
+ 'Google Storage' => 'Google',
+ 'Rackspace Cloud Files' => 'Rackspace'
+ }
+ fog.define 'directory'
+ fog.define 'public?', :default => true
+ fog.define 'host'
+ end
+
+ pc.namespace 'google_storage' do |gs|
+ gs.define 'access_key_id'
+ gs.define 'secret_access_key'
+ end
+
+ pc.namespace 'rackspace' do |rs|
+ rs.define 'username'
+ rs.define 'api_key'
+ end
+
pc.namespace 's3' do |s3|
s3.define 'bucket'
s3.define 'key'
s3.define 'secret'
s3.define 'host_alias'
+ s3.define 'region', :select_from => {
+ 'Asia North East' => 'ap-northeast-1',
+ 'Asia South East' => 'ap-southeast-1',
+ 'EU West' => 'eu-west-1',
+ 'US East' => 'us-east-1',
+ 'US West' => 'us-west-1'
+ }
end
end
View
39 lib/cloud.rb
@@ -0,0 +1,39 @@
+module RadiantClippedExtension
+
+ module Cloud
+
+ def self.credentials
+ case Radiant.config["paperclip.fog.provider"]
+ when "AWS"
+ return {
+ :provider => "AWS",
+ :aws_access_key_id => Radiant.config["paperclip.s3.key"],
+ :aws_secret_access_key => Radiant.config["paperclip.s3.secret"],
+ :region => Radiant.config["paperclip.s3.region"],
+ }
+ when "Google"
+ return {
+ :provider => "Google",
+ :rackspace_username => Radiant.config["paperclip.google_storage.access_key_id"],
+ :rackspace_api_key => Radiant.config["paperclip.google_storage.secret_access_key"]
+ }
+ when "Rackspace"
+ return {
+ :provider => "Rackspace",
+ :rackspace_username => Radiant.config["paperclip.rackspace.username"],
+ :rackspace_api_key => Radiant.config["paperclip.rackspace.api_key"]
+ }
+ end
+ end
+
+ def self.storage
+ if Radiant.config["paperclip.storage"] == "s3"
+ :fog
+ else
+ Radiant.config["paperclip.storage"]
+ end
+ end
+
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.