tiny_mce_helper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -0
- data/README +178 -0
- data/Rakefile +80 -0
- data/init.rb +1 -0
- data/install.rb +7 -0
- data/lib/tiny_mce_helper.rb +244 -0
- data/tasks/tiny_mce_helper_tasks.rake +21 -0
- data/test/app_root/config/tiny_mce_options.yml +119 -0
- data/test/app_root/config_bak/tiny_mce_options.yml +119 -0
- data/test/files/sourceforge.html +1271 -0
- data/test/files/tinymce_2_0_8.tgz +0 -0
- data/test/files/tinymce_2_1_1_1.tgz +0 -0
- data/test/files/wiki.html +361 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/tiny_mce_helper_test.rb +323 -0
- data/uninstall.rb +2 -0
- metadata +74 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
*SVN*
|
2
|
+
|
3
|
+
*0.0.1* (August 20th, 2007)
|
4
|
+
|
5
|
+
* Add README documentation
|
6
|
+
|
7
|
+
* Add tiny_mce:uninstall and tiny_mce:update rake tasks
|
8
|
+
|
9
|
+
* Add working unit tests
|
10
|
+
|
11
|
+
* Add installation and uninstallation scripts
|
12
|
+
|
13
|
+
* Add rake tasks tiny_mce:install and tiny_mce:update_options
|
data/README
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
= tiny_mce_helper
|
2
|
+
|
3
|
+
tiny_mce_helper adds helper methods for creating the TinyMCE initialization
|
4
|
+
script.
|
5
|
+
|
6
|
+
== Resources
|
7
|
+
|
8
|
+
API
|
9
|
+
|
10
|
+
* http://api.pluginaweek.org/tiny_mce_helper
|
11
|
+
|
12
|
+
Wiki
|
13
|
+
|
14
|
+
* http://wiki.pluginaweek.org/Tiny_mce_helper
|
15
|
+
|
16
|
+
Announcement
|
17
|
+
|
18
|
+
* http://www.pluginaweek.org/
|
19
|
+
|
20
|
+
Source
|
21
|
+
|
22
|
+
* http://svn.pluginaweek.org/trunk/plugins/action_pack/tiny_mce_helper
|
23
|
+
|
24
|
+
Development
|
25
|
+
|
26
|
+
* http://dev.pluginaweek.org/browser/trunk/plugins/action_pack/tiny_mce_helper
|
27
|
+
|
28
|
+
== Requirements
|
29
|
+
|
30
|
+
Currently, you must be running a version of Linux in order to run the rake
|
31
|
+
tasks.
|
32
|
+
|
33
|
+
== Description
|
34
|
+
|
35
|
+
TinyMCE is a rich text editor written in Javascript. This helper plugin helps
|
36
|
+
make it easier to validate your code and include the TinyMCE initialization
|
37
|
+
script. It also provides various tasks for installing/updating TinyMCE.
|
38
|
+
|
39
|
+
=== Installing TinyMCE
|
40
|
+
|
41
|
+
To install TinyMCE, you can use the tiny_mce:install task. This will download
|
42
|
+
the latest version (or one specified by you) from Sourceforge and extract it
|
43
|
+
into your application's public/javascripts folder.
|
44
|
+
|
45
|
+
For example, to install the latest version:
|
46
|
+
|
47
|
+
$ rake tiny_mce:install
|
48
|
+
(in /my/project)
|
49
|
+
Downloading TinyMCE source...
|
50
|
+
Extracting...
|
51
|
+
Done!
|
52
|
+
|
53
|
+
To install a custom version:
|
54
|
+
|
55
|
+
$ rake tiny_mce:install VERSION=2.0.8
|
56
|
+
(in /my/project)
|
57
|
+
Downloading TinyMCE source...
|
58
|
+
Extracting...
|
59
|
+
Done!
|
60
|
+
|
61
|
+
If tinymce already exists in your application's public/javascript folder, the
|
62
|
+
rake task will prompt you as to whether or not it should be overwritten:
|
63
|
+
|
64
|
+
$ rake tiny_mce:install
|
65
|
+
(in /my/project)
|
66
|
+
TinyMCE already be installed in /my/project/config/../public/javascripts/tinymce. Overwrite? (y/n): y
|
67
|
+
Downloading TinyMCE source...
|
68
|
+
Extracting...
|
69
|
+
Done!
|
70
|
+
|
71
|
+
=== Updating TinyMCE
|
72
|
+
|
73
|
+
If you have already installed TinyMCE and wish to update to the latest version,
|
74
|
+
you can run the tiny_mce:update task. This will overwrite the current TinyMCE
|
75
|
+
installation and WILL NOT prompt you if the folder already exists. For example,
|
76
|
+
|
77
|
+
$ rake tiny_mce:update
|
78
|
+
(in /my/project)
|
79
|
+
Downloading TinyMCE source...
|
80
|
+
Extracting...
|
81
|
+
Done!
|
82
|
+
|
83
|
+
Like tiny_mce:install, you can also specify a custom version:
|
84
|
+
|
85
|
+
$ rake tiny_mce:update VERSION=2.0.9
|
86
|
+
(in /my/project)
|
87
|
+
Downloading TinyMCE source...
|
88
|
+
Extracting...
|
89
|
+
Done!
|
90
|
+
|
91
|
+
=== Updating configuration options
|
92
|
+
|
93
|
+
In addition to installing the Javascript source, tiny_mce_helper is also able to
|
94
|
+
validate the options that are passed in to initialize TinyMCE. Since these
|
95
|
+
options can change over time, a configuration file is generated based on
|
96
|
+
information from the TinyMCE wiki. This configuration file contains a list of
|
97
|
+
all of the current possible options that can be specified.
|
98
|
+
|
99
|
+
For example, to create a new configuration file:
|
100
|
+
|
101
|
+
$ rake tiny_mce:update VERSION=2.0.9
|
102
|
+
(in /my/project)
|
103
|
+
Downloading configuration options from TinyMCE Wiki...
|
104
|
+
Done!
|
105
|
+
|
106
|
+
This will create config/tiny_mce_options.yml. The content of the configuration
|
107
|
+
should look similar to:
|
108
|
+
|
109
|
+
---
|
110
|
+
- accessibility_focus
|
111
|
+
- accessibility_warnings
|
112
|
+
- add_form_submit_trigger
|
113
|
+
- add_unload_trigger
|
114
|
+
- apply_source_formatting
|
115
|
+
- ask
|
116
|
+
- auto_focus
|
117
|
+
- auto_reset_designmode
|
118
|
+
- auto_resize
|
119
|
+
- browsers
|
120
|
+
- button_tile_map
|
121
|
+
- cleanup
|
122
|
+
- cleanup_callback
|
123
|
+
- cleanup_on_startup
|
124
|
+
- cleanup_serializer
|
125
|
+
...
|
126
|
+
|
127
|
+
=== Uninstalling TinyMCE
|
128
|
+
|
129
|
+
Uninstalling TinyMCE will remove the javascript source and the configuration
|
130
|
+
options. To invoke the installation, run the rake task tiny_mce:uninstall.
|
131
|
+
|
132
|
+
$ rake tiny_mce:uninstall
|
133
|
+
(in /my/project)
|
134
|
+
|
135
|
+
=== Creating TinyMCE script
|
136
|
+
|
137
|
+
To create the TinyMCE initialization script:
|
138
|
+
|
139
|
+
application.rhtml:
|
140
|
+
<%=
|
141
|
+
tiny_mce_init_script(
|
142
|
+
:theme => 'advanced',
|
143
|
+
:editor_selector => 'rich_text',
|
144
|
+
:content_css => '/stylesheets/tiny_mce_content.css',
|
145
|
+
:editor_css => '/stylesheets/tiny_mce_editor.css',
|
146
|
+
:auto_reset_designmode => true
|
147
|
+
)
|
148
|
+
%>
|
149
|
+
|
150
|
+
will generate the following javascript:
|
151
|
+
|
152
|
+
tinyMCE.init({
|
153
|
+
'mode' : 'textareas',
|
154
|
+
'theme' : 'advanced',
|
155
|
+
'editor_selected' : 'rich_text',
|
156
|
+
'content_css' : '/stylesheets/tiny_mce_content.css'
|
157
|
+
});
|
158
|
+
|
159
|
+
To see additional initialization helpers, see the API for PluginAWeek::Helpers::TinyMCEHelper
|
160
|
+
|
161
|
+
== Testing
|
162
|
+
|
163
|
+
Since the rake tasks for installing TinyMCE and updating the configuration
|
164
|
+
options are part of the unit tests, already-downloaded files are included with
|
165
|
+
the plugin. If you want to perform a "live" test which actually downloads the
|
166
|
+
files off the Internet (rather than using the local versions), you must set
|
167
|
+
the LIVE environment variable to true. For example,
|
168
|
+
|
169
|
+
rake test LIVE=true
|
170
|
+
|
171
|
+
== References
|
172
|
+
|
173
|
+
This plugin provides for the installation and utilization of TinyMCE in Ruby on
|
174
|
+
Rails applications. TinyMCE is a WYSIWYG HTML editing component released under
|
175
|
+
the GNU Public License (GPL) by Moxiecode Systems (http://tinymce.moxiecode.com/).
|
176
|
+
|
177
|
+
This plugin was originally created by by Blake Watters <blake@near-time.com> and
|
178
|
+
later modified by Aaron Pfeifer & Neil Abraham.
|
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/contrib/sshpublisher'
|
5
|
+
|
6
|
+
PKG_NAME = 'tiny_mce_helper'
|
7
|
+
PKG_VERSION = '0.0.1'
|
8
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
9
|
+
RUBY_FORGE_PROJECT = 'pluginaweek'
|
10
|
+
|
11
|
+
desc 'Default: run unit tests.'
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
desc 'Test the tiny_mce_helper plugin.'
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.libs << 'lib'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Generate documentation for the tiny_mce_helper plugin.'
|
22
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
|
+
rdoc.rdoc_dir = 'rdoc'
|
24
|
+
rdoc.title = 'TinyMCEHelper'
|
25
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
26
|
+
rdoc.rdoc_files.include('README')
|
27
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
+
end
|
29
|
+
|
30
|
+
spec = Gem::Specification.new do |s|
|
31
|
+
s.name = PKG_NAME
|
32
|
+
s.version = PKG_VERSION
|
33
|
+
s.platform = Gem::Platform::RUBY
|
34
|
+
s.summary = 'Adds helper methods for creating the TinyMCE initialization script.'
|
35
|
+
|
36
|
+
s.files = FileList['{lib,tasks,test}/**/*'].to_a + %w(CHANGELOG init.rb install.rb Rakefile README uninstall.rb)
|
37
|
+
s.require_path = 'lib'
|
38
|
+
s.autorequire = 'tiny_mce_helper'
|
39
|
+
s.has_rdoc = true
|
40
|
+
s.test_files = Dir['test/**/*_test.rb']
|
41
|
+
s.add_dependency 'actionpack', '>= 1.13.1'
|
42
|
+
|
43
|
+
s.author = 'Aaron Pfeifer, Neil Abraham'
|
44
|
+
s.email = 'info@pluginaweek.org'
|
45
|
+
s.homepage = 'http://www.pluginaweek.org'
|
46
|
+
end
|
47
|
+
|
48
|
+
Rake::GemPackageTask.new(spec) do |p|
|
49
|
+
p.gem_spec = spec
|
50
|
+
p.need_tar = true
|
51
|
+
p.need_zip = true
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Publish the beta gem'
|
55
|
+
task :pgem => [:package] do
|
56
|
+
Rake::SshFilePublisher.new('pluginaweek@pluginaweek.org', '/home/pluginaweek/gems.pluginaweek.org/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Publish the API documentation'
|
60
|
+
task :pdoc => [:rdoc] do
|
61
|
+
Rake::SshDirPublisher.new('pluginaweek@pluginaweek.org', "/home/pluginaweek/api.pluginaweek.org/#{PKG_NAME}", 'rdoc').upload
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Publish the API docs and gem'
|
65
|
+
task :publish => [:pdoc, :release]
|
66
|
+
|
67
|
+
desc 'Publish the release files to RubyForge.'
|
68
|
+
task :release => [:gem, :package] do
|
69
|
+
require 'rubyforge'
|
70
|
+
|
71
|
+
ruby_forge = RubyForge.new
|
72
|
+
ruby_forge.login
|
73
|
+
|
74
|
+
%w( gem tgz zip ).each do |ext|
|
75
|
+
file = "pkg/#{PKG_FILE_NAME}.#{ext}"
|
76
|
+
puts "Releasing #{File.basename(file)}..."
|
77
|
+
|
78
|
+
ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
|
79
|
+
end
|
80
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tiny_mce_helper'
|
data/install.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Install TinyMCE
|
2
|
+
puts 'Installing TinyMCE...'
|
3
|
+
PluginAWeek::Helpers::TinyMCEHelper.install(:version => ENV['VERSION'], :target => ENV['TARGET'])
|
4
|
+
|
5
|
+
# Update the configuration options
|
6
|
+
puts 'Updating TinyMCE configuration options...'
|
7
|
+
PluginAWeek::Helpers::TinyMCEHelper.update_options
|
@@ -0,0 +1,244 @@
|
|
1
|
+
module PluginAWeek #:nodoc:
|
2
|
+
module Helpers #:nodoc:
|
3
|
+
# Adds helper methods for generating the TinyMCE initialization script
|
4
|
+
# within your Rails views
|
5
|
+
module TinyMCEHelper
|
6
|
+
# The path to the file which contains all valid options that can be used
|
7
|
+
# to configure TinyMCE
|
8
|
+
OPTIONS_FILE_PATH = "#{RAILS_ROOT}/config/tiny_mce_options.yml"
|
9
|
+
|
10
|
+
# A regular expression matching options that are dynamic (i.e. they can
|
11
|
+
# vary on an integer or string basis)
|
12
|
+
DYNAMIC_OPTIONS = /theme_advanced_buttons|theme_advanced_container/
|
13
|
+
|
14
|
+
# Whether or not to use verbose output
|
15
|
+
mattr_accessor :verbose
|
16
|
+
@@verbose = true
|
17
|
+
|
18
|
+
# A list of all valid options that can be used to configure TinyMCE
|
19
|
+
mattr_accessor :valid_options
|
20
|
+
@@valid_options = File.exists?(OPTIONS_FILE_PATH) ? File.open(OPTIONS_FILE_PATH) {|f| YAML.load(f.read)} : []
|
21
|
+
|
22
|
+
class << self
|
23
|
+
# Installs TinyMCE by downloading it and adding it to your application's
|
24
|
+
# javascripts folder.
|
25
|
+
#
|
26
|
+
# == Versions
|
27
|
+
#
|
28
|
+
# By default, this will install the latest version of TinyMCE. You can
|
29
|
+
# install a specific version of TinyMCE (if you are using an old API) by
|
30
|
+
# passing in the version number.
|
31
|
+
#
|
32
|
+
# For example,
|
33
|
+
# PluginAWeek::Helpers::TinyMCEHelper.install #=> Installs the latest version
|
34
|
+
# PluginAWeek::Helpers::TinyMCEHelper.install('2.0.8') #=> Installs version 2.0.8
|
35
|
+
#
|
36
|
+
# An exception will be raised if the specified version cannot be found.
|
37
|
+
#
|
38
|
+
# == Target path
|
39
|
+
#
|
40
|
+
# By default, this will install TinyMCE into RAILS_ROOT/public/javascripts/tinymce.
|
41
|
+
# If you want to install it to a different directory, you can pass in
|
42
|
+
# a parameter with the relative path from RAILS_ROOT.
|
43
|
+
#
|
44
|
+
# For example,
|
45
|
+
# PluginAWeek::Helpers::TinyMCEHelper.install(nil, 'public/javascripts/richtext')
|
46
|
+
def install(options = {})
|
47
|
+
options.assert_valid_keys(:version, :target, :force)
|
48
|
+
options.reverse_merge!(:force => false)
|
49
|
+
|
50
|
+
version = options[:version]
|
51
|
+
base_target = options[:target] || 'public/javascripts/tinymce'
|
52
|
+
source_path = 'tinymce'
|
53
|
+
target_path = File.expand_path(File.join(RAILS_ROOT, base_target))
|
54
|
+
|
55
|
+
# If TinyMCE is already installed, make sure the user wants to continue
|
56
|
+
if !options[:force] && File.exists?(target_path)
|
57
|
+
print "TinyMCE already be installed in #{target_path}. Overwrite? (y/n): "
|
58
|
+
while !%w(y n).include?(option = STDIN.gets.chop)
|
59
|
+
print "Invalid option. Overwrite #{target_path}? (y/n): "
|
60
|
+
end
|
61
|
+
return if option == 'n'
|
62
|
+
end
|
63
|
+
|
64
|
+
require 'hpricot'
|
65
|
+
require 'open-uri'
|
66
|
+
|
67
|
+
# Get the url of the TinyMCE version
|
68
|
+
doc = Hpricot(open('http://sourceforge.net/project/showfiles.php?group_id=103281&package_id=111430'))
|
69
|
+
if version
|
70
|
+
version.gsub!('.', '_')
|
71
|
+
file_element = (doc/'tr[@id*="rel0_"] a').detect {|file| file.innerHTML =~ /#{version}.tgz$/}
|
72
|
+
raise ArgumentError, "Could not find TinyMCE version #{version}" if !file_element
|
73
|
+
else
|
74
|
+
file_element = (doc/'tr[@id^="pkg0_1rel0_"] a').detect {|file| file.innerHTML.to_s =~ /\d\.tgz$/}
|
75
|
+
raise ArgumentError, 'Could not find latest TinyMCE version' if !file_element
|
76
|
+
end
|
77
|
+
|
78
|
+
filename = file_element.innerHTML
|
79
|
+
file_url = file_element['href']
|
80
|
+
|
81
|
+
# Download and install it
|
82
|
+
Dir.chdir('/tmp/') do
|
83
|
+
begin
|
84
|
+
puts 'Downloading TinyMCE source...' if verbose
|
85
|
+
system("wget '#{file_url}' &> wget.log")
|
86
|
+
puts 'Extracting...' if verbose
|
87
|
+
system("tar xf #{filename} &> tar.log")
|
88
|
+
File.delete(filename)
|
89
|
+
FileUtils.mkdir_p(target_path)
|
90
|
+
FileUtils.cp_r("#{source_path}/.", target_path)
|
91
|
+
FileUtils.rmtree(source_path)
|
92
|
+
puts 'Done!' if verbose
|
93
|
+
rescue Object => e
|
94
|
+
puts "Error: #{e.inspect}"
|
95
|
+
puts 'Also see the last modified log file (wget.log or tar.log) in /tmp/.'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Uninstalls the TinyMCE installation and optional configuration file
|
101
|
+
def uninstall
|
102
|
+
# Remove the TinyMCE configuration file
|
103
|
+
File.delete(OPTIONS_FILE_PATH)
|
104
|
+
|
105
|
+
# Remove the TinyMCE installation
|
106
|
+
FileUtils.rm_rf("#{RAILS_ROOT}/public/javascripts/tinymce")
|
107
|
+
end
|
108
|
+
|
109
|
+
# Updates the list of possible configuration options that can be used
|
110
|
+
# when initializing the TinyMCE script. These are always installed to
|
111
|
+
# the application folder, config/tiny_mce_options.yml. If this file
|
112
|
+
# does not exist, then the TinyMCE helper will not be able to verify
|
113
|
+
# that all of the initialization options are valid.
|
114
|
+
def update_options
|
115
|
+
require 'hpricot'
|
116
|
+
require 'open-uri'
|
117
|
+
require 'yaml'
|
118
|
+
|
119
|
+
puts 'Downloading configuration options from TinyMCE Wiki...' if verbose
|
120
|
+
doc = Hpricot(open('http://wiki.moxiecode.com/index.php/TinyMCE:Configuration'))
|
121
|
+
options = (doc/'a[@title*="Configuration/"]/').collect {|option| option.to_s}.sort
|
122
|
+
options.reject! {|option| option =~ DYNAMIC_OPTIONS}
|
123
|
+
|
124
|
+
File.open("#{RAILS_ROOT}/config/tiny_mce_options.yml", 'w') do |out|
|
125
|
+
YAML.dump(options, out)
|
126
|
+
end
|
127
|
+
puts 'Done!' if verbose
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Are we using TinyMCE?
|
132
|
+
def using_tiny_mce?
|
133
|
+
@uses_tiny_mce
|
134
|
+
end
|
135
|
+
|
136
|
+
# Create the TinyMCE initialization scripts. The default configuration
|
137
|
+
# is for a simple theme that replaces all textareas on the page. For
|
138
|
+
# example, the default initialization script will generate the following:
|
139
|
+
#
|
140
|
+
# tinyMCE.init({
|
141
|
+
# 'mode' : 'textareas',
|
142
|
+
# 'theme' : 'simple'
|
143
|
+
# });
|
144
|
+
#
|
145
|
+
# == Customizing initialization options
|
146
|
+
#
|
147
|
+
# To customize the options to be included in the initialization script,
|
148
|
+
# you can pass in a hash to #tiny_mce_init_script. For example,
|
149
|
+
#
|
150
|
+
# tiny_mce_init_script(
|
151
|
+
# :theme => 'advanced',
|
152
|
+
# :editor_selector => 'rich_text',
|
153
|
+
# :content_css => '/stylesheets/tiny_mce_content.css',
|
154
|
+
# :editor_css => '/stylesheets/tiny_mce_editor.css',
|
155
|
+
# :auto_reset_designmode => true
|
156
|
+
# )
|
157
|
+
#
|
158
|
+
# will generate:
|
159
|
+
#
|
160
|
+
# tinyMCE.init({
|
161
|
+
# 'mode' : 'textareas',
|
162
|
+
# 'theme' : 'advanced',
|
163
|
+
# 'editor_selected' : 'rich_text',
|
164
|
+
# 'content_css' : '/stylesheets/tiny_mce_content.css'
|
165
|
+
# });
|
166
|
+
#
|
167
|
+
# == Validating options
|
168
|
+
#
|
169
|
+
# If additional options are passed in to initialize TinyMCE, they will be
|
170
|
+
# validated against the list of valid options in PluginAWeek::Helpers::TinyMCEHelper#valid_options.
|
171
|
+
# These options are configured in the file config/tiny_mce_options.yml.
|
172
|
+
# You can generate this file by invoke the rake task tiny_mce:update_options.
|
173
|
+
def tiny_mce_init_script(options = @tiny_mce_options)
|
174
|
+
options ||= {}
|
175
|
+
options.stringify_keys!.reverse_merge!(
|
176
|
+
'mode' => 'textareas',
|
177
|
+
'theme' => 'simple'
|
178
|
+
)
|
179
|
+
|
180
|
+
# Check validity
|
181
|
+
plugins = options['plugins']
|
182
|
+
options_to_validate = options.reject {|option, value| plugins && plugins.include?(option.split('_')[0]) || option =~ DYNAMIC_OPTIONS}
|
183
|
+
options_to_validate.assert_valid_keys(@@valid_options) if @@valid_options && @@valid_options.any?
|
184
|
+
|
185
|
+
init_script = 'tinyMCE.init({'
|
186
|
+
|
187
|
+
options.sort.each do |key, value|
|
188
|
+
init_script += "\n#{key} : "
|
189
|
+
|
190
|
+
case value
|
191
|
+
when String, Symbol, Fixnum
|
192
|
+
init_script << "'#{value}'"
|
193
|
+
when Array
|
194
|
+
init_script << "'#{value.join(',')}'"
|
195
|
+
when TrueClass
|
196
|
+
init_script << 'true'
|
197
|
+
when FalseClass
|
198
|
+
init_script << 'false'
|
199
|
+
else
|
200
|
+
raise ArgumentError, "Cannot parse value of type #{value.class} passed for TinyMCE option #{key}"
|
201
|
+
end
|
202
|
+
|
203
|
+
init_script << ','
|
204
|
+
end
|
205
|
+
|
206
|
+
init_script.chop << "\n});"
|
207
|
+
end
|
208
|
+
|
209
|
+
# Generate the TinyMCE
|
210
|
+
def tiny_mce(*args)
|
211
|
+
javascript_tag tiny_mce_init_script(*args)
|
212
|
+
end
|
213
|
+
|
214
|
+
# The name of the TinyMCE javascript file to use. In development, this
|
215
|
+
# will use the source (uncompressed) file in order to help with debugging
|
216
|
+
# issues that occur within TinyMCE. In production, the compressed version
|
217
|
+
# of TinyMCE will be used in order to increased download speed.
|
218
|
+
def tiny_mce_file_name
|
219
|
+
RAILS_ENV == 'development' ? 'tinymce/tiny_mce_src' : 'tinymce/tiny_mce'
|
220
|
+
end
|
221
|
+
|
222
|
+
# Generates the javascript include for TinyMCE. For example,
|
223
|
+
#
|
224
|
+
# javascript_include_tiny_mce
|
225
|
+
#
|
226
|
+
# will generate:
|
227
|
+
#
|
228
|
+
# <script type="text/javascript" src="/javascripts/tinymce/tiny_mce.js"></script>
|
229
|
+
def javascript_include_tiny_mce
|
230
|
+
javascript_include_tag tiny_mce_file_name
|
231
|
+
end
|
232
|
+
|
233
|
+
# Conditionally includes the TinyMCE javascript file if the variable
|
234
|
+
# @uses_tiny_mce has been set to true.
|
235
|
+
def javascript_include_tiny_mce_if_used
|
236
|
+
javascript_include_tiny_mce if using_tiny_mce?
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
ActionController::Base.class_eval do
|
243
|
+
helper PluginAWeek::Helpers::TinyMCEHelper
|
244
|
+
end
|