forked from galetahub/ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request galetahub#115 from chewi/master
Dragonfly backend plus raft of other improvements
- Loading branch information
Showing
28 changed files
with
356 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Ckeditor | ||
module Backend | ||
module Dragonfly | ||
def self.included(base) | ||
base.send(:include, InstanceMethods) | ||
base.send(:extend, ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def attachment_file_types | ||
@attachment_file_types ||= Ckeditor.attachment_file_types.map(&:to_sym).tap do |formats| | ||
# This is not ideal but Dragonfly doesn't return double | ||
# extensions. Having said that, the other backends | ||
# currently don't use attachment_file_types at all. | ||
[ :bz2, :gz, :lzma, :xz ].each do |f| | ||
formats << f if formats.include?("tar.#{f}".to_sym) | ||
end | ||
end | ||
end | ||
|
||
def image_file_types | ||
@image_file_types ||= Ckeditor.image_file_types.map(&:to_sym) | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
delegate :url, :path, :size, :image?, :width, :height, :to => :data | ||
|
||
alias_attribute :data_file_name, :data_name | ||
alias_attribute :data_content_type, :data_mime_type | ||
alias_attribute :data_file_size, :data_size | ||
|
||
private | ||
|
||
def url_thumb_options | ||
if data.basename.present? | ||
{ :basename => "thumb_#{data.basename}" } | ||
else | ||
{} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
lib/generators/ckeditor/templates/active_record/dragonfly/ckeditor/asset.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Ckeditor::Asset < ActiveRecord::Base | ||
include Ckeditor::Orm::ActiveRecord::AssetBase | ||
include Ckeditor::Backend::Dragonfly | ||
|
||
ckeditor_file_accessor :data | ||
validates_presence_of :data | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/generators/ckeditor/templates/active_record/dragonfly/ckeditor/attachment_file.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Ckeditor::AttachmentFile < Ckeditor::Asset | ||
validates_property :format, :of => :data, :in => attachment_file_types unless attachment_file_types.empty? | ||
|
||
def url_thumb | ||
Ckeditor::Utils.filethumb(filename) | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/generators/ckeditor/templates/active_record/dragonfly/ckeditor/picture.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Ckeditor::Picture < Ckeditor::Asset | ||
validates_property :format, :of => :data, :in => image_file_types unless image_file_types.empty? | ||
validates_property :image?, :of => :data, :as => true, :message => :invalid | ||
|
||
def url_content | ||
data.thumb("800x800>").url | ||
end | ||
|
||
def url_thumb | ||
data.thumb("118x100#").url(url_thumb_options) | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class CreateCkeditorAssets < ActiveRecord::Migration | ||
def self.up | ||
create_table :ckeditor_assets do |t| | ||
t.string :data_uid, :null => false | ||
t.string :data_name, :null => false | ||
t.string :data_mime_type | ||
t.integer :data_size | ||
|
||
t.integer :assetable_id | ||
t.string :assetable_type, :limit => 30 | ||
t.string :type, :limit => 30 | ||
|
||
# Uncomment these to save image dimensions, if your need them. | ||
# t.integer :data_width | ||
# t.integer :data_height | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_ckeditor_assetable_type" | ||
add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "idx_ckeditor_assetable" | ||
end | ||
|
||
def self.down | ||
drop_table :ckeditor_assets | ||
end | ||
end |
Oops, something went wrong.