radiant-assets-extension 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,5 +1,19 @@
1
- = Images
1
+ = Assets
2
2
 
3
- Radiant is so freaking awesome, but I made it better through this extension.
3
+ Provides simple image handling, incl. on-the-fly resizing. Intended as a
4
+ replacement for paperclipped in the long run, but very barebones right now.
4
5
 
5
- Created by Your Name.
6
+ == Radius Tags
7
+
8
+ <r:images size="300x" />
9
+
10
+ Proportionally resizes an image to 300px width. Supports imagemagick geometry
11
+ strings to do advanced resizing straight in Radius tags. Resized images are
12
+ cached in Radiant's built-in cache so they don't have to be re-created on every
13
+ request.
14
+
15
+ == Todo
16
+
17
+ - Handling of non-image uploads
18
+ - Attaching Assets to Pages
19
+ - Easy/Automatic migration from paperclipped
data/app/models/image.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  class Image < ActiveRecord::Base
2
2
  image_accessor :upload
3
+ validates_presence_of :upload
3
4
  end
data/assets_extension.rb CHANGED
@@ -1,20 +1,24 @@
1
1
  # Uncomment this if you reference any of your controllers in activate
2
2
  # require_dependency 'application_controller'
3
3
  require 'radiant-assets-extension/version'
4
- require 'dragonfly'
4
+ require 'radiant-assets-extension/s3_store'
5
5
 
6
6
  class AssetsExtension < Radiant::Extension
7
7
  version RadiantAssetsExtension::VERSION
8
- description "Simple asset management (images and other uploads) for Radiant."
9
- url "http://github"
8
+ description 'Simple asset management (images and other uploads) for Radiant.'
9
+ url 'http://ext.radiantcms.org/extensions/269-assets'
10
10
 
11
11
  extension_config do |config|
12
12
  path = '/assets'
13
13
  dragonfly = Dragonfly[:assets]
14
14
  dragonfly.configure_with(:imagemagick)
15
15
  dragonfly.configure_with(:rails)
16
- dragonfly.url_path_prefix = path
17
16
  dragonfly.define_macro(ActiveRecord::Base, :image_accessor)
17
+ dragonfly.url_path_prefix = path
18
+ if RadiantAssetsExtension::S3Store.enabled?
19
+ dragonfly.datastore = RadiantAssetsExtension::S3Store.new
20
+ end
21
+
18
22
  config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :assets, path
19
23
  end
20
24
 
@@ -0,0 +1,41 @@
1
+ require 'dragonfly'
2
+
3
+ module RadiantAssetsExtension
4
+ # Subclass that allows connecting to S3 regions other than US-Standard
5
+ class S3Store < Dragonfly::DataStorage::S3DataStore
6
+ def self.enabled?
7
+ Radiant::Config['assets.storage'] && Radiant::Config['assets.storage'] == 's3'
8
+ end
9
+
10
+ def self.region_hosts
11
+ {
12
+ 'us-east-1' => 's3.amazonaws.com',
13
+ 'us-west-1' => 's3-us-west-1.amazonaws.com',
14
+ 'eu-west-1' => 's3-eu-west-1.amazonaws.com',
15
+ 'ap-southeast-1' => 's3-ap-southeast-1.amazonaws.com'
16
+ }
17
+ end
18
+
19
+ DEFAULT_BUCKET_NAME = 'radiant-assets-extension'
20
+
21
+ def initialize(opts={})
22
+ # HACK: AWS::S3 doesn't support S3 international regions properly
23
+ # https://github.com/marcel/aws-s3/issues#issue/4/comment/411302
24
+ # we monkey-patch the default host
25
+ AWS::S3::DEFAULT_HOST.replace Radiant::Config['s3.host'] || self.class.s3_region_hosts['us-east-1']
26
+ super({
27
+ :bucket_name => Radiant::Config['s3.bucket'] || DEFAULT_BUCKET_NAME,
28
+ :access_key_id => Radiant::Config['s3.key'],
29
+ :secret_access_key => Radiant::Config['s3.secret']
30
+ }.merge(opts))
31
+ end
32
+
33
+ def connect!
34
+ AWS::S3::Base.establish_connection!(
35
+ :server => "#{bucket_name}.s3.amazonaws.com",
36
+ :access_key_id => access_key_id,
37
+ :secret_access_key => secret_access_key
38
+ )
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,3 @@
1
1
  module RadiantAssetsExtension
2
- VERSION = '0.0.1'
3
-
4
-
5
- end
2
+ VERSION = '0.0.2'
3
+ end
@@ -1,15 +1,15 @@
1
1
  namespace :radiant do
2
2
  namespace :extensions do
3
- namespace :images do
3
+ namespace :assets do
4
4
 
5
5
  desc "Runs the migration of the Images extension"
6
6
  task :migrate => :environment do
7
7
  require 'radiant/extension_migrator'
8
8
  if ENV["VERSION"]
9
- ImagesExtension.migrator.migrate(ENV["VERSION"].to_i)
9
+ AssetsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
10
  Rake::Task['db:schema:dump'].invoke
11
11
  else
12
- ImagesExtension.migrator.migrate
12
+ AssetsExtension.migrator.migrate
13
13
  Rake::Task['db:schema:dump'].invoke
14
14
  end
15
15
  end
@@ -18,17 +18,17 @@ namespace :radiant do
18
18
  task :update => :environment do
19
19
  is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
20
  puts "Copying assets from ImagesExtension"
21
- Dir[ImagesExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
- path = file.sub(ImagesExtension.root, '')
21
+ Dir[AssetsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(AssetsExtension.root, '')
23
23
  directory = File.dirname(path)
24
24
  mkdir_p RAILS_ROOT + directory, :verbose => false
25
25
  cp file, RAILS_ROOT + path, :verbose => false
26
26
  end
27
- unless ImagesExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
27
+ unless AssetsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
28
  puts "Copying rake tasks from ImagesExtension"
29
29
  local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
30
  mkdir_p local_tasks_path, :verbose => false
31
- Dir[File.join ImagesExtension.root, %w(lib tasks *.rake)].each do |file|
31
+ Dir[File.join AssetsExtension.root, %w(lib tasks *.rake)].each do |file|
32
32
  cp file, local_tasks_path, :verbose => false
33
33
  end
34
34
  end
@@ -37,7 +37,7 @@ namespace :radiant do
37
37
  desc "Syncs all available translations for this ext to the English ext master"
38
38
  task :sync => :environment do
39
39
  # The main translation root, basically where English is kept
40
- language_root = ImagesExtension.root + "/config/locales"
40
+ language_root = AssetsExtension.root + "/config/locales"
41
41
  words = TranslationSupport.get_translation_keys(language_root)
42
42
 
43
43
  Dir["#{language_root}/*.yml"].each do |filename|
@@ -52,4 +52,4 @@ namespace :radiant do
52
52
  end
53
53
  end
54
54
  end
55
- end
55
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-assets-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerrit Kaiser
@@ -81,8 +81,9 @@ files:
81
81
  - features/support/env.rb
82
82
  - features/support/paths.rb
83
83
  - lib/radiant-assets-extension.rb
84
+ - lib/radiant-assets-extension/s3_store.rb
84
85
  - lib/radiant-assets-extension/version.rb
85
- - lib/tasks/images_extension_tasks.rake
86
+ - lib/tasks/assets_extension_tasks.rake
86
87
  - public/stylesheets/admin/extensions/assets/assets.css
87
88
  - radiant-assets-extension.gemspec
88
89
  - spec/spec.opts
@@ -91,7 +92,7 @@ has_rdoc: true
91
92
  homepage: http://ext.radiantcms.org/extensions/269-assets
92
93
  licenses: []
93
94
 
94
- post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-assets-extension', :version => '0.0.1'\n "
95
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-assets-extension', :version => '0.0.2'\n "
95
96
  rdoc_options: []
96
97
 
97
98
  require_paths: