This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrote Readme; fixed Rails3.1 compatability - now works with 3.1.0
- Loading branch information
Mike Howard
committed
Sep 12, 2011
1 parent
e4e139d
commit 6d37145
Showing
5 changed files
with
121 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,101 @@ | ||
require 'fileutils' | ||
|
||
class UseTinyMCE | ||
# paths | ||
USE_TINYMCE_ROOT = File.expand_path('../../../', __FILE__) | ||
ASSETS_ROOT = File.join(USE_TINYMCE_ROOT, 'assets') | ||
case | ||
when Rails.version =~ /^3.0/ then | ||
JAVASCRIPT_ROOT = File.join(Rails.root, 'public', 'javascripts') | ||
RAILS_REGX = Regexp.new('//\s+Rails 3.0') | ||
MODE_STRING = 'mode : "textareas"' | ||
JQUERY_SELECTOR = '"textarea"' | ||
when Rails.version =~ /^3.1/ then; | ||
# make sure we are in the right versino of Rails | ||
unless defined?(Rails) | ||
puts "This rake task only runs on Rails" | ||
exit | ||
end | ||
unless Rails.version =~ /^3.[01]/ | ||
puts "Don't know how to install on Rails Version #{Rails.version}" | ||
exit | ||
end | ||
|
||
module UseTinyMCE | ||
module RakeSupport | ||
# gem paths - used to source for installation | ||
USE_TINYMCE_ROOT = File.expand_path('../../../', __FILE__) | ||
ASSETS_ROOT = File.join(USE_TINYMCE_ROOT, 'assets') | ||
|
||
# target paths and customizations | ||
# MSH - asset pipeline gets in way, so put it in public/javascripts | ||
# JAVASCRIPT_ROOT = File.join(Rails.root, 'app', 'assets', 'javascripts') | ||
JAVASCRIPT_ROOT = File.join(Rails.root, 'public', 'javascripts') | ||
RAILS_REGX = Regexp.new('//\s+Rails 3.1') | ||
MODE_STRING = [ 'mode: "specific_textareas"', ' editor_selector: "tinymce"' ].join(",\n") | ||
# set the TinyMCE selection mode: this controls which textarea elements use TinyMCE | ||
# mode: specific_textareas is essentially the same as mode:textareas | ||
# editor_selector: foo defines a class which MUST be present in a textarea element IF | ||
# (1) editor_selector is defined & (2) you want it to have TinyMCE | ||
# editor_deselector: foo defines a CLASS which must be present to keep a textarea from | ||
# using TinyMCE. Note: Both editor_deselector must be defined AND the class must be present. | ||
# so - the settings below include TinyMCE in textareas By Default and Allow Deselecting | ||
# Use this if you are both masochistic and want love to positively select which textareas | ||
# use TinyMCE. This code | ||
# MODE_STRING = [ 'mode: "specific_textareas"', ' editor_selector: "tinymce"', | ||
# ' editor_deselector: "no-tinymce"' ].join(",\n") | ||
MODE_STRING = [ 'mode: "specific_textareas"', ' editor_deselector: "no-tinymce"' ].join(",\n") | ||
# This MODE_STRING will configure to NOT USE TinyMCE in textareas unless the 'editor_selector' | ||
# class is present. | ||
# MODE_STRING = [ 'mode: "specific_textareas"', ' editor_selector: "tinymce"' ].join(",\n") | ||
JQUERY_SELECTOR = '"textarea.tinymce"' | ||
else | ||
puts "Don't know how to install on Rails Version #{Rails.version}" | ||
exit | ||
end | ||
# puts "USE_TINYMCE_ROOT: #{USE_TINYMCE_ROOT}" | ||
# puts "ASSETS_ROOT: #{ASSETS_ROOT}" | ||
# puts "JAVASCRIPT_ROOT: #{JAVASCRIPT_ROOT}" | ||
|
||
def self.copy_init_script(source) | ||
source_path = File.join(ASSETS_ROOT, source) | ||
source_text = File.new(source_path).read.sub(/{mode_string}/, MODE_STRING).sub(/{jquery_selector}/, JQUERY_SELECTOR) | ||
def self.copy_init_script(source) | ||
source_path = File.join(ASSETS_ROOT, source) | ||
source_text = File.new(source_path).read.sub(/{mode_string}/, MODE_STRING).sub(/{jquery_selector}/, JQUERY_SELECTOR) | ||
|
||
dest_path = File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
dest_file = File.new(dest_path, "w") | ||
dest_file.write(source_text) | ||
dest_file.close | ||
end | ||
dest_path = File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
dest_file = File.new(dest_path, "w") | ||
dest_file.write(source_text) | ||
dest_file.close | ||
end | ||
|
||
def self.rmdir_tree(root) | ||
Dir.entries(root).each do |fname| | ||
if fname[0] == '.' | ||
next | ||
else | ||
path = File.join(root, fname) | ||
if File.directory?(path) | ||
rmdir_tree(path) | ||
elsif File.file?(path) | ||
File.delete(path) | ||
def self.rmdir_tree(root) | ||
Dir.entries(root).each do |fname| | ||
if fname[0] == '.' | ||
next | ||
else | ||
path = File.join(root, fname) | ||
if File.directory?(path) | ||
rmdir_tree(path) | ||
elsif File.file?(path) | ||
File.delete(path) | ||
end | ||
end | ||
end | ||
Dir.rmdir(root) | ||
end | ||
Dir.rmdir(root) | ||
end | ||
end | ||
|
||
namespace :use_tinymce do | ||
desc "uninstall use_tinymce javascript code" | ||
task :uninstall do | ||
init_file_path = File.join(UseTinyMCE::JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
init_file_path = File.join(UseTinyMCE::RakeSupport::JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
File.delete(init_file_path) if File.exists? init_file_path | ||
|
||
tinymce_root_path = File.join(UseTinyMCE::JAVASCRIPT_ROOT, 'tinymce') | ||
UseTinyMCE::rmdir_tree(tinymce_root_path) if File.exists? tinymce_root_path | ||
tinymce_root_path = File.join(UseTinyMCE::RakeSupport::JAVASCRIPT_ROOT, 'tinymce') | ||
UseTinyMCE::RakeSupport::rmdir_tree(tinymce_root_path) if File.exists? tinymce_root_path | ||
end | ||
task :install_tinymce_advanced => :uninstall do | ||
FileUtils.cp_r File.join(UseTinyMCE::ASSETS_ROOT, 'tinymce_no_jquery', 'tinymce'), UseTinyMCE::JAVASCRIPT_ROOT | ||
FileUtils.cp_r File.join(UseTinyMCE::RakeSupport::ASSETS_ROOT, 'tinymce_no_jquery', 'tinymce'), UseTinyMCE::RakeSupport::JAVASCRIPT_ROOT | ||
end | ||
task :install_tinymce_jquery => :uninstall do | ||
FileUtils.cp_r File.join(UseTinyMCE::UseTinyMCE::ASSETS_ROOT, 'tinymce_jquery', 'tinymce'), UseTinyMCE::JAVASCRIPT_ROOT | ||
FileUtils.cp_r File.join(UseTinyMCE::RakeSupport::UseTinyMCE::RakeSupport::ASSETS_ROOT, 'tinymce_jquery', 'tinymce'), UseTinyMCE::RakeSupport::JAVASCRIPT_ROOT | ||
end | ||
|
||
desc "Install tinymce with 'simple' initialization" | ||
task :install_simple => :install_tinymce_advanced do | ||
UseTinyMCE::copy_init_script('use_tinymce_init_simple.js') | ||
# FileUtils.cp File.join(UseTinyMCE::ASSETS_ROOT, 'use_tinymce_init_simple.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
UseTinyMCE::RakeSupport::copy_init_script('use_tinymce_init_simple.js') | ||
# FileUtils.cp File.join(UseTinyMCE::RakeSupport::ASSETS_ROOT, 'use_tinymce_init_simple.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
end | ||
|
||
desc "Install tinymce with 'advanced' initialization" | ||
task :install_advanced => :install_tinymce_advanced do | ||
UseTinyMCE::copy_init_script('use_tinymce_init_advanced.js') | ||
# FileUtils.cp File.join(UseTinyMCE::ASSETS_ROOT, 'use_tinymce_init_advanced.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
UseTinyMCE::RakeSupport::copy_init_script('use_tinymce_init_advanced.js') | ||
# FileUtils.cp File.join(UseTinyMCE::RakeSupport::ASSETS_ROOT, 'use_tinymce_init_advanced.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
end | ||
|
||
desc "Install tinymce jquery plugin with 'advanced' initialization" | ||
task :install_jquery => :install_tinymce_jquery do | ||
UseTinyMCE::copy_init_script('use_tinymce_init_jquery.js') | ||
# FileUtils.cp File.join(UseTinyMCE::ASSETS_ROOT, 'use_tinymce_init_jquery.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
UseTinyMCE::RakeSupport::copy_init_script('use_tinymce_init_jquery.js') | ||
# FileUtils.cp File.join(UseTinyMCE::RakeSupport::ASSETS_ROOT, 'use_tinymce_init_jquery.js'), File.join(JAVASCRIPT_ROOT, 'use_tinymce_init.js') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters