Skip to content

Commit

Permalink
Update ckeditor to version 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
galetahub committed Jan 19, 2010
1 parent 3533d7d commit b3770f7
Show file tree
Hide file tree
Showing 439 changed files with 12,771 additions and 2,898 deletions.
9 changes: 5 additions & 4 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ the results users have when publishing it. It brings to the web common editing f
Because CKEditor is licensed under flexible Open Source and commercial licenses, you'll be able to integrate and use it inside any kind of application.
This is the ideal editor for developers, created to provide easy and powerful solutions to their users.

CKEditor version: 3.0.2
CKEditor version: 3.1
SWFUpload version: 2.2.0
Rails version: 2.3.x

http://ckeditor.com/
http://swfupload.org/
"ckeditor.com":http://ckeditor.com/
"swfupload.org":http://swfupload.org/

Demo appication:
http://github.com/galetahub/rails-ckeditor-demo-app
"rails-ckeditor-demo-app":http://github.com/galetahub/rails-ckeditor-demo-app

h2. Install

Expand Down
5 changes: 5 additions & 0 deletions app/helpers/ckeditor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def file_image_tag(filename, path)
image = case extname.to_s
when '.swf' then '/javascripts/ckeditor/images/swf.gif'
when '.pdf' then '/javascripts/ckeditor/images/pdf.gif'
when '.doc', '.txt' then '/javascripts/ckeditor/images/doc.gif'
when '.mp3' then '/javascripts/ckeditor/images/mp3.gif'
when '.rar', '.zip', '.tg' then '/javascripts/ckeditor/images/rar.gif'
when '.xls' then '/javascripts/ckeditor/images/xls.gif'
else '/javascripts/ckeditor/images/ckfnothumb.gif'
end

image_tag(image, :alt=>path, :title=>filename, :onerror=>"this.src='/javascripts/ckeditor/images/ckfnothumb.gif'", :class=>'image')
Expand Down
12 changes: 5 additions & 7 deletions app/views/ckeditor/_swfupload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// Backend settings
upload_url: upload_path,
post_params: params,
file_post_name: <%= @swf_file_post_name.inspect %>,
file_post_name: "<%= @swf_file_post_name %>",

// Flash file settings
file_size_limit : <%= @file_size_limit.inspect %>,
file_types : <%= @file_types.inspect %>,
file_types_description : <%= @file_types_description.inspect %>,
file_upload_limit : <%= @file_upload_limit %>,
file_size_limit : "<%= @file_size_limit %>",
file_types : "<%= @file_types %>",
file_types_description : "<%= @file_types_description %>",
file_upload_limit : "<%= @file_upload_limit %>",
file_queue_limit : 0,

// The event handler functions are defined in handlers.js
Expand Down Expand Up @@ -42,12 +42,10 @@

custom_settings : {
progressTarget : "divFileProgressContainer"
//cancelButtonId : "btn_cancel"
},

// Debug settings
debug: false
});

};
</script>
30 changes: 4 additions & 26 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
# Include hook code here
require 'ckeditor_config'
require 'ckeditor'
require 'ckeditor_version'
require 'ckeditor_file_utils'
Dir[File.join(File.dirname(__FILE__), 'vendor/*/lib')].each do |path|
$LOAD_PATH.unshift path
end

CkeditorFileUtils.check_and_install
require 'ckeditor'

# make plugin controller available to app
config.load_paths += %W(#{Ckeditor::PLUGIN_CONTROLLER_PATH} #{Ckeditor::PLUGIN_HELPER_PATH})

Rails::Initializer.run(:set_load_path, config)

ActionView::Base.send(:include, Ckeditor::Helper)

# require the controller
require 'ckeditor_controller'

class ActionController::Routing::RouteSet
unless (instance_methods.include?('draw_with_ckeditor'))
class_eval <<-"end_eval", __FILE__, __LINE__
alias draw_without_ckeditor draw
def draw_with_ckeditor
draw_without_ckeditor do |map|
map.connect 'ckeditor/images', :controller => 'ckeditor', :action => 'images'
map.connect 'ckeditor/files', :controller => 'ckeditor', :action => 'files'
map.connect 'ckeditor/create', :controller => 'ckeditor', :action => 'create'
yield map
end
end
alias draw draw_with_ckeditor
end_eval
end
end

172 changes: 30 additions & 142 deletions lib/ckeditor.rb
Original file line number Diff line number Diff line change
@@ -1,138 +1,36 @@
# Ckeditor
module Ckeditor
PLUGIN_NAME = 'rails-ckeditor'
PLUGIN_PATH = File.join(RAILS_ROOT, "vendor/plugins", PLUGIN_NAME)

PLUGIN_PUBLIC_PATH = Ckeditor::Config.exists? ? Ckeditor::Config['public_path'] : "#{RAILS_ROOT}/public/uploads"
PLUGIN_PUBLIC_URI = Ckeditor::Config.exists? ? Ckeditor::Config['public_uri'] : "/uploads"

PLUGIN_CONTROLLER_PATH = File.join(PLUGIN_PATH, "/app/controllers")
PLUGIN_VIEWS_PATH = File.join(PLUGIN_PATH, "/app/views")
PLUGIN_HELPER_PATH = File.join(PLUGIN_PATH, "/app/helpers")

PLUGIN_FILE_MANAGER_URI = Ckeditor::Config.exists? ? Ckeditor::Config['file_manager_uri'] : ""
PLUGIN_FILE_MANAGER_UPLOAD_URI = Ckeditor::Config.exists? ? Ckeditor::Config['file_manager_upload_uri'] : ""
PLUGIN_FILE_MANAGER_IMAGE_URI = Ckeditor::Config.exists? ? Ckeditor::Config['file_manager_image_uri'] : ""
PLUGIN_FILE_MANAGER_IMAGE_UPLOAD_URI = Ckeditor::Config.exists? ? Ckeditor::Config['file_manager_image_upload_uri'] : ""

module Helper
include ActionView::Helpers

def ckeditor_textarea(object, field, options = {})
options.symbolize_keys!

var = options.delete(:object) if options.key?(:object)
var ||= @template.instance_variable_get("@#{object}")

if var
value = var.send(field.to_sym)
value = value.nil? ? "" : value
else
value = ""

begin
klass = "#{object}".camelcase.constantize
@template.instance_variable_set("@#{object}", eval("#{klass}.new()"))
rescue NameError
end
end
id = ckeditor_element_id(object, field)

textarea_options = { :id => id }

textarea_options[:cols] = options[:cols].nil? ? 70 : options[:cols].to_i
textarea_options[:rows] = options[:rows].nil? ? 20 : options[:rows].to_i

width = options[:width].nil? ? '100%' : options[:width]
height = options[:height].nil? ? '100%' : options[:height]

textarea_options[:class] = options[:class] unless options[:class].nil?

ckeditor_options = {}

ckeditor_options[:toolbar] = options[:toolbar] unless options[:toolbar].nil?
ckeditor_options[:skin] = options[:skin] unless options[:skin].nil?
ckeditor_options[:language] = options[:language] unless options[:language].nil?
ckeditor_options[:width] = options[:width] unless options[:width].nil?
ckeditor_options[:height] = options[:height] unless options[:height].nil?

ckeditor_options[:swf_params] = options[:swf_params] unless options[:swf_params].nil?

ckeditor_options[:filebrowserBrowseUrl] = PLUGIN_FILE_MANAGER_URI
ckeditor_options[:filebrowserUploadUrl] = PLUGIN_FILE_MANAGER_UPLOAD_URI

ckeditor_options[:filebrowserImageBrowseUrl] = PLUGIN_FILE_MANAGER_IMAGE_URI
ckeditor_options[:filebrowserImageUploadUrl] = PLUGIN_FILE_MANAGER_IMAGE_UPLOAD_URI

output_buffer = ActionView::SafeBuffer.new

if options[:ajax]
textarea_options.update(:name => id)

output_buffer << tag(:input, { "type" => "hidden", "name" => "#{object}[#{field}]", "id" => "#{id}_hidden"})
output_buffer << ActionView::Base::InstanceTag.new(object, field, self, var).to_text_area_tag(textarea_options)
else
textarea_options.update(:style => "width:#{width};height:#{height}")

output_buffer << ActionView::Base::InstanceTag.new(object, field, self, var).to_text_area_tag(textarea_options)
end

output_buffer << javascript_tag("CKEDITOR.replace('#{object}[#{field}]', {
#{ckeditor_applay_options(ckeditor_options)}
});\n")

output_buffer
end

def ckeditor_form_remote_tag(options = {})
editors = options[:editors]
before = ""
editors.keys.each do |e|
editors[e].each do |f|
before += ckeditor_before_js(e, f)
end
end
options[:before] = options[:before].nil? ? before : before + options[:before]
form_remote_tag(options)
end

def ckeditor_remote_form_for(object_name, *args, &proc)
options = args.last.is_a?(Hash) ? args.pop : {}
concat(ckeditor_form_remote_tag(options), proc.binding)
fields_for(object_name, *(args << options), &proc)
concat('</form>', proc.binding)
end
alias_method :ckeditor_form_remote_for, :ckeditor_remote_form_for

def ckeditor_element_id(object, field)
#id = eval("@#{object}.id")
#"#{object}_#{id}_#{field}_editor"
"#{object}_#{field}_editor"
end

def ckeditor_div_id(object, field)
id = eval("@#{object}.id")
"div-#{object}-#{id}-#{field}-editor"
end
require 'yaml'
require 'fileutils'
require 'tmpdir'

# Include hook code here
require 'ckeditor/config'
require 'ckeditor/utils'
require 'ckeditor/view_helper'
require 'ckeditor/form_builder'

unless defined?(ActionView::SafeBuffer)
require 'ckeditor/safe_buffer'
end

def ckeditor_before_js(object, field)
id = ckeditor_element_id(object, field)
"var oEditor = CKEDITOR.instances.#{id}.getData();"
end

def ckeditor_applay_options(options={})
str = []
options.each do |k, v|
value = case v.class.to_s
when 'String' then "'#{v}'"
when 'Hash' then "{ #{ckeditor_applay_options(v)} }"
else v
ActionView::Base.send(:include, Ckeditor::ViewHelper)
ActionView::Helpers::FormBuilder.send(:include, Ckeditor::FormBuilder)

Ckeditor::Utils.check_and_install

class ActionController::Routing::RouteSet
unless (instance_methods.include?('draw_with_ckeditor'))
class_eval <<-"end_eval", __FILE__, __LINE__
alias draw_without_ckeditor draw
def draw_with_ckeditor
draw_without_ckeditor do |map|
map.connect 'ckeditor/images', :controller => 'ckeditor', :action => 'images'
map.connect 'ckeditor/files', :controller => 'ckeditor', :action => 'files'
map.connect 'ckeditor/create', :controller => 'ckeditor', :action => 'create'
yield map
end
str << "#{k}: #{value}"
end

str.join(',')
end
alias draw draw_with_ckeditor
end_eval
end
end

Expand All @@ -154,13 +52,3 @@ def javascript_include_tag(*sources)
[main_sources.join("\n"), application_source].join("\n")
end
end

module ActionView::Helpers
class FormBuilder
include Ckeditor::Helper

def cktext_area(method, options = {})
ckeditor_textarea(@object_name, method, objectify_options(options))
end
end
end
43 changes: 43 additions & 0 deletions lib/ckeditor/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Ckeditor

class Config
cattr_accessor :filepath
@@filepath = File.join(RAILS_ROOT, "config/ckeditor.yml")

@@available_settings = (File.exists?(@@filepath) ? YAML::load(File.open(@@filepath))[RAILS_ENV] : nil)

class << self

def [](name)
return if @@available_settings.nil?
@@available_settings[name.to_s]
end

def method_missing(method, *args)
method_name = method.to_s
return self[method_name].to_s if !@@available_settings.nil? && @@available_settings.keys.include?(method_name)
super
end

def exists?
File.exists?(@@filepath)
end

def create_yml
unless File.exists?(@@filepath)
ck_config = File.join(RAILS_ROOT, 'vendor/plugins/rails-ckeditor/', 'ckeditor.yml.tpl')
FileUtils.cp ck_config, @@filepath unless File.exist?(@@filepath)

log "#{@@filepath} example file created!"
log "Please modify your settings"
else
log "config/#{@@filepath} already exists. Aborting task..."
end
end

def log(message)
STDOUT.puts message
end
end
end
end
Loading

0 comments on commit b3770f7

Please sign in to comment.