ckeditor 4.0.9 → 4.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/app/assets/javascripts/ckeditor/init.js.erb +1 -1
- data/app/controllers/ckeditor/application_controller.rb +3 -3
- data/app/controllers/ckeditor/attachment_files_controller.rb +6 -6
- data/app/controllers/ckeditor/pictures_controller.rb +7 -7
- data/lib/ckeditor.rb +19 -15
- data/lib/ckeditor/backend/carrierwave.rb +9 -9
- data/lib/ckeditor/backend/dragonfly.rb +2 -2
- data/lib/ckeditor/backend/paperclip.rb +4 -4
- data/lib/ckeditor/engine.rb +5 -5
- data/lib/ckeditor/helpers/controllers.rb +6 -6
- data/lib/ckeditor/helpers/form_builder.rb +1 -1
- data/lib/ckeditor/helpers/form_helper.rb +1 -1
- data/lib/ckeditor/helpers/view_helper.rb +1 -1
- data/lib/ckeditor/hooks/formtastic.rb +1 -1
- data/lib/ckeditor/http.rb +7 -7
- data/lib/ckeditor/orm/active_record.rb +3 -3
- data/lib/ckeditor/orm/base.rb +3 -3
- data/lib/ckeditor/orm/mongoid.rb +4 -4
- data/lib/ckeditor/utils.rb +11 -11
- data/lib/ckeditor/version.rb +1 -1
- data/lib/generators/ckeditor/install_generator.rb +10 -10
- data/lib/generators/ckeditor/templates/active_record/carrierwave/ckeditor/asset.rb +1 -1
- data/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb +4 -4
- data/lib/generators/ckeditor/templates/active_record/paperclip/ckeditor/attachment_file.rb +1 -1
- data/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb +2 -2
- data/lib/generators/ckeditor/templates/base/carrierwave/uploaders/ckeditor_attachment_file_uploader.rb +1 -1
- data/lib/generators/ckeditor/templates/base/carrierwave/uploaders/ckeditor_picture_uploader.rb +1 -1
- data/lib/generators/ckeditor/templates/mongoid/carrierwave/ckeditor/asset.rb +1 -1
- data/test/ckeditor_test.rb +1 -1
- data/test/controllers/attachment_files_controller_test.rb +15 -15
- data/test/controllers/pictures_controller_test.rb +15 -15
- data/test/dummy/config/routes.rb +1 -1
- data/test/functional/posts_controller_test.rb +2 -2
- data/test/generators/install_generator_test.rb +7 -7
- data/test/models/attachment_file_test.rb +2 -2
- data/test/models/picture_test.rb +2 -2
- data/test/models/utils_test.rb +4 -5
- data/test/support/helpers.rb +6 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -3,6 +3,6 @@
|
|
3
3
|
|
4
4
|
(function() {
|
5
5
|
if (typeof window['CKEDITOR_BASEPATH'] === "undefined" || window['CKEDITOR_BASEPATH'] === null) {
|
6
|
-
window['CKEDITOR_BASEPATH'] = "<%= asset_path(
|
6
|
+
window['CKEDITOR_BASEPATH'] = "<%= asset_path(Ckeditor.asset_path) %>/";
|
7
7
|
}
|
8
8
|
}).call(this);
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class Ckeditor::ApplicationController < ::ApplicationController
|
2
2
|
respond_to :html, :json
|
3
3
|
layout 'ckeditor/application'
|
4
|
-
|
4
|
+
|
5
5
|
before_filter :find_asset, :only => [:destroy]
|
6
6
|
before_filter :ckeditor_authorize!
|
7
7
|
before_filter :authorize_resource
|
8
8
|
|
9
9
|
protected
|
10
|
-
|
10
|
+
|
11
11
|
def respond_with_asset(asset)
|
12
12
|
file = params[:CKEditor].blank? ? params[:qqfile] : params[:upload]
|
13
13
|
asset.data = Ckeditor::Http.normalize_param(file, request)
|
@@ -18,7 +18,7 @@ class Ckeditor::ApplicationController < ::ApplicationController
|
|
18
18
|
body = params[:CKEditor].blank? ? asset.to_json(:only=>[:id, :type]) : %Q"<script type='text/javascript'>
|
19
19
|
window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{config.relative_url_root}#{Ckeditor::Utils.escape_single_quotes(asset.url_content)}');
|
20
20
|
</script>"
|
21
|
-
|
21
|
+
|
22
22
|
render :text => body
|
23
23
|
else
|
24
24
|
render :nothing => true
|
@@ -3,22 +3,22 @@ class Ckeditor::AttachmentFilesController < Ckeditor::ApplicationController
|
|
3
3
|
def index
|
4
4
|
@attachments = Ckeditor.attachment_file_adapter.find_all(ckeditor_attachment_files_scope)
|
5
5
|
@attachments = Ckeditor::Paginatable.new(@attachments).page(params[:page])
|
6
|
-
|
6
|
+
|
7
7
|
respond_with(@attachments, :layout => @attachments.first_page?)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def create
|
11
11
|
@attachment = Ckeditor.attachment_file_model.new
|
12
|
-
|
12
|
+
respond_with_asset(@attachment)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def destroy
|
16
16
|
@attachment.destroy
|
17
17
|
respond_with(@attachment, :location => attachment_files_path)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
def find_asset
|
23
23
|
@attachment = Ckeditor.attachment_file_adapter.get!(params[:id])
|
24
24
|
end
|
@@ -3,22 +3,22 @@ class Ckeditor::PicturesController < Ckeditor::ApplicationController
|
|
3
3
|
def index
|
4
4
|
@pictures = Ckeditor.picture_adapter.find_all(ckeditor_pictures_scope)
|
5
5
|
@pictures = Ckeditor::Paginatable.new(@pictures).page(params[:page])
|
6
|
-
|
7
|
-
respond_with(@pictures, :layout => @pictures.first_page?)
|
6
|
+
|
7
|
+
respond_with(@pictures, :layout => @pictures.first_page?)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def create
|
11
11
|
@picture = Ckeditor.picture_model.new
|
12
|
-
|
12
|
+
respond_with_asset(@picture)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def destroy
|
16
16
|
@picture.destroy
|
17
17
|
respond_with(@picture, :location => pictures_path)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
def find_asset
|
23
23
|
@picture = Ckeditor.picture_adapter.get!(params[:id])
|
24
24
|
end
|
data/lib/ckeditor.rb
CHANGED
@@ -6,27 +6,27 @@ module Ckeditor
|
|
6
6
|
autoload :Http, 'ckeditor/http'
|
7
7
|
autoload :TextArea, 'ckeditor/text_area'
|
8
8
|
autoload :Paginatable, 'ckeditor/paginatable'
|
9
|
-
|
9
|
+
|
10
10
|
module Helpers
|
11
11
|
autoload :ViewHelper, 'ckeditor/helpers/view_helper'
|
12
12
|
autoload :FormHelper, 'ckeditor/helpers/form_helper'
|
13
13
|
autoload :FormBuilder, 'ckeditor/helpers/form_builder'
|
14
14
|
autoload :Controllers, 'ckeditor/helpers/controllers'
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
module Hooks
|
18
18
|
autoload :SimpleFormBuilder, 'ckeditor/hooks/simple_form'
|
19
19
|
autoload :CanCanAuthorization, 'ckeditor/hooks/cancan'
|
20
20
|
autoload :PunditAuthorization, 'ckeditor/hooks/pundit'
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
module Backend
|
24
24
|
autoload :Paperclip, 'ckeditor/backend/paperclip'
|
25
25
|
autoload :CarrierWave, 'ckeditor/backend/carrierwave'
|
26
26
|
autoload :Dragonfly, 'ckeditor/backend/dragonfly'
|
27
27
|
end
|
28
28
|
|
29
|
-
IMAGE_TYPES =
|
29
|
+
IMAGE_TYPES = %w(image/jpeg image/png image/gif image/jpg image/pjpeg image/tiff image/x-png)
|
30
30
|
|
31
31
|
DEFAULT_AUTHORIZE = Proc.new {}
|
32
32
|
|
@@ -35,21 +35,25 @@ module Ckeditor
|
|
35
35
|
DEFAULT_CURRENT_USER = Proc.new do
|
36
36
|
request.env["warden"].try(:user) || respond_to?(:current_user) && current_user
|
37
37
|
end
|
38
|
-
|
39
|
-
# Allowed image file types for upload.
|
38
|
+
|
39
|
+
# Allowed image file types for upload.
|
40
40
|
# Set to nil or [] (empty array) for all file types
|
41
41
|
mattr_accessor :image_file_types
|
42
|
-
@@image_file_types =
|
43
|
-
|
44
|
-
# Allowed attachment file types for upload.
|
42
|
+
@@image_file_types = %w(jpg jpeg png gif tiff)
|
43
|
+
|
44
|
+
# Allowed attachment file types for upload.
|
45
45
|
# Set to nil or [] (empty array) for all file types
|
46
46
|
mattr_accessor :attachment_file_types
|
47
|
-
@@attachment_file_types =
|
48
|
-
|
47
|
+
@@attachment_file_types = %w(doc docx xls odt ods pdf rar zip tar tar.gz swf)
|
48
|
+
|
49
49
|
# Ckeditor files destination path
|
50
50
|
mattr_accessor :relative_path
|
51
51
|
@@relative_path = '/assets/ckeditor'
|
52
|
-
|
52
|
+
|
53
|
+
# Ckeditor assets path
|
54
|
+
mattr_accessor :asset_path
|
55
|
+
@@asset_path = (Rails::VERSION::MAJOR == 4 ? 'assets/ckeditor' : 'ckeditor')
|
56
|
+
|
53
57
|
# Ckeditor assets for precompilation
|
54
58
|
mattr_accessor :assets
|
55
59
|
@@assets = nil
|
@@ -84,11 +88,11 @@ module Ckeditor
|
|
84
88
|
def self.setup
|
85
89
|
yield self
|
86
90
|
end
|
87
|
-
|
91
|
+
|
88
92
|
def self.root_path
|
89
93
|
@root_path ||= Pathname.new(File.dirname(File.expand_path('../', __FILE__)))
|
90
94
|
end
|
91
|
-
|
95
|
+
|
92
96
|
# All css and js files from ckeditor folder
|
93
97
|
def self.assets
|
94
98
|
@@assets ||= Utils.select_assets("ckeditor", "vendor/assets/javascripts") << "ckeditor/init.js"
|
@@ -162,7 +166,7 @@ module Ckeditor
|
|
162
166
|
#
|
163
167
|
def self.authorize_with(*args, &block)
|
164
168
|
extension = args.shift
|
165
|
-
|
169
|
+
|
166
170
|
if extension
|
167
171
|
@authorize = Proc.new {
|
168
172
|
@authorization_adapter = Ckeditor::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
|
@@ -8,7 +8,7 @@ module Ckeditor
|
|
8
8
|
base.send(:include, InstanceMethods)
|
9
9
|
base.send(:extend, ClassMethods)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
module ClassMethods
|
13
13
|
def self.extended(base)
|
14
14
|
base.class_eval do
|
@@ -17,7 +17,7 @@ module Ckeditor
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
module InstanceMethods
|
22
22
|
# process :strip
|
23
23
|
def strip
|
@@ -27,7 +27,7 @@ module Ckeditor
|
|
27
27
|
img
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# process :quality => 85
|
32
32
|
def quality(percentage)
|
33
33
|
manipulate! do |img|
|
@@ -36,28 +36,28 @@ module Ckeditor
|
|
36
36
|
img
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def extract_content_type
|
41
41
|
if file.content_type == 'application/octet-stream' || file.content_type.blank?
|
42
42
|
content_type = MIME::Types.type_for(original_filename).first
|
43
43
|
else
|
44
44
|
content_type = file.content_type
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
model.data_content_type = content_type.to_s
|
48
|
-
end
|
49
|
-
|
48
|
+
end
|
49
|
+
|
50
50
|
def set_size
|
51
51
|
model.data_file_size = file.size
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def read_dimensions
|
55
55
|
if model.image? && model.has_dimensions?
|
56
56
|
magick = ::MiniMagick::Image.new(current_path)
|
57
57
|
model.width, model.height = magick[:width], magick[:height]
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -5,7 +5,7 @@ module Ckeditor
|
|
5
5
|
base.send(:include, InstanceMethods)
|
6
6
|
base.send(:extend, ClassMethods)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
module ClassMethods
|
10
10
|
def attachment_file_types
|
11
11
|
@attachment_file_types ||= Ckeditor.attachment_file_types.map(&:to_sym).tap do |formats|
|
@@ -22,7 +22,7 @@ module Ckeditor
|
|
22
22
|
@image_file_types ||= Ckeditor.image_file_types.map(&:to_sym)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
module InstanceMethods
|
27
27
|
delegate :url, :path, :size, :image?, :width, :height, :to => :data
|
28
28
|
|
@@ -7,18 +7,18 @@ module Ckeditor
|
|
7
7
|
base.send(:include, InstanceMethods)
|
8
8
|
base.send(:extend, ClassMethods)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
module ClassMethods
|
12
12
|
def self.extended(base)
|
13
13
|
base.class_eval do
|
14
14
|
before_validation :extract_content_type
|
15
15
|
before_create :read_dimensions, :parameterize_filename
|
16
|
-
|
16
|
+
|
17
17
|
delegate :url, :path, :styles, :size, :content_type, :to => :data
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
module InstanceMethods
|
23
23
|
def geometry
|
24
24
|
@geometry ||= begin
|
@@ -26,7 +26,7 @@ module Ckeditor
|
|
26
26
|
::Paperclip::Geometry.from_file(file)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
protected
|
31
31
|
|
32
32
|
def parameterize_filename
|
data/lib/ckeditor/engine.rb
CHANGED
@@ -4,28 +4,28 @@ require 'ckeditor'
|
|
4
4
|
module Ckeditor
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
isolate_namespace Ckeditor
|
7
|
-
|
7
|
+
|
8
8
|
initializer "ckeditor.assets_precompile", :group => :all do |app|
|
9
9
|
app.config.assets.precompile += Ckeditor.assets
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
initializer "ckeditor.helpers" do
|
13
13
|
ActiveSupport.on_load(:action_controller) do
|
14
14
|
ActionController::Base.send :include, Ckeditor::Helpers::Controllers
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
ActiveSupport.on_load :action_view do
|
18
18
|
ActionView::Base.send :include, Ckeditor::Helpers::ViewHelper
|
19
19
|
ActionView::Base.send :include, Ckeditor::Helpers::FormHelper
|
20
20
|
ActionView::Helpers::FormBuilder.send :include, Ckeditor::Helpers::FormBuilder
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
initializer "ckeditor.hooks" do
|
25
25
|
if Object.const_defined?("Formtastic")
|
26
26
|
require "ckeditor/hooks/formtastic"
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
if Object.const_defined?("SimpleForm")
|
30
30
|
require "ckeditor/hooks/simple_form"
|
31
31
|
end
|
@@ -2,9 +2,9 @@ module Ckeditor
|
|
2
2
|
module Helpers
|
3
3
|
module Controllers
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
protected
|
7
|
-
|
7
|
+
|
8
8
|
def ckeditor_current_user
|
9
9
|
instance_eval &Ckeditor.current_user_method
|
10
10
|
end
|
@@ -12,20 +12,20 @@ module Ckeditor
|
|
12
12
|
def ckeditor_authorize!
|
13
13
|
instance_eval &Ckeditor.authorize_with
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def ckeditor_before_create_asset(asset)
|
17
17
|
asset.assetable = ckeditor_current_user if ckeditor_current_user
|
18
18
|
return true
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def ckeditor_pictures_scope(options = {})
|
22
22
|
ckeditor_filebrowser_scope(options)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def ckeditor_attachment_files_scope(options = {})
|
26
26
|
ckeditor_filebrowser_scope(options)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def ckeditor_filebrowser_scope(options = {})
|
30
30
|
{ :order => [:id, :desc] }.merge(options)
|
31
31
|
end
|
data/lib/ckeditor/http.rb
CHANGED
@@ -36,7 +36,7 @@ module Ckeditor
|
|
36
36
|
@tempfile.size
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# Usage (paperclip example)
|
41
41
|
# @asset.data = QqFile.new(params[:qqfile], request)
|
42
42
|
class QqFile < ::Tempfile
|
@@ -44,27 +44,27 @@ module Ckeditor
|
|
44
44
|
def initialize(filename, request, tmpdir = Dir::tmpdir)
|
45
45
|
@original_filename = filename
|
46
46
|
@request = request
|
47
|
-
|
47
|
+
|
48
48
|
super Digest::SHA1.hexdigest(filename), tmpdir
|
49
49
|
binmode
|
50
50
|
fetch
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def fetch
|
54
54
|
self.write(body)
|
55
55
|
self.rewind
|
56
56
|
self
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def original_filename
|
60
60
|
@original_filename
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def content_type
|
64
64
|
types = MIME::Types.type_for(original_filename)
|
65
65
|
types.empty? ? @request.content_type : types.first.to_s
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def body
|
69
69
|
if @request.raw_post.respond_to?(:force_encoding)
|
70
70
|
@request.raw_post.force_encoding("UTF-8")
|
@@ -73,7 +73,7 @@ module Ckeditor
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# Convert nested Hash to HashWithIndifferentAccess and replace
|
78
78
|
# file upload hash with UploadedFile objects
|
79
79
|
def self.normalize_param(*args)
|
@@ -8,13 +8,13 @@ module Ckeditor
|
|
8
8
|
base.send(:include, Base::AssetBase::InstanceMethods)
|
9
9
|
base.send(:extend, ClassMethods)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
module ClassMethods
|
13
13
|
def self.extended(base)
|
14
14
|
base.class_eval do
|
15
15
|
self.table_name = "ckeditor_assets"
|
16
|
-
|
17
|
-
belongs_to :assetable, :polymorphic => true
|
16
|
+
|
17
|
+
belongs_to :assetable, :polymorphic => true
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/ckeditor/orm/base.rb
CHANGED
@@ -10,11 +10,11 @@ module Ckeditor
|
|
10
10
|
def size
|
11
11
|
data_file_size
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def has_dimensions?
|
15
15
|
respond_to?(:width) && respond_to?(:height)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def image?
|
19
19
|
Ckeditor::IMAGE_TYPES.include?(data_content_type)
|
20
20
|
end
|
@@ -30,7 +30,7 @@ module Ckeditor
|
|
30
30
|
def url_thumb
|
31
31
|
url(:thumb)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def as_json_methods
|
35
35
|
[:url_content, :url_thumb, :size, :filename, :format_created_at]
|
36
36
|
end
|
data/lib/ckeditor/orm/mongoid.rb
CHANGED
@@ -12,12 +12,12 @@ module Ckeditor
|
|
12
12
|
base.send(:include, InstanceMethods)
|
13
13
|
base.send(:extend, ClassMethods)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
module InstanceMethods
|
17
17
|
def type
|
18
18
|
_type
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def as_json_methods
|
22
22
|
[:id, :type] + super
|
23
23
|
end
|
@@ -30,8 +30,8 @@ module Ckeditor
|
|
30
30
|
field :data_file_size, :type => Integer
|
31
31
|
field :width, :type => Integer
|
32
32
|
field :height, :type => Integer
|
33
|
-
|
34
|
-
belongs_to :assetable, :polymorphic => true
|
33
|
+
|
34
|
+
belongs_to :assetable, :polymorphic => true
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/ckeditor/utils.rb
CHANGED
@@ -12,16 +12,16 @@ module Ckeditor
|
|
12
12
|
def escape_single_quotes(str)
|
13
13
|
str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def parameterize_filename(filename)
|
17
17
|
return filename unless Ckeditor.parameterize_filenames
|
18
18
|
|
19
19
|
extension = File.extname(filename)
|
20
20
|
basename = filename.gsub(/#{extension}$/, "")
|
21
|
-
|
21
|
+
|
22
22
|
[basename.parameterize('_'), extension].join.downcase
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def js_replace(dom_id, options = nil)
|
26
26
|
js = ["if (typeof CKEDITOR != 'undefined') {"]
|
27
27
|
|
@@ -35,10 +35,10 @@ module Ckeditor
|
|
35
35
|
js << "}"
|
36
36
|
js.join(" ").html_safe
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def js_fileuploader(uploader_type, options = {})
|
40
40
|
options = { :multiple => true, :element => "fileupload" }.merge(options)
|
41
|
-
|
41
|
+
|
42
42
|
case uploader_type.to_s.downcase
|
43
43
|
when "image" then
|
44
44
|
options[:action] = JavascriptCode.new("EDITOR.config.filebrowserImageUploadUrl")
|
@@ -58,14 +58,14 @@ module Ckeditor
|
|
58
58
|
|
59
59
|
def filethumb(filename)
|
60
60
|
extname = filename.blank? ? "unknown" : File.extname(filename).gsub(/^\./, '')
|
61
|
-
|
62
|
-
|
61
|
+
image = "#{extname}.gif"
|
62
|
+
source = Ckeditor.root_path.join("app/assets/javascripts/ckeditor/filebrowser/images/thumbs")
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
unless File.exists?(File.join(source, image))
|
65
|
+
image = "unknown.gif"
|
66
|
+
end
|
67
67
|
|
68
|
-
|
68
|
+
File.join(Ckeditor.relative_path, "filebrowser/images/thumbs", image)
|
69
69
|
end
|
70
70
|
|
71
71
|
def select_assets(path, relative_path)
|
data/lib/ckeditor/version.rb
CHANGED
@@ -7,14 +7,14 @@ module Ckeditor
|
|
7
7
|
include Rails::Generators::Migration
|
8
8
|
|
9
9
|
desc "Generates migration for Asset (Picture, AttachmentFile) models"
|
10
|
-
|
10
|
+
|
11
11
|
# ORM configuration
|
12
12
|
class_option :orm, :type => :string, :default => "active_record",
|
13
13
|
:desc => "Backend processor for upload support"
|
14
|
-
|
14
|
+
|
15
15
|
class_option :backend, :type => :string, :default => 'paperclip',
|
16
16
|
:desc => "paperclip (default), carrierwave, or dragonfly"
|
17
|
-
|
17
|
+
|
18
18
|
def self.source_root
|
19
19
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
20
20
|
end
|
@@ -31,7 +31,7 @@ module Ckeditor
|
|
31
31
|
template File.join("base", "dragonfly", "initializer.rb"), "config/initializers/ckeditor_dragonfly.rb"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def mount_engine
|
36
36
|
route "mount Ckeditor::Engine => '/ckeditor'"
|
37
37
|
end
|
@@ -41,11 +41,11 @@ module Ckeditor
|
|
41
41
|
template "#{generator_dir}/ckeditor/#{filename}.rb",
|
42
42
|
File.join('app/models', ckeditor_dir, "#{filename}.rb")
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
if backend == "carrierwave"
|
46
46
|
template "#{uploaders_dir}/uploaders/ckeditor_attachment_file_uploader.rb",
|
47
47
|
File.join("app/uploaders", "ckeditor_attachment_file_uploader.rb")
|
48
|
-
|
48
|
+
|
49
49
|
template "#{uploaders_dir}/uploaders/ckeditor_picture_uploader.rb",
|
50
50
|
File.join("app/uploaders", "ckeditor_picture_uploader.rb")
|
51
51
|
end
|
@@ -56,7 +56,7 @@ module Ckeditor
|
|
56
56
|
migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', "create_ckeditor_assets.rb")
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
protected
|
61
61
|
|
62
62
|
def ckeditor_dir
|
@@ -66,15 +66,15 @@ module Ckeditor
|
|
66
66
|
def generator_dir
|
67
67
|
@generator_dir ||= [orm, backend].join('/')
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def uploaders_dir
|
71
71
|
@uploaders_dir ||= ['base', 'carrierwave'].join('/')
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def orm
|
75
75
|
(options[:orm] || "active_record").to_s
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def backend
|
79
79
|
(options[:backend] || "paperclip").to_s
|
80
80
|
end
|
@@ -4,18 +4,18 @@ class CreateCkeditorAssets < ActiveRecord::Migration
|
|
4
4
|
t.string :data_file_name, :null => false
|
5
5
|
t.string :data_content_type
|
6
6
|
t.integer :data_file_size
|
7
|
-
|
7
|
+
|
8
8
|
t.integer :assetable_id
|
9
9
|
t.string :assetable_type, :limit => 30
|
10
10
|
t.string :type, :limit => 30
|
11
|
-
|
11
|
+
|
12
12
|
# Uncomment it to save images dimensions, if your need it
|
13
13
|
t.integer :width
|
14
14
|
t.integer :height
|
15
|
-
|
15
|
+
|
16
16
|
t.timestamps
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_ckeditor_assetable_type"
|
20
20
|
add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "idx_ckeditor_assetable"
|
21
21
|
end
|
@@ -2,7 +2,7 @@ class Ckeditor::AttachmentFile < Ckeditor::Asset
|
|
2
2
|
has_attached_file :data,
|
3
3
|
:url => "/ckeditor_assets/attachments/:id/:filename",
|
4
4
|
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
|
5
|
-
|
5
|
+
|
6
6
|
validates_attachment_size :data, :less_than => 100.megabytes
|
7
7
|
validates_attachment_presence :data
|
8
8
|
|
@@ -4,7 +4,7 @@ class CreateCkeditorAssets < ActiveRecord::Migration
|
|
4
4
|
t.string :data_file_name, :null => false
|
5
5
|
t.string :data_content_type
|
6
6
|
t.integer :data_file_size
|
7
|
-
|
7
|
+
|
8
8
|
t.integer :assetable_id
|
9
9
|
t.string :assetable_type, :limit => 30
|
10
10
|
t.string :type, :limit => 30
|
@@ -15,7 +15,7 @@ class CreateCkeditorAssets < ActiveRecord::Migration
|
|
15
15
|
|
16
16
|
t.timestamps
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_ckeditor_assetable_type"
|
20
20
|
add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "idx_ckeditor_assetable"
|
21
21
|
end
|
data/test/ckeditor_test.rb
CHANGED
@@ -2,62 +2,62 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class AttachmentFilesControllerTest < ActionController::TestCase
|
4
4
|
tests Ckeditor::AttachmentFilesController
|
5
|
-
|
5
|
+
|
6
6
|
include RawPost
|
7
7
|
include ControllerHooks
|
8
|
-
|
8
|
+
|
9
9
|
def setup
|
10
10
|
@attachment = fixture_file_upload('files/rails.tar.gz', 'application/x-gzip')
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def teardown
|
14
14
|
Ckeditor::AttachmentFile.destroy_all
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
test "index action" do
|
18
18
|
get :index
|
19
|
-
|
19
|
+
|
20
20
|
assert_equal 200, @response.status
|
21
21
|
assert_template "ckeditor/attachment_files/index"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
test "create action via filebrowser" do
|
25
25
|
assert_difference 'Ckeditor::AttachmentFile.count' do
|
26
26
|
post :create, :qqfile => @attachment
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
assert_equal 200, @response.status
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
test "create action via CKEditor upload form" do
|
33
33
|
assert_difference 'Ckeditor::AttachmentFile.count' do
|
34
34
|
post :create, :upload => @attachment, :CKEditor => 'ckeditor_field'
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
assert_equal 200, @response.status
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
test "create action via html5 upload" do
|
41
41
|
assert_difference 'Ckeditor::AttachmentFile.count' do
|
42
42
|
raw_post :create, { :qqfile => @attachment.original_filename }, @attachment.read
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
assert_equal 200, @response.status
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
test "invalid params for create action" do
|
49
49
|
assert_no_difference 'Ckeditor::AttachmentFile.count' do
|
50
50
|
post :create, :qqfile => nil
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
test "destroy action via filebrowser" do
|
55
55
|
@attachment_file = Ckeditor::AttachmentFile.create :data => @attachment
|
56
|
-
|
56
|
+
|
57
57
|
assert_difference 'Ckeditor::AttachmentFile.count', -1 do
|
58
58
|
delete :destroy, :id => @attachment_file.id
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
assert_equal 302, @response.status
|
62
62
|
end
|
63
63
|
end
|
@@ -2,63 +2,63 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class PicturesControllerTest < ActionController::TestCase
|
4
4
|
tests Ckeditor::PicturesController
|
5
|
-
|
5
|
+
|
6
6
|
include RawPost
|
7
7
|
include Ckeditor::Engine.routes.url_helpers
|
8
8
|
include ControllerHooks
|
9
|
-
|
9
|
+
|
10
10
|
def setup
|
11
11
|
@image = fixture_file_upload('files/rails.png', 'image/png')
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def teardown
|
15
15
|
Ckeditor::Picture.destroy_all
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
test "index action" do
|
19
19
|
get :index
|
20
|
-
|
20
|
+
|
21
21
|
assert_equal 200, @response.status
|
22
22
|
assert_template "ckeditor/pictures/index"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
test "create action via filebrowser" do
|
26
26
|
assert_difference 'Ckeditor::Picture.count' do
|
27
27
|
post :create, :qqfile => @image
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
assert_equal 200, @response.status
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
test "create action via CKEditor upload form" do
|
34
34
|
assert_difference 'Ckeditor::Picture.count' do
|
35
35
|
post :create, :upload => @image, :CKEditor => 'ckeditor_field'
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
assert_equal 200, @response.status
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
test "create action via html5 upload" do
|
42
42
|
assert_difference 'Ckeditor::Picture.count' do
|
43
43
|
raw_post :create, { :qqfile => @image.original_filename }, @image.read, "image/png"
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
assert_equal 200, @response.status
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
test "invalid params for create action" do
|
50
50
|
assert_no_difference 'Ckeditor::Picture.count' do
|
51
51
|
post :create, :qqfile => nil
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
test "destroy action via filebrowser" do
|
56
56
|
@picture = Ckeditor::Picture.create :data => @image
|
57
|
-
|
57
|
+
|
58
58
|
assert_difference 'Ckeditor::Picture.count', -1 do
|
59
59
|
delete :destroy, :id => @picture.id
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
assert_equal 302, @response.status
|
63
63
|
end
|
64
64
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -11,7 +11,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
11
11
|
|
12
12
|
test "include javascripts" do
|
13
13
|
get :index
|
14
|
-
|
14
|
+
|
15
15
|
assert_select "script[src=/assets/application.js]"
|
16
16
|
assert_select "script", Regexp.new(Regexp.escape(%q!CKEDITOR.replace('test_area');!))
|
17
17
|
end
|
@@ -25,7 +25,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
25
25
|
|
26
26
|
test "form builder helper" do
|
27
27
|
get :new
|
28
|
-
|
28
|
+
|
29
29
|
assert_select "textarea#post_content[name='post[content]'][cols=40][rows=20]", ""
|
30
30
|
assert_select "script", Regexp.new(Regexp.escape(%q!CKEDITOR.replace('post_content', {"width":800,"height":400});!))
|
31
31
|
assert_select "textarea#new_info_content[name='post[info]'][cols=40][rows=20]", "Defaults info content"
|
@@ -8,7 +8,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
8
8
|
|
9
9
|
setup do
|
10
10
|
dir = File.expand_path("../../", __FILE__)
|
11
|
-
|
11
|
+
|
12
12
|
FileUtils.mkdir_p File.join(dir, 'tmp/config')
|
13
13
|
FileUtils.cp File.join(dir, 'support/routes.txt'), File.join(dir, 'tmp/config/routes.rb')
|
14
14
|
end
|
@@ -25,7 +25,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
25
25
|
|
26
26
|
assert_file "config/initializers/ckeditor.rb", /require "ckeditor\/orm\/mongoid"/
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
test "models and migration for active_record orm via paperclip" do
|
30
30
|
run_generator %w(--orm=active_record --backend=paperclip)
|
31
31
|
|
@@ -46,7 +46,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
46
46
|
assert_file "app/models/ckeditor/asset.rb"
|
47
47
|
assert_file "app/models/ckeditor/picture.rb"
|
48
48
|
assert_file "app/models/ckeditor/attachment_file.rb"
|
49
|
-
|
49
|
+
|
50
50
|
assert_file "app/uploaders/ckeditor_attachment_file_uploader.rb"
|
51
51
|
assert_file "app/uploaders/ckeditor_picture_uploader.rb"
|
52
52
|
|
@@ -81,17 +81,17 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
81
81
|
|
82
82
|
assert_no_migration "db/migrate/create_ckeditor_assets.rb"
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
test "models for mongoid orm via carrierwave" do
|
86
86
|
run_generator %w(--orm=mongoid --backend=carrierwave)
|
87
|
-
|
87
|
+
|
88
88
|
assert_file "app/models/ckeditor/asset.rb"
|
89
89
|
assert_file "app/models/ckeditor/picture.rb"
|
90
90
|
assert_file "app/models/ckeditor/attachment_file.rb"
|
91
|
-
|
91
|
+
|
92
92
|
assert_file "app/uploaders/ckeditor_attachment_file_uploader.rb"
|
93
93
|
assert_file "app/uploaders/ckeditor_picture_uploader.rb"
|
94
|
-
|
94
|
+
|
95
95
|
assert_no_migration "db/migrate/create_ckeditor_assets.rb"
|
96
96
|
end
|
97
97
|
end
|
@@ -7,14 +7,14 @@ class AttachmentFileTest < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
test "Set file content_type and size" do
|
9
9
|
@attachment = create_attachment
|
10
|
-
|
10
|
+
|
11
11
|
# TODO: fix filename parameterization
|
12
12
|
if CKEDITOR_BACKEND == :paperclip
|
13
13
|
assert_equal "rails_tar.gz", @attachment.data_file_name
|
14
14
|
else
|
15
15
|
assert_equal "rails.tar.gz", @attachment.data_file_name
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
assert_equal "application/x-gzip", @attachment.data_content_type
|
19
19
|
assert_equal 6823, @attachment.data_file_size
|
20
20
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/gz.gif", @attachment.url_thumb
|
data/test/models/picture_test.rb
CHANGED
@@ -7,12 +7,12 @@ class PictureTest < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
test "Set file content_type and size" do
|
9
9
|
@picture = create_picture
|
10
|
-
|
10
|
+
|
11
11
|
assert_equal "image/png", @picture.data_content_type
|
12
12
|
assert_equal "rails.png", @picture.data_file_name
|
13
13
|
assert_equal 6646, @picture.data_file_size
|
14
14
|
assert @picture.url_thumb.include?('thumb_rails.png')
|
15
|
-
|
15
|
+
|
16
16
|
if @picture.has_dimensions?
|
17
17
|
assert_equal 50, @picture.width
|
18
18
|
assert_equal 64, @picture.height
|
data/test/models/utils_test.rb
CHANGED
@@ -2,15 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class UtilsTest < ActiveSupport::TestCase
|
4
4
|
test 'exists filethumb' do
|
5
|
-
|
6
|
-
"psd", "rar", "swf", "tar", "txt", "wmv", "xlsx", "zip"].each do |ext|
|
5
|
+
%w(avi doc docx exe gz htm jpg mp3 mpg pdf psd rar swf tar txt wmv xlsx zip).each do |ext|
|
7
6
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/#{ext}.gif", Ckeditor::Utils.filethumb("somefile.#{ext}")
|
8
7
|
end
|
9
|
-
|
8
|
+
|
10
9
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/unknown.gif", Ckeditor::Utils.filethumb("somefile.ddd")
|
11
10
|
end
|
12
|
-
|
13
|
-
test 'wrong filethumb' do
|
11
|
+
|
12
|
+
test 'wrong filethumb' do
|
14
13
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/unknown.gif", Ckeditor::Utils.filethumb("somefile.ddd")
|
15
14
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/unknown.gif", Ckeditor::Utils.filethumb("somefile")
|
16
15
|
assert_equal "/assets/ckeditor/filebrowser/images/thumbs/unknown.gif", Ckeditor::Utils.filethumb("")
|
data/test/support/helpers.rb
CHANGED
@@ -3,25 +3,25 @@ require 'action_dispatch/testing/test_process'
|
|
3
3
|
|
4
4
|
class ActiveSupport::TestCase
|
5
5
|
include ActionDispatch::TestProcess
|
6
|
-
|
6
|
+
|
7
7
|
def new_attachment(data = nil)
|
8
8
|
data ||= fixture_file_upload('files/rails.tar.gz', 'application/x-gzip')
|
9
|
-
|
9
|
+
|
10
10
|
Ckeditor.attachment_file_model.new(:data => data)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def create_attachment(data = nil)
|
14
14
|
attachment = new_attachment(data)
|
15
15
|
attachment.save!
|
16
16
|
attachment
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def new_picture(data = nil)
|
20
20
|
data ||= fixture_file_upload('files/rails.png', 'image/png')
|
21
|
-
|
21
|
+
|
22
22
|
Ckeditor.picture_model.new(:data => data)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def create_picture(data = nil)
|
26
26
|
picture = new_picture(data)
|
27
27
|
picture.save!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ckeditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|