Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace :spec do
t.rcov = true
t.rcov_opts = ['--exclude', 'spec', '--rails']
end

desc "Print Specdoc for all specs"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
Expand All @@ -62,7 +62,7 @@ namespace :spec do
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
end
end

# Hopefully no one has written their extensions in pre-0.9 style
# desc "Translate specs from pre-0.9 to 0.9 style"
# task :translate do
Expand Down
32 changes: 16 additions & 16 deletions app/controllers/fckeditor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FckeditorController < ApplicationController
"application/xml",
"application/xhtml+xml"
]

RXML = <<-EOL
xml.instruct!
#=> <?xml version="1.0" encoding="utf-8" ?>
Expand All @@ -64,21 +64,21 @@ class FckeditorController < ApplicationController
xml.Error("number" => errorNumber) if !errorNumber.nil?
end
EOL

def config
tag_list = []
class_name = (params[:class_name].blank? ? 'Page' : params[:class_name])
class_name.constantize.tag_descriptions.sort.each do |tag_name, description|
tag_list << tag_name
end
@fck_tag_list = tag_list.collect{|tag| 'R:' + tag.upcase}.join('|')
@fck_tag_list = tag_list.collect{|tag| 'R:' + tag.upcase}.join('|')
respond_to do |format|
format.js
format.js
end
end

# figure out who needs to handle this request
def command
def command
@current_folder = current_directory_path
@url = upload_directory_path
if params[:Command] == 'GetFoldersAndFiles' || params[:Command] == 'GetFolders'
Expand All @@ -91,8 +91,8 @@ def command
unless params[:Command] == 'FileUpload'
render :inline => RXML , :type => :rxml , :locals => {:url => @url, :folders => @folders, :files => @files, :errorNumber => @errorNumber}
end
end
end

def get_folders_and_files(include_files = true)
@folders = Array.new
@files = {}
Expand All @@ -103,10 +103,10 @@ def get_folders_and_files(include_files = true)
end
path = @current_folder + entry
if FileTest.directory?(path)
@folders.push entry
@folders.push entry
end
if include_files and FileTest.file?(path)
@files[entry] = (File.size(path) / 1024)
@files[entry] = (File.size(path) / 1024)
end
end
rescue => e
Expand All @@ -115,7 +115,7 @@ def get_folders_and_files(include_files = true)
end

def create_folder
begin
begin
@url = current_directory_path
path = @url + params[:NewFolderName]
if !(File.stat(@url).writable?)
Expand All @@ -132,7 +132,7 @@ def create_folder
@errorNumber = 110 if @errorNumber.nil?
end
end

def upload_file
begin
@new_file = check_file(params[:NewFile])
Expand Down Expand Up @@ -164,27 +164,27 @@ def upload_file
def upload
self.upload_file
end

def check_spelling
require 'cgi'
@original_text = params[:textinputs] ? params[:textinputs].first : ''
plain_text = ActionController::Base.helpers.strip_tags(CGI.unescape(@original_text))
@words = FckeditorSpellCheck.check_spelling(plain_text)
render :file => "#{FckeditorExtension.root}/app/views/fckeditor/spell_check.rhtml"
end

private
def current_directory_path
base_dir = "#{UPLOADED_ROOT}/#{params[:Type]}"
Dir.mkdir(base_dir,0775) unless File.exists?(base_dir)
check_path("#{base_dir}#{params[:CurrentFolder]}")
end

def upload_directory_path
uploaded = ActionController::Base.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"
"#{uploaded}#{params[:CurrentFolder]}"
end

def check_file(file)
# check that the file is a tempfile object
# RAILS_DEFAULT_LOGGER.info "CLASS OF UPLOAD OBJECT: #{file.class}"
Expand All @@ -194,7 +194,7 @@ def check_file(file)
end
file
end

def check_path(path)
exp_path = File.expand_path path
if exp_path !~ %r[^#{File.expand_path(RAILS_ROOT)}/public#{UPLOADED}]
Expand Down
2 changes: 1 addition & 1 deletion app/models/fckeditor_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.included(base)
before_filter :add_fckeditor_interface, :only => [:edit, :new]
}
end

module FckeditorInstanceMethods
def add_fckeditor_interface
include_javascript 'fckeditor/fckeditor'
Expand Down
38 changes: 19 additions & 19 deletions lib/fckeditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module Fckeditor
PLUGIN_NAME = 'fckeditor'
PLUGIN_PATH = "#{RAILS_ROOT}/vendor/extensions/#{PLUGIN_NAME}"
PLUGIN_PUBLIC_PATH = "#{PLUGIN_PATH}/public"
PLUGIN_CONTROLLER_PATH = "#{PLUGIN_PATH}/app/controllers"
PLUGIN_VIEWS_PATH = "#{PLUGIN_PATH}/app/views"
PLUGIN_CONTROLLER_PATH = "#{PLUGIN_PATH}/app/controllers"
PLUGIN_VIEWS_PATH = "#{PLUGIN_PATH}/app/views"
PLUGIN_HELPER_PATH = "#{PLUGIN_PATH}/app/helpers"

module Helper
def fckeditor_textarea(object, field, options = {})
var = instance_variable_get("@#{object}")
Expand All @@ -19,22 +19,22 @@ def fckeditor_textarea(object, field, options = {})
instance_variable_set("@#{object}", eval("#{klass}.new()"))
end
id = fckeditor_element_id(object, field)

cols = options[:cols].nil? ? '' : "cols='"+options[:cols]+"'"
rows = options[:rows].nil? ? '' : "rows='"+options[:rows]+"'"

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

toolbarSet = options[:toolbarSet].nil? ? 'Default' : options[:toolbarSet]

if options[:ajax]
inputs = "<input type='hidden' id='#{id}_hidden' name='#{object}[#{field}]'>\n" <<
"<textarea id='#{id}' #{cols} #{rows} name='#{id}'>#{value}</textarea>\n"
else
else
inputs = "<textarea id='#{id}' #{cols} #{rows} name='#{object}[#{field}]'>#{value}</textarea>\n"
end

js_path = "#{request.relative_url_root}/javascripts"
base_path = "#{js_path}/fckeditor/"
return inputs <<
Expand All @@ -43,7 +43,7 @@ def fckeditor_textarea(object, field, options = {})
"oFCKeditor.Config['CustomConfigurationsPath'] = '#{js_path}/fckcustom.js';\n" <<
"oFCKeditor.ReplaceTextarea();\n")
end

def fckeditor_form_remote_tag(options = {})
editors = options[:editors]
before = ""
Expand All @@ -52,39 +52,39 @@ def fckeditor_form_remote_tag(options = {})
before += fckeditor_before_js(e, f)
end
end
options[:before] = options[:before].nil? ? before : before + options[:before]
options[:before] = options[:before].nil? ? before : before + options[:before]
form_remote_tag(options)
end

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

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

def fckeditor_div_id(object, field)
id = eval("@#{object}.id")
"div-#{object}-#{id}-#{field}-editor"
id = eval("@#{object}.id")
"div-#{object}-#{id}-#{field}-editor"
end

def fckeditor_before_js(object, field)
id = fckeditor_element_id(object, field)
"var oEditor = FCKeditorAPI.GetInstance('"+id+"'); document.getElementById('"+id+"_hidden').value = oEditor.GetXHTML();"
end
end
end
end

include ActionView
module ActionView::Helpers::AssetTagHelper
alias_method :rails_javascript_include_tag, :javascript_include_tag

# <%= javascript_include_tag :defaults, :fckeditor %>
def javascript_include_tag(*sources)
main_sources, application_source = [], []
Expand All @@ -93,7 +93,7 @@ def javascript_include_tag(*sources)
sources.push('fckeditor/fckeditor')
end
unless sources.empty?
main_sources = rails_javascript_include_tag(*sources).split("\n")
main_sources = rails_javascript_include_tag(*sources).split("\n")
application_source = main_sources.pop if main_sources.last.include?('application.js')
end
[main_sources.join("\n"), application_source].join("\n")
Expand Down
38 changes: 19 additions & 19 deletions lib/fckeditor_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module FckeditorFileUtils
FCKEDITOR_INSTALL_DIRECTORY = File.join(RAILS_ROOT, '/public/javascripts/fckeditor/')

def FckeditorFileUtils.recursive_copy(options)
source = options[:source]
dest = options[:dest]
logging = options[:logging].nil? ? true : options[:logging]

Dir.foreach(source) do |entry|
next if entry =~ /^\./
if File.directory?(File.join(source, entry))
Expand All @@ -17,8 +17,8 @@ def FckeditorFileUtils.recursive_copy(options)
end
FileUtils.mkdir File.join(dest, entry)#, :noop => true#, :verbose => true
end
recursive_copy(:source => File.join(source, entry),
:dest => File.join(dest, entry),
recursive_copy(:source => File.join(source, entry),
:dest => File.join(dest, entry),
:logging => logging)
else
if logging
Expand All @@ -28,43 +28,43 @@ def FckeditorFileUtils.recursive_copy(options)
end
end
end

def FckeditorFileUtils.backup_existing
source = File.join(RAILS_ROOT,'/public/javascripts/fckeditor')
dest = File.join(RAILS_ROOT,'/public/javascripts/fckeditor_bck')
FileUtils.rm_r(dest) if File.exists? dest

FileUtils.rm_r(dest) if File.exists? dest
FileUtils.mv source, dest
end

def FckeditorFileUtils.create_uploads_directory
uploads = File.join(RAILS_ROOT, '/public/uploads')
FileUtils.mkdir(uploads) unless File.exist?(uploads)
FileUtils.mkdir(uploads) unless File.exist?(uploads)
end
def FckeditorFileUtils.install(log)

def FckeditorFileUtils.install(log)
directory = File.join(RAILS_ROOT, '/vendor/extensions/fckeditor/')
source = File.join(directory,'/public/javascripts/fckeditor/')
FileUtils.mkdir(FCKEDITOR_INSTALL_DIRECTORY)
FileUtils.mkdir(FCKEDITOR_INSTALL_DIRECTORY)
# recursively copy all our files over
recursive_copy(:source => source, :dest => FCKEDITOR_INSTALL_DIRECTORY, :logging => log)
recursive_copy(:source => source, :dest => FCKEDITOR_INSTALL_DIRECTORY, :logging => log)
# create the upload directories
create_uploads_directory
end

def FckeditorFileUtils.destroy_and_install
# remove the existing install (if any) and install a new one
if File.exist?(FCKEDITOR_INSTALL_DIRECTORY)
if File.exist?(FCKEDITOR_INSTALL_DIRECTORY)
FileUtils.rm_r(FCKEDITOR_INSTALL_DIRECTORY)
end
end
# now install fresh
install(true)
install(true)
end

def FckeditorFileUtils.check_and_install
# check to see if already installed, if not install
unless File.exist?(FCKEDITOR_INSTALL_DIRECTORY)
install(false)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/fckeditor_spell_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class FckeditorSpellCheck
def self.check_spelling(text)
if RUBY_PLATFORM =~ /mswin/i
aspell_program = 'c:\program files\aspell\bin\aspell' # windows
else
else
aspell_program = 'aspell' # every other OS on the planet
end

# call aspell
command = "\"#{aspell_program}\" -a --lang=#{language} --encoding=utf-8 -H 2>&1"
RAILS_DEFAULT_LOGGER.info("Running spell check: #{command}")
Expand Down
2 changes: 1 addition & 1 deletion lib/fckeditor_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module FckeditorVersion
MAJOR = 0
MINOR = 4
RELEASE = 3

def self.current
"#{MAJOR}.#{MINOR}.#{RELEASE}"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/fckeditor_extension_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace :radiant do
require "#{directory}/lib/fckeditor"
require "#{directory}/lib/fckeditor_version"
require "#{directory}/lib/fckeditor_file_utils"
puts "** Installing Radiant FCKEditor Extension version #{FckeditorExtension.version}..."
FckeditorFileUtils.destroy_and_install
puts "** Installing Radiant FCKEditor Extension version #{FckeditorExtension.version}..."
FckeditorFileUtils.destroy_and_install
puts "** Successfully installed Radiant FCKEditor Extension version #{FckeditorExtension.version}"
end
end
end
end
end
Loading