tinymce_hammer 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/README.rdoc +200 -0
- data/Rakefile +7 -0
- data/app/controllers/tinymce/hammer_controller.rb +13 -0
- data/config/routes.rb +4 -0
- data/lib/tasks/tinymce.rake +7 -0
- data/lib/tinymce/engine.rb +23 -0
- data/lib/tinymce/hammer.rb +48 -0
- data/lib/tinymce/hammer/builder_methods.rb +9 -0
- data/lib/tinymce/hammer/combiner.rb +97 -0
- data/lib/tinymce/hammer/controller_methods.rb +18 -0
- data/lib/tinymce/hammer/view_helpers.rb +99 -0
- data/lib/tinymce_hammer.rb +1 -0
- data/tinymce_hammer.gemspec +17 -0
- metadata +72 -0
data/README.rdoc
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
= tinymce_hammer
|
2
|
+
|
3
|
+
== Attention
|
4
|
+
|
5
|
+
<b>This is the Rails 3 gem version of tinymce_hammer. If you want to use tinymce_hammer with Rails 2, please checkout branch rails2.</b>
|
6
|
+
|
7
|
+
See the plugin website for guides/tutorials: http://tinymcehammer.lanalot.com/
|
8
|
+
|
9
|
+
tinymce_hammer makes its easy to use the TinyMCE WYSIWYG editor inside a Ruby
|
10
|
+
On Rails (2.3/3+) application. What it does:
|
11
|
+
|
12
|
+
* Easy to use, two-step installation and you are ready to go. Form helpers are
|
13
|
+
provided for most common cases.
|
14
|
+
|
15
|
+
* Flexible, need to lazy load TinyMCE w/javascript? Need two different editors
|
16
|
+
on the same page? Want to use your own form helpers? No problem.
|
17
|
+
|
18
|
+
* Fast, TinyMCE requests lots of .js files for the most basic of editor
|
19
|
+
configurations. It does all this over XMLHttpRequest. tinymce_hammer
|
20
|
+
eliminates this by combining all required library files (plugins, themes,
|
21
|
+
languages, etc) into one javascript file.
|
22
|
+
|
23
|
+
== Installation
|
24
|
+
|
25
|
+
1. Manually as system wide gem:
|
26
|
+
|
27
|
+
$ gem install tinymce_hammer
|
28
|
+
|
29
|
+
Or inside your Gemfile:
|
30
|
+
|
31
|
+
gem 'tinymce_hammer'
|
32
|
+
|
33
|
+
Remember to run:
|
34
|
+
|
35
|
+
$ bundle install
|
36
|
+
|
37
|
+
2. <b>This fork does not contain a bundled tinymce version!</b> So download it here:
|
38
|
+
|
39
|
+
http://tinymce.moxiecode.com/download/download.php
|
40
|
+
|
41
|
+
3. And copy it to:
|
42
|
+
|
43
|
+
your_app/public/javascript/tiny_mce
|
44
|
+
|
45
|
+
== Basic Usage
|
46
|
+
|
47
|
+
The easiest way to use tinymce_hammer involves 2 steps:
|
48
|
+
|
49
|
+
1. Call the follow function in your layout/template. It can go anywhere
|
50
|
+
really, but inside the head tags is prefered:
|
51
|
+
|
52
|
+
<%= init_tinymce_hammer_if_required %>
|
53
|
+
|
54
|
+
2. Use one of the following 3 methods to add a tinymce enabled textarea tag
|
55
|
+
to your page.
|
56
|
+
|
57
|
+
=== Example 1: tinymce_tag (form tag helper)
|
58
|
+
|
59
|
+
This is your basic drop-in replacement for text_area_tag:
|
60
|
+
|
61
|
+
<%= tinymce_tag('comment[body]', 'Your comment goes here ...') %>
|
62
|
+
|
63
|
+
=== Example 2: tinymce (form helper)
|
64
|
+
|
65
|
+
This is just like the text_area helper, it assumes there is an instance
|
66
|
+
variable, and if found will pull data from that to populate the field with.
|
67
|
+
|
68
|
+
<%= tinymce(:comment, :body) %>
|
69
|
+
|
70
|
+
=== Example 3: tinymce (form builder helper)
|
71
|
+
|
72
|
+
<%- form_for @comment do |form| -%>
|
73
|
+
<%= form.label :body %>
|
74
|
+
<%= form.tinymce :body %>
|
75
|
+
<% end %>
|
76
|
+
|
77
|
+
=== Example 4: via Javascript:
|
78
|
+
|
79
|
+
You cannot use the tinymce textarea form helper when using this initializing method,
|
80
|
+
but you can add your own classname to your textarea and pass this as parameter to the
|
81
|
+
init_tinymce() helper.
|
82
|
+
|
83
|
+
=== Example viewfile:
|
84
|
+
|
85
|
+
<% form_for @post do |f| %>
|
86
|
+
<%= f.text_area :body, class => "my_tinymce" %>
|
87
|
+
<% end %>
|
88
|
+
<%= init_tinymce('my_tinymce') %>
|
89
|
+
|
90
|
+
You can choose whatever you want as the classname for the text_area. Just assure to pass
|
91
|
+
this classname also to the textarea you want to be a tinyMCE Editor. This helps to initialize
|
92
|
+
only the returned form and not all textareas already on the page.
|
93
|
+
Very handy! See the RDoc for more about the parameters.
|
94
|
+
|
95
|
+
NOTICE! This helper DOES NOT load the combined js file for you. So include it with the javascript_include_tag
|
96
|
+
helper as usual.
|
97
|
+
|
98
|
+
== Deployment
|
99
|
+
|
100
|
+
Tinymce defaults to caching the combined js file using ActionController's
|
101
|
+
caches_page method. This causes problems in certain deployed environments
|
102
|
+
(like Heroku) where you can not write to disk, or to web servers that don't
|
103
|
+
pass requests for js files through. To avoid this issue run the following
|
104
|
+
rake task:
|
105
|
+
|
106
|
+
rake tinymce:cache_js
|
107
|
+
|
108
|
+
You can commit the js file that builds to your repository and that should avoid
|
109
|
+
deploy time issues. You could also add that to a capistrano recipe.
|
110
|
+
|
111
|
+
== Advanced Usage
|
112
|
+
|
113
|
+
The basic examples above get a TinyMCE editor up and running quickly. You
|
114
|
+
might have more specific needs that the basic approach doesn't fill. You
|
115
|
+
might:
|
116
|
+
|
117
|
+
* want to lazy load TinyMCE dynamically after page load
|
118
|
+
* only want the combined javascript TinyMCE file provided by tinymce_hammer
|
119
|
+
* require multiple editors on the same page that are configured differently
|
120
|
+
* need to register javascript callbacks with TinyMCE
|
121
|
+
|
122
|
+
In all of the above cases its best to load the combined JS file and call
|
123
|
+
the tinyMCE.init() javascript function yourself. I'll leave that up to you
|
124
|
+
how and when. The url to the combine file is:
|
125
|
+
|
126
|
+
/javascripts/tinymce_hammer.js
|
127
|
+
|
128
|
+
It works great to lazy load (I personally use LazyLoad from
|
129
|
+
http://wonko.com/post/painless_javascript_lazy_loading_with_lazyload).
|
130
|
+
|
131
|
+
== Configuration
|
132
|
+
|
133
|
+
tinymce_hammer has five configuration options. Its best to place them in an
|
134
|
+
intializer (like config/initializer/tinymce_hammer.rb). Here they are with their
|
135
|
+
default values:
|
136
|
+
|
137
|
+
* Tinymce::Hammer.install_path
|
138
|
+
|
139
|
+
'/javascripts/tiny_mce'
|
140
|
+
|
141
|
+
* Tinymce::Hammer.plugins
|
142
|
+
|
143
|
+
['paste']
|
144
|
+
|
145
|
+
* Tinymce::Hammer.languages
|
146
|
+
|
147
|
+
['en']
|
148
|
+
|
149
|
+
* Tinymce::Hammer.themes
|
150
|
+
|
151
|
+
['advanced']
|
152
|
+
|
153
|
+
* Tinymce::Hammer.init
|
154
|
+
|
155
|
+
[
|
156
|
+
[:paste_convert_headers_to_strong, true],
|
157
|
+
[:paste_convert_middot_lists, true],
|
158
|
+
[:paste_remove_spans, true],
|
159
|
+
[:paste_remove_styles, true],
|
160
|
+
[:paste_strip_class_attributes, true],
|
161
|
+
[:theme, 'advanced'],
|
162
|
+
[:theme_advanced_toolbar_align, 'left'],
|
163
|
+
[:theme_advanced_toolbar_location, 'top'],
|
164
|
+
[:theme_advanced_buttons1, 'undo,redo,cut,copy,paste,pastetext,|,bold,italic,strikethrough,blockquote,charmap,bullist,numlist,removeformat,|,link,unlink,image,|,cleanup,code'],
|
165
|
+
[:theme_advanced_buttons2, ''],
|
166
|
+
[:theme_advanced_buttons3, ''],
|
167
|
+
[:valid_elements, "a[href|title],blockquote[cite],br,caption,cite,code,dl,dt,dd,em,i,img[src|alt|title|width|height|align],li,ol,p,pre,q[cite],small,strike,strong/b,sub,sup,u,ul"],
|
168
|
+
]
|
169
|
+
|
170
|
+
NOTE: install_path is the path inside public to your TinyMCE installation.
|
171
|
+
|
172
|
+
NOTE: please don't set the <tt>mode</tt> option for the init. This is managed
|
173
|
+
by tinymce_hammer. If this doesn't work for your, try the advanced usage.
|
174
|
+
|
175
|
+
== Sample Configuration
|
176
|
+
|
177
|
+
Tinymce::Hammer.install_path = '/javascripts/lib/tiny_mce'
|
178
|
+
|
179
|
+
Tinymce::Hammer.plugins = %w(safari table paste tabfocus)
|
180
|
+
|
181
|
+
Tinymce::Hammer.init = [
|
182
|
+
[:paste_convert_headers_to_strong, true],
|
183
|
+
[:paste_convert_middot_lists, true],
|
184
|
+
[:paste_remove_spans, true],
|
185
|
+
[:paste_remove_styles, true],
|
186
|
+
[:paste_strip_class_attributes, true],
|
187
|
+
[:theme, 'advanced'],
|
188
|
+
[:theme_advanced_toolbar_align, 'left'],
|
189
|
+
[:theme_advanced_toolbar_location, 'top'],
|
190
|
+
[:theme_advanced_buttons1, 'undo,redo,cut,copy,paste,pastetext,|,bold,italic,strikethrough,blockquote,charmap,bullist,numlist,removeformat,|,link,unlink,image,|,cleanup,code'],
|
191
|
+
[:theme_advanced_buttons2, ''],
|
192
|
+
[:theme_advanced_buttons3, ''],
|
193
|
+
[:valid_elements, "a[href|title],blockquote[cite],br,caption,cite,code,dl,dt,dd,em,i,img[src|alt|title|width|height|align],li,ol,p,pre,q[cite],small,strike,strong/b,sub,sup,u,ul"],
|
194
|
+
]
|
195
|
+
|
196
|
+
== Questions
|
197
|
+
|
198
|
+
The best way to get help is to post to the mailing list (google group).
|
199
|
+
|
200
|
+
http://groups.google.com/group/tinymce_hammer/topics
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Tinymce::HammerController < ActionController::Base
|
2
|
+
|
3
|
+
caches_page :combine
|
4
|
+
|
5
|
+
before_filter do |c|
|
6
|
+
c.headers["Content-Type"] = "text/javascript; charset=utf-8"
|
7
|
+
end
|
8
|
+
|
9
|
+
def combine
|
10
|
+
render :text => Tinymce::Hammer::Combiner.combined_js, :layout => false
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'action_controller/base'
|
2
|
+
require 'action_view'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), "hammer.rb")
|
5
|
+
|
6
|
+
%w(builder_methods combiner controller_methods view_helpers).each do |class_name|
|
7
|
+
require File.join(File.dirname(__FILE__), "hammer", class_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
module Tinymce
|
11
|
+
class Engine < Rails::Engine
|
12
|
+
|
13
|
+
# Load rake tasks
|
14
|
+
rake_tasks do
|
15
|
+
load File.join(File.dirname(__FILE__), '..', 'tasks', 'tinymce.rake')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActionController::Base.send(:include, Tinymce::Hammer::ControllerMethods)
|
22
|
+
ActionView::Base.send(:include, Tinymce::Hammer::ViewHelpers)
|
23
|
+
ActionView::Helpers::FormBuilder.send(:include, Tinymce::Hammer::BuilderMethods)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Tinymce
|
2
|
+
module Hammer
|
3
|
+
|
4
|
+
mattr_accessor :install_path, :src, :languages, :themes, :plugins, :setup
|
5
|
+
|
6
|
+
@@install_path = '/javascripts/tiny_mce'
|
7
|
+
|
8
|
+
@@src = false
|
9
|
+
|
10
|
+
@@setup = nil
|
11
|
+
|
12
|
+
@@plugins = ['paste']
|
13
|
+
|
14
|
+
@@languages = ['en']
|
15
|
+
|
16
|
+
@@themes = ['advanced']
|
17
|
+
|
18
|
+
@@init = {
|
19
|
+
:paste_convert_headers_to_strong => true,
|
20
|
+
:paste_convert_middot_lists => true,
|
21
|
+
:paste_remove_spans => true,
|
22
|
+
:paste_remove_styles => true,
|
23
|
+
:paste_strip_class_attributes => true,
|
24
|
+
:theme => 'advanced',
|
25
|
+
:theme_advanced_toolbar_align => 'left',
|
26
|
+
:theme_advanced_toolbar_location => 'top',
|
27
|
+
:theme_advanced_buttons1 => 'undo,redo,cut,copy,paste,pastetext,|,bold,italic,strikethrough,blockquote,charmap,bullist,numlist,removeformat,|,link,unlink,image,|,cleanup,code',
|
28
|
+
:theme_advanced_buttons2 => '',
|
29
|
+
:theme_advanced_buttons3 => '',
|
30
|
+
:valid_elements => "a[href|title,blockquote[cite],br,caption,cite,code,dl,dt,dd,em,i,img[src|alt|title|width|height|align],li,ol,p,pre,q[cite],small,strike,strong/b,sub,sup,u,ul" ,
|
31
|
+
}
|
32
|
+
|
33
|
+
def self.init= js
|
34
|
+
@@init = js
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.init
|
38
|
+
@@init
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.cache_js
|
42
|
+
File.open("#{Rails.root}/public/javascripts/tinymce_hammer.js", 'w') do |file|
|
43
|
+
file.write Combiner.combined_js
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Tinymce::Hammer::Combiner
|
2
|
+
|
3
|
+
REQUIRED = true
|
4
|
+
OPTIONAL = false
|
5
|
+
MARK_DONE = true
|
6
|
+
|
7
|
+
# Combines the following files into a single .js file, and caches that file
|
8
|
+
# to disk (when action_controller.perform_caching == true).
|
9
|
+
#
|
10
|
+
# * tiny_mce.js (the main library)
|
11
|
+
# * each requested language file (like en.js)
|
12
|
+
# * each requested theme's editor_template.js
|
13
|
+
# * each requested theme's language files
|
14
|
+
# * each requested plugin's editor_plugin.js
|
15
|
+
# * each requested plugin's language files
|
16
|
+
#
|
17
|
+
# On-top of combining .js files support js is added to the top and end of this
|
18
|
+
# file to alert tiny_mce that these files have been loaded into the dom and
|
19
|
+
# no XMLHttpRequests are required to load these dynamically.
|
20
|
+
def self.combined_js
|
21
|
+
|
22
|
+
init_content
|
23
|
+
|
24
|
+
suffix = Tinymce::Hammer.src ? '_src' : ''
|
25
|
+
|
26
|
+
# add the tiny mce library
|
27
|
+
add_content("tiny_mce#{suffix}.js", REQUIRED)
|
28
|
+
|
29
|
+
# add languages
|
30
|
+
Tinymce::Hammer.languages.each do |lang|
|
31
|
+
add_content("langs/#{lang}.js", REQUIRED, MARK_DONE)
|
32
|
+
end
|
33
|
+
|
34
|
+
# add themes (and their languages)
|
35
|
+
Tinymce::Hammer.themes.each do |theme|
|
36
|
+
add_content("themes/#{theme}/editor_template#{suffix}.js", REQUIRED, MARK_DONE)
|
37
|
+
Tinymce::Hammer.languages.each do |lang|
|
38
|
+
add_content("themes/#{theme}/langs/#{lang}.js", OPTIONAL, MARK_DONE)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# add plugins (and their languages)
|
43
|
+
Tinymce::Hammer.plugins.each do |plugin|
|
44
|
+
add_content("plugins/#{plugin}/editor_plugin#{suffix}.js" , OPTIONAL, MARK_DONE)
|
45
|
+
Tinymce::Hammer.languages.each do |lang|
|
46
|
+
add_content("plugins/#{plugin}/langs/#{lang}.js", OPTIONAL, MARK_DONE)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
@content + @events.join("\n")
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
# this code tells tiny_mce where its main library files are located and that
|
57
|
+
# it was loaded via a combined file.
|
58
|
+
def self.init_content
|
59
|
+
@content = "
|
60
|
+
(function(){var DomReady=window.DomReady={};var userAgent=navigator.userAgent.toLowerCase();var browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:(/msie/.test(userAgent))&&(!/opera/.test(userAgent)),mozilla:(/mozilla/.test(userAgent))&&(!/(compatible|webkit)/.test(userAgent))};var readyBound=false;var isReady=false;var readyList=[];function domReady(){if(!isReady){isReady=true;if(readyList){for(var fn=0;fn<readyList.length;fn++){readyList[fn].call(window,[]);}
|
61
|
+
readyList=[];}}};function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){if(oldonload){oldonload();}
|
62
|
+
func();}}};function bindReady(){if(readyBound){return;}
|
63
|
+
readyBound=true;if(document.addEventListener&&!browser.opera){document.addEventListener('DOMContentLoaded',domReady,false);}
|
64
|
+
if(browser.msie&&window==top)(function(){if(isReady)return;try{document.documentElement.doScroll('left');}catch(error){setTimeout(arguments.callee,0);return;}
|
65
|
+
domReady();})();if(browser.opera){document.addEventListener('DOMContentLoaded',function(){if(isReady)return;for(var i=0;i<document.styleSheets.length;i++)
|
66
|
+
if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return;}
|
67
|
+
domReady();},false);}
|
68
|
+
if(browser.safari){var numStyles;(function(){if(isReady)return;if(document.readyState!='loaded'&&document.readyState!='complete'){setTimeout(arguments.callee,0);return;}
|
69
|
+
if(numStyles===undefined){var links=document.getElementsByTagName('link');for(var i=0;i<links.length;i++){if(links[i].getAttribute('rel')=='stylesheet'){numStyles++;}}
|
70
|
+
var styles=document.getElementsByTagName('style');numStyles+=styles.length;}
|
71
|
+
if(document.styleSheets.length!=numStyles){setTimeout(arguments.callee,0);return;}
|
72
|
+
domReady();})();}
|
73
|
+
addLoadEvent(domReady);};DomReady.ready=function(fn,args){bindReady();if(isReady){fn.call(window,[]);}else{readyList.push(function(){return fn.call(window,[]);});}};bindReady();})();
|
74
|
+
|
75
|
+
|
76
|
+
window.tinyMCEPreInit = {
|
77
|
+
base : '#{Tinymce::Hammer.install_path}',
|
78
|
+
suffix : '',
|
79
|
+
query : ''
|
80
|
+
}
|
81
|
+
window.tinyMCE_GZ = { loaded : true };"
|
82
|
+
|
83
|
+
@events = []
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.add_content path, required, mark_done = false
|
87
|
+
url_path = File.join(Tinymce::Hammer.install_path, path)
|
88
|
+
disk_path = File.join(Rails.root, 'public', Tinymce::Hammer.install_path, path)
|
89
|
+
if required or File.exists?(disk_path)
|
90
|
+
@content += File.read(disk_path)
|
91
|
+
if mark_done
|
92
|
+
@events << "tinymce.ScriptLoader.markDone(tinyMCE.baseURI.toAbsolute('#{url_path}'));";
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tinymce::Hammer::ControllerMethods
|
2
|
+
|
3
|
+
def self.included base
|
4
|
+
base.send(:hide_action, :require_tinymce_hammer)
|
5
|
+
base.send(:helper_method, :require_tinymce_hammer)
|
6
|
+
base.send(:hide_action, :tinymce_hammer_required?)
|
7
|
+
base.send(:helper_method, :tinymce_hammer_required?)
|
8
|
+
end
|
9
|
+
|
10
|
+
def require_tinymce_hammer
|
11
|
+
@tinymce_hammer_required = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def tinymce_hammer_required?
|
15
|
+
@tinymce_hammer_required == true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Tinymce::Hammer::ViewHelpers
|
2
|
+
|
3
|
+
# If you call this method in your document head two script tags will be
|
4
|
+
# inserted when tinymce is required, otherwise nothing will be inserted.
|
5
|
+
def init_tinymce_hammer_if_required
|
6
|
+
if tinymce_hammer_required?
|
7
|
+
tinymce_hammer_javascript_tags
|
8
|
+
else
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def init_tinymce_hammer
|
14
|
+
tinymce_hammer_javascript_tags
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns two script tags. The first loads the combined javascript file
|
18
|
+
# containing tinymce. The second tag initializes tiny mce.
|
19
|
+
def tinymce_hammer_javascript_tags
|
20
|
+
|
21
|
+
init = ::Tinymce::Hammer.init
|
22
|
+
if init.is_a?(Hash)
|
23
|
+
init = HashWithIndifferentAccess.new(init)
|
24
|
+
init = init.keys.sort.collect(&:to_s).sort.collect{|key|
|
25
|
+
[key, init[key]]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
init = init.collect {|key,value| "#{key} : #{value.to_json}" }.join(', ')
|
29
|
+
|
30
|
+
setup = "init.setup = #{Tinymce::Hammer.setup};" if Tinymce::Hammer.setup
|
31
|
+
|
32
|
+
return "
|
33
|
+
<script src='#{tinymce_hammer_js_path}' type='text/javascript'></script>
|
34
|
+
<script type='text/javascript'>
|
35
|
+
TinymceHammer = {
|
36
|
+
init : function() {
|
37
|
+
var init = { #{init} };
|
38
|
+
init.mode = 'specific_textareas';
|
39
|
+
init.editor_selector = 'tinymce';
|
40
|
+
init.plugins = '#{Tinymce::Hammer.plugins.join(',')}';
|
41
|
+
init.language = '#{I18n.locale}';
|
42
|
+
#{setup}
|
43
|
+
tinyMCE.init(init);
|
44
|
+
},
|
45
|
+
addEditor : function(dom_id) {
|
46
|
+
tinyMCE.execCommand('mceAddControl', true, dom_id);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
DomReady.ready(TinymceHammer.init);
|
50
|
+
</script>".html_safe
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the TinymceHammer initializer javascript only. Very handy for AJAX calls and on-demand initializing.
|
54
|
+
# You can pass a classname for the textarea you want to initialize, or an array of classnames you want to be initialized.
|
55
|
+
def init_tinymce(classname="tinymce")
|
56
|
+
init = Tinymce::Hammer.init.collect{|key,value|
|
57
|
+
"#{key} : #{value.to_json}"
|
58
|
+
}.join(', ')
|
59
|
+
selector = classname.is_a?(Array) ? classname.join(",") : classname.to_s
|
60
|
+
setup = "init.setup = #{Tinymce::Hammer.setup};" if Tinymce::Hammer.setup
|
61
|
+
init = <<-JS
|
62
|
+
<script type="text/javascript">
|
63
|
+
TinymceHammer = {
|
64
|
+
init : function() {
|
65
|
+
var init = { #{init} };
|
66
|
+
init.mode = 'specific_textareas';
|
67
|
+
init.editor_selector = '#{selector}';
|
68
|
+
init.plugins = '#{Tinymce::Hammer.plugins.join(',')}';
|
69
|
+
init.language = '#{Tinymce::Hammer.languages.first}';
|
70
|
+
#{setup}
|
71
|
+
tinyMCE.init(init);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
TinymceHammer.init();
|
75
|
+
</script>
|
76
|
+
JS
|
77
|
+
end
|
78
|
+
|
79
|
+
def tinymce_tag name, content = '', options = {}
|
80
|
+
require_tinymce_hammer
|
81
|
+
append_class_name(options, 'tinymce')
|
82
|
+
text_area_tag(name, content, options)
|
83
|
+
end
|
84
|
+
|
85
|
+
def tinymce object_name, method, options = {}
|
86
|
+
require_tinymce_hammer
|
87
|
+
append_class_name(options, 'tinymce')
|
88
|
+
text_area(object_name, method, options)
|
89
|
+
end
|
90
|
+
|
91
|
+
def append_class_name options, class_name #:nodoc:
|
92
|
+
key = options.has_key?('class') ? 'class' : :class
|
93
|
+
unless options[key].to_s =~ /(^|\s+)#{class_name}(\s+|$)/
|
94
|
+
options[key] = "#{options[key]} #{class_name}".strip
|
95
|
+
end
|
96
|
+
options
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'tinymce/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tinymce_hammer}
|
5
|
+
s.version = "0.2.2"
|
6
|
+
|
7
|
+
s.authors = ["Trevor Rowe", "Thomas von Deyen"]
|
8
|
+
s.date = %q{2011-06-05}
|
9
|
+
s.summary = %q{TinyMCE WYSIWYG editor for your Rails 3 application.}
|
10
|
+
s.description = %q{TinyMCE Hammer makes its easy to use the TinyMCE WYSIWYG editor inside a Ruby
|
11
|
+
On Rails (3+) application.}
|
12
|
+
s.email = %q{tvdeyen@gmail.com}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.homepage = %q{https://github.com/tvdeyen/tinymce_hammer}
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tinymce_hammer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trevor Rowe
|
9
|
+
- Thomas von Deyen
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-06-05 00:00:00 +02:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: |-
|
19
|
+
TinyMCE Hammer makes its easy to use the TinyMCE WYSIWYG editor inside a Ruby
|
20
|
+
On Rails (3+) application.
|
21
|
+
email: tvdeyen@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- .gitignore
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- app/controllers/tinymce/hammer_controller.rb
|
33
|
+
- config/routes.rb
|
34
|
+
- lib/tasks/tinymce.rake
|
35
|
+
- lib/tinymce/engine.rb
|
36
|
+
- lib/tinymce/hammer.rb
|
37
|
+
- lib/tinymce/hammer/builder_methods.rb
|
38
|
+
- lib/tinymce/hammer/combiner.rb
|
39
|
+
- lib/tinymce/hammer/controller_methods.rb
|
40
|
+
- lib/tinymce/hammer/view_helpers.rb
|
41
|
+
- lib/tinymce_hammer.rb
|
42
|
+
- tinymce_hammer.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: https://github.com/tvdeyen/tinymce_hammer
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.6.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: TinyMCE WYSIWYG editor for your Rails 3 application.
|
71
|
+
test_files: []
|
72
|
+
|