ckeditor 3.5.4 → 3.6.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +23 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +96 -97
- data/Rakefile +16 -33
- data/app/controllers/ckeditor/attachment_files_controller.rb +4 -4
- data/app/controllers/ckeditor/base_controller.rb +15 -42
- data/app/controllers/ckeditor/pictures_controller.rb +3 -3
- data/app/views/ckeditor/attachment_files/index.html.erb +13 -51
- data/app/views/ckeditor/pictures/index.html.erb +14 -52
- data/app/views/ckeditor/shared/_asset.html.erb +19 -0
- data/app/views/ckeditor/shared/_asset_tmpl.html.erb +21 -0
- data/app/views/layouts/ckeditor.html.erb +16 -23
- data/config/locales/en.ckeditor.yml +3 -7
- data/config/locales/ru.ckeditor.yml +4 -8
- data/config/locales/uk.ckeditor.yml +4 -8
- data/config/routes.rb +3 -3
- data/lib/ckeditor.rb +30 -79
- data/lib/ckeditor/engine.rb +14 -13
- data/lib/ckeditor/helpers/controllers.rb +30 -0
- data/lib/ckeditor/helpers/form_builder.rb +11 -0
- data/lib/ckeditor/helpers/form_helper.rb +25 -0
- data/lib/ckeditor/helpers/view_helper.rb +19 -0
- data/lib/ckeditor/http.rb +81 -0
- data/lib/ckeditor/orm/active_record.rb +91 -0
- data/lib/ckeditor/utils.rb +51 -70
- data/lib/ckeditor/version.rb +2 -7
- data/lib/generators/ckeditor/install_generator.rb +62 -0
- data/lib/generators/ckeditor/models_generator.rb +51 -0
- data/lib/generators/ckeditor/templates/ckeditor.rb +18 -0
- data/lib/generators/ckeditor/templates/ckeditor/config.js +52 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/ckfnothumb.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/mp3.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/pdf.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/rar.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/swf.gif +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/xls.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +222 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css +112 -0
- data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/attachment/dialogs/attachment.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/images/attachment.png +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/en.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/ru.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/uk.js +0 -0
- data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/attachment/plugin.js +0 -0
- data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/embed/dialogs/embed.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/images/embed.png +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/en.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/ru.js +0 -0
- data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/uk.js +0 -0
- data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/embed/plugin.js +0 -0
- data/lib/generators/ckeditor/templates/models/active_record/asset.rb +7 -0
- data/lib/generators/ckeditor/templates/models/active_record/attachment_file.rb +15 -0
- data/lib/generators/ckeditor/{migration/templates/models/paperclip → templates/models/active_record}/migration.rb +3 -8
- data/lib/generators/ckeditor/templates/models/active_record/picture.rb +13 -0
- data/test/ckeditor_test.rb +13 -0
- data/test/controllers/attachment_files_controller_test.rb +52 -0
- data/test/controllers/pictures_controller_test.rb +52 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -0
- data/test/dummy/app/controllers/posts_controller.rb +83 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/models/ckeditor/asset.rb +7 -0
- data/test/dummy/app/models/ckeditor/attachment_file.rb +15 -0
- data/test/dummy/app/models/ckeditor/picture.rb +13 -0
- data/test/dummy/app/models/post.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/posts/_form.html.erb +30 -0
- data/test/dummy/app/views/posts/edit.html.erb +6 -0
- data/test/dummy/app/views/posts/index.html.erb +27 -0
- data/test/dummy/app/views/posts/new.html.erb +5 -0
- data/test/dummy/app/views/posts/show.html.erb +5 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +46 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +34 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/ckeditor.rb +18 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/migrate/20110623120047_create_posts.rb +14 -0
- data/test/dummy/db/migrate/20110705195648_create_ckeditor_assets.rb +26 -0
- data/test/dummy/db/schema.rb +36 -0
- data/test/dummy/log/development.log +818 -0
- data/test/dummy/log/production.log +0 -0
- data/test/dummy/log/server.log +0 -0
- data/test/dummy/log/test.log +5398 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/public/stylesheets/scaffold.css +56 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/files/rails.png +0 -0
- data/test/dummy/test/fixtures/files/rails.tar.gz +0 -0
- data/test/generators/install_generator_test.rb +18 -0
- data/test/generators/models_generator_test.rb +21 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/integration/posts_test.rb +41 -0
- data/test/routes_test.rb +47 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +28 -0
- data/test/tmp/app/models/ckeditor/asset.rb +7 -0
- data/test/tmp/app/models/ckeditor/attachment_file.rb +15 -0
- data/test/tmp/app/models/ckeditor/picture.rb +13 -0
- data/test/tmp/db/migrate/20110711170413_create_ckeditor_assets.rb +26 -0
- metadata +220 -99
- data/CHANGELOG +0 -15
- data/app/helpers/ckeditor/base_helper.rb +0 -21
- data/app/views/ckeditor/_asset.html.erb +0 -20
- data/app/views/ckeditor/_swfupload.html.erb +0 -73
- data/lib/ckeditor/form_builder.rb +0 -22
- data/lib/ckeditor/middleware.rb +0 -18
- data/lib/ckeditor/view_helper.rb +0 -92
- data/lib/generators/ckeditor/base/USAGE +0 -9
- data/lib/generators/ckeditor/base/base_generator.rb +0 -41
- data/lib/generators/ckeditor/base/templates/ckeditor.rb +0 -54
- data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/attachment/dialogs/attachment.js +0 -384
- data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/attachment/plugin.js +0 -44
- data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/embed/dialogs/embed.js +0 -65
- data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/embed/plugin.js +0 -43
- data/lib/generators/ckeditor/base/templates/ckeditor/config.js +0 -43
- data/lib/generators/ckeditor/base/templates/ckeditor/css/ckfinder.css +0 -316
- data/lib/generators/ckeditor/base/templates/ckeditor/css/fck_dialog.css +0 -119
- data/lib/generators/ckeditor/base/templates/ckeditor/css/fck_editor.css +0 -448
- data/lib/generators/ckeditor/base/templates/ckeditor/css/swfupload.css +0 -94
- data/lib/generators/ckeditor/base/templates/ckeditor/images/add.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/cancelbutton.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/doc.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/refresh.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/select_files.png +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/spacer.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/images/toolbar.start.gif +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/images/attachment.png +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/en.js +0 -10
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/ru.js +0 -10
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/uk.js +0 -10
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/images/embed.png +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/en.js +0 -9
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/ru.js +0 -9
- data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/uk.js +0 -9
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/fileprogress.js +0 -266
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/handlers.js +0 -181
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/jquery-1.5.1.min.js +0 -16
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/querystring.js +0 -40
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/rails.js +0 -158
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.js +0 -1
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.queue.js +0 -1
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.swf +0 -0
- data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.swfobject.js +0 -111
- data/lib/generators/ckeditor/migration/USAGE +0 -12
- data/lib/generators/ckeditor/migration/migration_generator.rb +0 -46
- data/lib/generators/ckeditor/migration/templates/models/attachment_fu/asset.rb +0 -32
- data/lib/generators/ckeditor/migration/templates/models/attachment_fu/attachment_file.rb +0 -24
- data/lib/generators/ckeditor/migration/templates/models/attachment_fu/migration.rb +0 -30
- data/lib/generators/ckeditor/migration/templates/models/attachment_fu/picture.rb +0 -25
- data/lib/generators/ckeditor/migration/templates/models/paperclip/asset.rb +0 -97
- data/lib/generators/ckeditor/migration/templates/models/paperclip/attachment_file.rb +0 -40
- data/lib/generators/ckeditor/migration/templates/models/paperclip/picture.rb +0 -23
- data/lib/tasks/ckeditor_tasks.rake +0 -3
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ckeditor
|
2
|
+
module Helpers
|
3
|
+
module Controllers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def ckeditor_authenticate
|
9
|
+
return true
|
10
|
+
end
|
11
|
+
|
12
|
+
def ckeditor_before_create_asset(asset)
|
13
|
+
asset.assetable = current_user if respond_to?(:current_user)
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
|
17
|
+
def ckeditor_pictures_scope(options = {})
|
18
|
+
ckeditor_filebrowser_scope(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ckeditor_attachment_files_scope(options = {})
|
22
|
+
ckeditor_filebrowser_scope(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ckeditor_filebrowser_scope(options = {})
|
26
|
+
{ :order => [:id, :desc] }.merge(options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Ckeditor
|
2
|
+
module Helpers
|
3
|
+
module FormHelper
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
include ActionView::Helpers::TagHelper
|
7
|
+
include ActionView::Helpers::JavaScriptHelper
|
8
|
+
|
9
|
+
def cktext_area(object_name, method, options = {})
|
10
|
+
options = { :language => I18n.locale.to_s }.merge(options)
|
11
|
+
input_html = (options.delete(:input_html) || {})
|
12
|
+
hash = input_html.stringify_keys
|
13
|
+
|
14
|
+
instance_tag = ActionView::Base::InstanceTag.new(object_name, method, self, options.delete(:object))
|
15
|
+
instance_tag.send(:add_default_name_and_id, hash)
|
16
|
+
|
17
|
+
output_buffer = ActiveSupport::SafeBuffer.new
|
18
|
+
output_buffer << instance_tag.to_text_area_tag(input_html)
|
19
|
+
output_buffer << javascript_tag(Utils.js_replace(hash['id'], options))
|
20
|
+
|
21
|
+
output_buffer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ckeditor
|
2
|
+
module Helpers
|
3
|
+
module ViewHelper
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def cktext_area_tag(name, content = nil, options = {})
|
7
|
+
element_id = sanitize_to_id(name)
|
8
|
+
options = { :language => I18n.locale.to_s }.merge(options)
|
9
|
+
input_html = { :id => element_id }.merge( options.delete(:input_html) || {} )
|
10
|
+
|
11
|
+
output_buffer = ActiveSupport::SafeBuffer.new
|
12
|
+
output_buffer << text_area_tag(name, content, input_html)
|
13
|
+
output_buffer << javascript_tag(Utils.js_replace(element_id, options))
|
14
|
+
|
15
|
+
output_buffer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'mime/types'
|
4
|
+
|
5
|
+
module Ckeditor
|
6
|
+
module Http
|
7
|
+
# Create tempfile from hash
|
8
|
+
class UploadedFile
|
9
|
+
attr_accessor :original_filename, :content_type, :tempfile, :headers
|
10
|
+
|
11
|
+
def initialize(hash)
|
12
|
+
@original_filename = hash[:filename]
|
13
|
+
@content_type = hash[:type]
|
14
|
+
@headers = hash[:head]
|
15
|
+
@tempfile = hash[:tempfile]
|
16
|
+
raise(ArgumentError, ':tempfile is required') unless @tempfile
|
17
|
+
end
|
18
|
+
|
19
|
+
def open
|
20
|
+
@tempfile.open
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
@tempfile.path
|
25
|
+
end
|
26
|
+
|
27
|
+
def read(*args)
|
28
|
+
@tempfile.read(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def rewind
|
32
|
+
@tempfile.rewind
|
33
|
+
end
|
34
|
+
|
35
|
+
def size
|
36
|
+
@tempfile.size
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Usage (paperclip example)
|
41
|
+
# @asset.data = QqFile.new(params[:qqfile], request)
|
42
|
+
class QqFile < ::Tempfile
|
43
|
+
|
44
|
+
def initialize(filename, request, tmpdir = Dir::tmpdir)
|
45
|
+
@original_filename = filename
|
46
|
+
@request = request
|
47
|
+
|
48
|
+
super Digest::SHA1.hexdigest(filename), tmpdir
|
49
|
+
fetch
|
50
|
+
end
|
51
|
+
|
52
|
+
def fetch
|
53
|
+
self.write @request.raw_post
|
54
|
+
self.rewind
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def original_filename
|
59
|
+
@original_filename
|
60
|
+
end
|
61
|
+
|
62
|
+
def content_type
|
63
|
+
types = MIME::Types.type_for(@request.content_type)
|
64
|
+
types.empty? ? @request.content_type : types.first.to_s
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Convert nested Hash to HashWithIndifferentAccess and replace
|
69
|
+
# file upload hash with UploadedFile objects
|
70
|
+
def self.normalize_param(*args)
|
71
|
+
value = args.first
|
72
|
+
if Hash === value && value.has_key?(:tempfile)
|
73
|
+
UploadedFile.new(value)
|
74
|
+
elsif value.is_a?(String)
|
75
|
+
QqFile.new(*args)
|
76
|
+
else
|
77
|
+
value
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Ckeditor
|
2
|
+
module Orm
|
3
|
+
module ActiveRecord
|
4
|
+
module AssetBase
|
5
|
+
def self.included(base)
|
6
|
+
base.send(:include, InstanceMethods)
|
7
|
+
base.send(:extend, ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def self.extended(base)
|
12
|
+
base.class_eval do
|
13
|
+
set_table_name "ckeditor_assets"
|
14
|
+
|
15
|
+
belongs_to :assetable, :polymorphic => true
|
16
|
+
|
17
|
+
before_validation :extract_content_type
|
18
|
+
before_create :read_dimensions, :parameterize_filename
|
19
|
+
|
20
|
+
delegate :url, :path, :styles, :size, :content_type, :to => :data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
def filename
|
27
|
+
data_file_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_created_at
|
31
|
+
I18n.l(created_at, :format => "%d.%m.%Y")
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_dimensions?
|
35
|
+
respond_to?(:width) && respond_to?(:height)
|
36
|
+
end
|
37
|
+
|
38
|
+
def image?
|
39
|
+
Ckeditor::IMAGE_TYPES.include?(data_content_type)
|
40
|
+
end
|
41
|
+
|
42
|
+
def geometry
|
43
|
+
@geometry ||= Paperclip::Geometry.from_file(data.to_file)
|
44
|
+
@geometry
|
45
|
+
end
|
46
|
+
|
47
|
+
def url_content
|
48
|
+
url
|
49
|
+
end
|
50
|
+
|
51
|
+
def url_thumb
|
52
|
+
url(:thumb)
|
53
|
+
end
|
54
|
+
|
55
|
+
def as_json(options = nil)
|
56
|
+
options = {
|
57
|
+
:methods => [:url_content, :url_thumb, :size, :filename, :format_created_at],
|
58
|
+
:root => "asset"
|
59
|
+
}.merge(options || {})
|
60
|
+
|
61
|
+
super options
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def parameterize_filename
|
67
|
+
unless data_file_name.blank?
|
68
|
+
filename = Ckeditor::Utils.parameterize_filename(data_file_name)
|
69
|
+
self.data.instance_write(:file_name, filename)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_dimensions
|
74
|
+
if image? && has_dimensions?
|
75
|
+
self.width = geometry.width
|
76
|
+
self.height = geometry.height
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Extract content_type from filename using mime/types gem
|
81
|
+
def extract_content_type
|
82
|
+
if data_content_type == "application/octet-stream" && !data_file_name.blank?
|
83
|
+
content_types = MIME::Types.type_for(data_file_name)
|
84
|
+
self.data_content_type = content_types.first.to_s unless content_types.empty?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/ckeditor/utils.rb
CHANGED
@@ -1,70 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'fileutils'
|
3
|
-
require 'open-uri'
|
4
|
-
require 'digest/sha1'
|
5
|
-
require 'mime/types'
|
6
|
-
|
7
2
|
module Ckeditor
|
8
3
|
module Utils
|
9
|
-
# RemoteFile
|
10
|
-
#
|
11
|
-
# remote_file = RemoteFile.new("http://www.google.com/intl/en_ALL/images/logo.gif")
|
12
|
-
# remote_file.original_filename #=> logo.gif
|
13
|
-
# remote_file.content_type #= image/gif
|
14
|
-
#
|
15
|
-
class RemoteFile < ::Tempfile
|
16
|
-
|
17
|
-
def initialize(path, tmpdir = Dir::tmpdir)
|
18
|
-
@original_filename = File.basename(path)
|
19
|
-
@remote_path = path
|
20
|
-
|
21
|
-
super Digest::SHA1.hexdigest(path), tmpdir
|
22
|
-
fetch
|
23
|
-
end
|
24
|
-
|
25
|
-
def fetch
|
26
|
-
string_io = OpenURI.send(:open, @remote_path)
|
27
|
-
body = string_io.read
|
28
|
-
|
29
|
-
# Fix for ruby 1.9.2 (ASCII-8BIT and UTF-8 in hell issue)
|
30
|
-
if body && body.respond_to?(:encoding) && body.encoding.name == 'ASCII-8BIT'
|
31
|
-
body.force_encoding('UTF-8')
|
32
|
-
end
|
33
|
-
|
34
|
-
self.write body
|
35
|
-
self.rewind
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
def original_filename
|
40
|
-
@original_filename
|
41
|
-
end
|
42
|
-
|
43
|
-
def content_type
|
44
|
-
types = MIME::Types.type_for(self.path)
|
45
|
-
types.empty? ? extract_content_type : types.first.to_s
|
46
|
-
end
|
47
|
-
|
48
|
-
protected
|
49
|
-
|
50
|
-
def extract_content_type
|
51
|
-
mime = `file --mime -br #{self.path}`.strip
|
52
|
-
mime = mime.gsub(/^.*: */,"")
|
53
|
-
mime = mime.gsub(/;.*$/,"")
|
54
|
-
mime = mime.gsub(/,.*$/,"")
|
55
|
-
mime
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
4
|
class << self
|
60
|
-
# remove the existing install (if any)
|
61
|
-
def destroy
|
62
|
-
directory = Rails.root.join('public', 'javascripts', 'ckeditor')
|
63
|
-
if File.exist?(directory)
|
64
|
-
FileUtils.rm_r(directory, :force => true)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
5
|
def escape_single_quotes(str)
|
69
6
|
str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
70
7
|
end
|
@@ -76,20 +13,64 @@ module Ckeditor
|
|
76
13
|
[basename.parameterize('_'), extension].join.downcase
|
77
14
|
end
|
78
15
|
|
79
|
-
def download(url)
|
80
|
-
RemoteFile.new(url)
|
81
|
-
end
|
82
|
-
|
83
16
|
def extract(filepath, output)
|
84
17
|
# TODO: need check system OS
|
85
18
|
system("tar --exclude=*.php --exclude=*.asp -C '#{output}' -xzvf '#{filepath}' ckeditor/")
|
86
19
|
end
|
87
20
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
21
|
+
def js_replace(dom_id, options = {})
|
22
|
+
js_options = applay_options(options)
|
23
|
+
js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"]
|
24
|
+
|
25
|
+
if js_options.blank?
|
26
|
+
js << "CKEDITOR.replace('#{dom_id}');"
|
27
|
+
else
|
28
|
+
js << "CKEDITOR.replace('#{dom_id}', { #{js_options} });"
|
29
|
+
end
|
30
|
+
|
31
|
+
js.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def js_fileuploader(uploader_type, options = {})
|
35
|
+
options = { :multiple => true, :element => "fileupload" }.merge(options)
|
36
|
+
|
37
|
+
case uploader_type.to_s.downcase
|
38
|
+
when "image" then
|
39
|
+
options[:action] = "^EDITOR.config.filebrowserImageUploadUrl"
|
40
|
+
options[:allowedExtensions] = Ckeditor.image_file_types
|
41
|
+
when "flash" then
|
42
|
+
options[:action] = "^EDITOR.config.filebrowserFlashUploadUrl"
|
43
|
+
options[:allowedExtensions] = ["swf"]
|
44
|
+
else
|
45
|
+
options[:action] = "^EDITOR.config.filebrowserUploadUrl"
|
46
|
+
options[:allowedExtensions] = Ckeditor.attachment_file_types
|
47
|
+
end
|
48
|
+
|
49
|
+
js_options = applay_options(options)
|
50
|
+
|
51
|
+
"$(document).ready(function(){ new qq.FileUploaderInput({ #{js_options} }); });"
|
91
52
|
end
|
92
53
|
|
54
|
+
def applay_options(options)
|
55
|
+
str = []
|
56
|
+
|
57
|
+
options.each do |key, value|
|
58
|
+
item = case value
|
59
|
+
when String then
|
60
|
+
value.split(//).first == '^' ? value.slice(1..-1) : "'#{value}'"
|
61
|
+
when Hash then
|
62
|
+
"{ #{applay_options(value)} }"
|
63
|
+
when Array then
|
64
|
+
arr = value.collect { |v| "'#{v}'" }
|
65
|
+
"[ #{arr.join(',')} ]"
|
66
|
+
else value
|
67
|
+
end
|
68
|
+
|
69
|
+
str << "#{key}: #{item}"
|
70
|
+
end
|
71
|
+
|
72
|
+
str.sort.join(',')
|
73
|
+
end
|
93
74
|
end
|
94
75
|
end
|
95
76
|
end
|
data/lib/ckeditor/version.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Ckeditor
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
class_option :version, :type => :string, :default => Ckeditor::Version::EDITOR,
|
8
|
+
:desc => "Version of ckeditor which be install"
|
9
|
+
|
10
|
+
desc "Download and install ckeditor"
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
14
|
+
end
|
15
|
+
|
16
|
+
# copy configuration
|
17
|
+
def copy_initializer
|
18
|
+
template "ckeditor.rb", "config/initializers/ckeditor.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
# copy ckeditor files
|
22
|
+
def install_ckeditor
|
23
|
+
say_status("fetching #{filename}", "", :green)
|
24
|
+
get(download_url, "tmp/#{filename}")
|
25
|
+
|
26
|
+
filepath = Rails.root.join("tmp/#{filename}")
|
27
|
+
|
28
|
+
if File.exist?(filepath)
|
29
|
+
Ckeditor::Utils.extract(filepath, Rails.root.join('public', 'javascripts'))
|
30
|
+
directory "ckeditor", "public/javascripts/ckeditor"
|
31
|
+
FileUtils.rm_rf(filepath)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def download_javascripts
|
36
|
+
js_dir = "public/javascripts/ckeditor/filebrowser/javascripts"
|
37
|
+
|
38
|
+
say_status("fetching rails.js", "", :green)
|
39
|
+
get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "#{js_dir}/rails.js"
|
40
|
+
|
41
|
+
say_status("fetching fileuploader.js", "", :green)
|
42
|
+
get "https://raw.github.com/galetahub/file-uploader/master/client/fileuploader.js", "#{js_dir}/fileuploader.js"
|
43
|
+
|
44
|
+
say_status("fetching jquery-1.6.1.min.js", "", :green)
|
45
|
+
get "http://code.jquery.com/jquery-1.6.1.min.js", "#{js_dir}/jquery.js"
|
46
|
+
|
47
|
+
say_status("fetching jquery.tmpl.min.js", "", :green)
|
48
|
+
get "https://raw.github.com/jquery/jquery-tmpl/master/jquery.tmpl.min.js", "#{js_dir}/jquery.tmpl.js"
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def download_url
|
54
|
+
"http://download.cksource.com/CKEditor/CKEditor/CKEditor%20#{options[:version]}/#{filename}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def filename
|
58
|
+
"ckeditor_#{options[:version]}.tar.gz"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|