trying out dragonfly
Oleg
committed Dec 22, 2011
commit 22d0e1ae70fe36d1ec09902fc3e945d13a18a55f
Showing 5
changed files with
22 additions
and 29 deletions
Gemfile
+1
-1
| @@ | @@ -2,7 +2,7 @@ source 'http://rubygems.org' |
| gem 'rails', '>=3.0.0' | |
| gem 'active_link_to', '~>1.0.0' | |
| - | gem 'paperclip', '>=2.3.0' |
| + | gem 'dragonfly', '>=0.9.0' |
| group :test do | |
| gem 'sqlite3' | |
app/models/cms/file.rb
+7
-14
| @@ | @@ -1,3 +1,5 @@ |
| + | require 'dragonfly/rails/images' |
| + | |
| class Cms::File < ActiveRecord::Base | |
| IMAGE_MIMETYPES = %w(gif jpeg pjpeg png svg+xml tiff).collect{|subtype| "image/#{subtype}"} | |
| @@ | @@ -11,15 +13,7 @@ class Cms::File < ActiveRecord::Base |
| attr_accessor :dimensions | |
| # -- AR Extensions -------------------------------------------------------- | |
| - | has_attached_file :file, ComfortableMexicanSofa.config.upload_file_options.merge( |
| - | # dimensions accessor needs to be set before file assignment for this to work |
| - | :styles => lambda { |f| |
| - | (f.instance.dimensions.blank?? { } : { :original => f.instance.dimensions }).merge( |
| - | :cms_thumb => '80x60#' |
| - | ) |
| - | } |
| - | ) |
| - | before_post_process :is_image? |
| + | image_accessor :file |
| # -- Relationships -------------------------------------------------------- | |
| belongs_to :site | |
| @@ | @@ -27,7 +21,6 @@ class Cms::File < ActiveRecord::Base |
| # -- Validations ---------------------------------------------------------- | |
| validates :site_id, :presence => true | |
| - | validates_attachment_presence :file |
| # -- Callbacks ------------------------------------------------------------ | |
| before_save :assign_label | |
| @@ | @@ -36,18 +29,18 @@ class Cms::File < ActiveRecord::Base |
| after_destroy :reload_page_cache | |
| # -- Scopes --------------------------------------------------------------- | |
| - | scope :images, where(:file_content_type => IMAGE_MIMETYPES) |
| - | scope :not_images, where('file_content_type NOT IN (?)', IMAGE_MIMETYPES) |
| + | scope :images, where(:file_mime_type => IMAGE_MIMETYPES) |
| + | scope :not_images, where('file_mime_type NOT IN (?)', IMAGE_MIMETYPES) |
| # -- Instance Methods ----------------------------------------------------- | |
| def is_image? | |
| - | IMAGE_MIMETYPES.include?(file_content_type) |
| + | IMAGE_MIMETYPES.include?(file_mime_type) |
| end | |
| protected | |
| def assign_label | |
| - | self.label = self.label.blank?? self.file_file_name.gsub(/\.[^\.]*?$/, '').titleize : self.label |
| + | self.label = self.label.blank?? self.file_name.gsub(/\.[^\.]*?$/, '').titleize : self.label |
| end | |
| def assign_position | |
config/initializers/paperclip.rb
+0
-3
| @@ | @@ -1,3 +0,0 @@ |
| - | Paperclip.options[:command_path] = case Rails.env |
| - | when 'development', 'test' then '/usr/local/bin' |
| - | end |
| \ No newline at end of file | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+9
-8
| @@ | @@ -73,18 +73,19 @@ class CreateCms < ActiveRecord::Migration |
| # -- Files -------------------------------------------------------------- | |
| create_table :cms_files do |t| | |
| - | t.integer :site_id, :null => false |
| + | t.integer :site_id, :null => false |
| t.integer :block_id | |
| - | t.string :label, :null => false |
| - | t.string :file_file_name, :null => false |
| - | t.string :file_content_type, :null => false |
| - | t.integer :file_file_size, :null => false |
| - | t.string :description, :limit => 2048 |
| - | t.integer :position, :null => false, :default => 0 |
| + | t.string :label, :null => false |
| + | t.string :file_uid, :null => false |
| + | t.string :file_name, :null => false |
| + | t.string :file_mime_type, :null => false |
| + | t.integer :file_size, :null => false |
| + | t.string :description, :limit => 2048 |
| + | t.integer :position, :null => false, :default => 0 |
| t.timestamps | |
| end | |
| add_index :cms_files, [:site_id, :label] | |
| - | add_index :cms_files, [:site_id, :file_file_name] |
| + | add_index :cms_files, [:site_id, :file_name] |
| add_index :cms_files, [:site_id, :position] | |
| add_index :cms_files, [:site_id, :block_id] | |
test/fixtures/cms/files.yml
+5
-3
| @@ | @@ -1,8 +1,10 @@ |
| default: | |
| site: default | |
| label: Sample | |
| - | file_file_name: sample.jpg |
| - | file_content_type: image/jpeg |
| - | file_file_size: 20099 |
| + | file_name: sample.jpg |
| + | file_uid: abc123 |
| + | # file_file_name: sample.jpg |
| + | # file_content_type: image/jpeg |
| + | # file_file_size: 20099 |
| description: Description | |
| position: 0 | |
| \ No newline at end of file | |