Skip to content

Commit be3d951

Browse files
committed
Load classes by ActiveSupport::Dependencies.ref
1 parent 71347cd commit be3d951

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

app/controllers/ckeditor_controller.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
class CkeditorController < ApplicationController
22
skip_before_filter :verify_authenticity_token, :only => [:create]
33
before_filter :swf_options, :only => [:images, :files, :create]
4+
respond_to :html, :xml, :json
45
layout "ckeditor"
56

67
# GET /ckeditor/images
78
def images
8-
@images = Ckeditor.image_model.find(:all, :order=>"id DESC")
9-
10-
respond_to do |format|
11-
format.html {}
12-
format.xml { render :xml=>@images }
13-
end
9+
@images = Ckeditor.image_model.order("id DESC")
10+
respond_with(@images)
1411
end
1512

1613
# GET /ckeditor/files
1714
def files
18-
@files = Ckeditor.file_model.find(:all, :order=>"id DESC")
19-
20-
respond_to do |format|
21-
format.html {}
22-
format.xml { render :xml=>@files }
23-
end
15+
@files = Ckeditor.file_model.order("id DESC")
16+
respond_with(@files)
2417
end
2518

2619
# POST /ckeditor/create/:kind
@@ -48,7 +41,7 @@ def create
4841

4942
if @record.valid? && @record.save
5043
@text = params[:CKEditor].blank? ? @record.to_json(:only=>[:id, :type], :methods=>[:url, :content_type, :size, :filename, :format_created_at], :root => "asset") : %Q"<script type='text/javascript'>
51-
window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{escape_single_quotes(@record.url_content)}');
44+
window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(@record.url_content)}');
5245
</script>"
5346

5447
render :text => @text
@@ -80,9 +73,4 @@ def swf_options
8073
@file_types_description ||= "Images"
8174
@file_upload_limit ||= 10
8275
end
83-
84-
def escape_single_quotes(str)
85-
str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
86-
end
87-
8876
end

ckeditor.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
Gem::Specification.new do |s|
77
s.name = %q{ckeditor}
8-
s.version = "3.4.0.pre"
8+
s.version = "3.4.1.pre"
99

1010
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Igor Galeta"]
12-
s.date = %q{2010-08-20}
12+
s.date = %q{2010-08-31}
1313
s.description = %q{CKEditor is a WYSIWYG editor to be used inside web pages}
1414
s.email = %q{[email protected]}
1515
s.extra_rdoc_files = [

lib/ckeditor.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,27 @@ module Ckeditor
4949
mattr_accessor :file_manager_image_uri
5050
@@file_manager_image_uri = "/ckeditor/images"
5151

52-
mattr_accessor :file_manager_image_model
53-
@@file_manager_image_model = "Ckeditor::Picture"
54-
55-
mattr_accessor :file_manager_file_model
56-
@@file_manager_file_model = "Ckeditor::AttachmentFile"
57-
52+
# Get the image class from the image reference object.
5853
def self.image_model
59-
@@image_model ||= @@file_manager_image_model.to_s.constantize
60-
@@image_model
54+
@@image_model_ref.get
55+
end
56+
57+
# Set the image model reference object to access the images.
58+
def self.file_manager_image_model=(class_name)
59+
@@image_model_ref = ActiveSupport::Dependencies.ref(class_name)
6160
end
61+
self.file_manager_image_model = "Ckeditor::Picture"
6262

63+
# Get the file class from the file reference object.
6364
def self.file_model
64-
@@file_model ||= @@file_manager_file_model.to_s.constantize
65-
@@file_model
65+
@@file_model_ref.get
66+
end
67+
68+
# Set the file model reference object to access the files.
69+
def self.file_manager_file_model=(class_name)
70+
@@file_model_ref = ActiveSupport::Dependencies.ref(class_name)
6671
end
72+
self.file_manager_file_model = "Ckeditor::AttachmentFile"
6773

6874
# Default way to setup Ckeditor. Run rails generate ckeditor to create
6975
# a fresh initializer with all configuration values.

lib/ckeditor/utils.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
module Ckeditor
44
module Utils
5-
CKEDITOR_INSTALL_DIRECTORY = Rails.root.join('/public/javascripts/ckeditor/')
65

7-
##################################################################
86
# remove the existing install (if any)
9-
def self.destroy
10-
if File.exist?(CKEDITOR_INSTALL_DIRECTORY)
11-
FileUtils.rm_r(CKEDITOR_INSTALL_DIRECTORY)
7+
def self.destroy
8+
directory = Rails.root.join('public', 'javascripts', 'ckeditor')
9+
if File.exist?(directory)
10+
FileUtils.rm_r(directory, :force => true)
1211
end
1312
end
13+
14+
def self.escape_single_quotes(str)
15+
str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
16+
end
1417
end
1518
end

lib/ckeditor/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Ckeditor
22
module Version
33
MAJOR = 3
44
MINOR = 4
5-
RELEASE = 0
5+
RELEASE = 1
66

77
def self.dup
88
"#{MAJOR}.#{MINOR}.#{RELEASE}.pre"

0 commit comments

Comments
 (0)