Skip to content

Commit

Permalink
Merge pull request galetahub#115 from chewi/master
Browse files Browse the repository at this point in the history
Dragonfly backend plus raft of other improvements
  • Loading branch information
galetahub committed Apr 21, 2012
2 parents 30084d1 + da83829 commit 82cee8d
Show file tree
Hide file tree
Showing 28 changed files with 356 additions and 198 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Expand Up @@ -2,7 +2,7 @@ source "http://rubygems.org"

gemspec

gem "rails", "3.1.3"
gem "rails", "3.2.3"

platforms :mri_18 do
group :test do
Expand All @@ -24,8 +24,9 @@ platforms :ruby do
end

group :active_record do
gem "paperclip"
gem "paperclip", "< 3.0.1" # https://github.com/thoughtbot/paperclip/issues/807
gem "carrierwave"
gem "dragonfly"
gem "mini_magick"
end

Expand Down
132 changes: 67 additions & 65 deletions Gemfile.lock
Expand Up @@ -9,38 +9,37 @@ GEM
remote: http://rubygems.org/
specs:
SystemTimer (1.2.3)
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
actionmailer (3.2.3)
actionpack (= 3.2.3)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.5)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.3)
activesupport (= 3.1.3)
sprockets (~> 2.1.2)
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (2.2.1)
bson (1.5.2)
bson_ext (1.5.2)
bson (= 1.5.2)
arel (3.0.2)
bson (1.6.2)
bson_ext (1.6.2)
bson (~> 1.6.2)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
Expand All @@ -51,88 +50,90 @@ GEM
xpath (~> 0.1.4)
carrierwave (0.5.8)
activesupport (~> 3.0)
carrierwave-mongoid (0.1.3)
carrierwave (>= 0.5.6)
carrierwave-mongoid (0.1.7)
carrierwave (~> 0.5.6)
mongoid (~> 2.1)
childprocess (0.2.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
cocaine (0.2.1)
columnize (0.3.6)
dragonfly (0.9.12)
rack
erubis (2.7.0)
ffi (1.0.11)
hike (1.2.1)
i18n (0.6.0)
json (1.6.4)
kgio (2.7.0)
journey (1.0.3)
json (1.6.6)
kgio (2.7.4)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.3.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
mini_magick (3.4)
subexec (~> 0.2.1)
mongo (1.5.2)
bson (= 1.5.2)
mongoid (2.3.4)
mongo (1.6.2)
bson (~> 1.6.2)
mongoid (2.4.7)
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
mongoid-paperclip (0.0.7)
paperclip (>= 2.3.6)
multi_json (1.0.4)
multi_json (1.2.0)
mynyml-redgreen (0.7.1)
term-ansicolor (>= 1.0.4)
nokogiri (1.5.0)
orm_adapter (0.0.6)
paperclip (2.4.5)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
nokogiri (1.5.2)
orm_adapter (0.0.7)
paperclip (3.0.0)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
bundler (~> 1.0)
railties (= 3.1.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
raindrops (0.8.0)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rbx-require-relative (0.0.9)
rdoc (3.12)
json (~> 1.4)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rubyzip (0.9.5)
selenium-webdriver (2.15.0)
childprocess (>= 0.2.1)
ffi (~> 1.0.9)
multi_json (~> 1.0.4)
rubyzip (0.9.7)
selenium-webdriver (2.20.0)
childprocess (>= 0.2.5)
ffi (~> 1.0)
multi_json (~> 1.0)
rubyzip
sprockets (2.0.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
Expand All @@ -144,7 +145,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
tzinfo (0.3.33)
unicorn (4.0.1)
kgio (~> 2.4)
rack
Expand All @@ -162,12 +163,13 @@ DEPENDENCIES
carrierwave
carrierwave-mongoid
ckeditor!
dragonfly
mini_magick
mongoid
mongoid-paperclip
mynyml-redgreen (~> 0.7.1)
paperclip
rails (= 3.1.3)
paperclip (< 3.0.1)
rails (= 3.2.3)
ruby-debug
sqlite3
unicorn (~> 4.0.1)
1 change: 1 addition & 0 deletions lib/ckeditor.rb
Expand Up @@ -21,6 +21,7 @@ module Hooks
module Backend
autoload :Paperclip, 'ckeditor/backend/paperclip'
autoload :CarrierWave, 'ckeditor/backend/carrierwave'
autoload :Dragonfly, 'ckeditor/backend/dragonfly'
end

# Allowed image file types for upload.
Expand Down
45 changes: 45 additions & 0 deletions lib/ckeditor/backend/dragonfly.rb
@@ -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
8 changes: 4 additions & 4 deletions lib/ckeditor/utils.rb
Expand Up @@ -14,7 +14,7 @@ def parameterize_filename(filename)
end

def js_replace(dom_id, options = {})
js_options = applay_options(options)
js_options = apply_options(options)
js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"]

if js_options.blank?
Expand All @@ -41,20 +41,20 @@ def js_fileuploader(uploader_type, options = {})
options[:allowedExtensions] = Ckeditor.attachment_file_types
end

js_options = applay_options(options)
js_options = apply_options(options)

"$(document).ready(function(){ new qq.FileUploaderInput({ #{js_options} }); });".html_safe
end

def applay_options(options)
def apply_options(options)
str = []

options.each do |key, value|
item = case value
when String then
value.split(//).first == '^' ? value.slice(1..-1) : "'#{value}'"
when Hash then
"{ #{applay_options(value)} }"
"{ #{apply_options(value)} }"
when Array then
arr = value.collect { |v| "'#{v}'" }
"[ #{arr.join(',')} ]"
Expand Down
6 changes: 5 additions & 1 deletion lib/generators/ckeditor/install_generator.rb
Expand Up @@ -13,7 +13,7 @@ class InstallGenerator < Rails::Generators::Base
:desc => "Backend processor for upload support"

class_option :backend, :type => :string, :default => 'paperclip',
:desc => "Paperclip (by default) or carrierwave"
:desc => "paperclip (default), carrierwave, or dragonfly"

def self.source_root
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
Expand All @@ -26,6 +26,10 @@ def self.next_migration_number(dirname)
# copy configuration
def copy_initializer
template "ckeditor.rb", "config/initializers/ckeditor.rb"

if backend == "dragonfly"
template File.join("base", "dragonfly", "initializer.rb"), "config/initializers/ckeditor_dragonfly.rb"
end
end

def mount_engine
Expand Down
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 82cee8d

Please sign in to comment.