Skip to content

Commit

Permalink
Added support for FormBuilder#tinymce(method_name)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Jun 1, 2009
1 parent 1f3215f commit 8287bc2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
64 changes: 32 additions & 32 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,31 @@ requires a TinyMCE editor.

== Installation

* Install this plugin into vendor/plugins/tinymce_hammer.
* Download Moxiecode's TinyMCE and install it somewhere inside of plublic.
The assumed default path is RAILS_ROOT/public/javascripts/tiny_mce.
1) Install this plugin into vendor/plugins/tinymce_hammer
2) Install TinyMCE somwhere inside public/ (the default location is assumed to
be RAILS_ROOT/public/javascript/tiny_mce).

http://tinymce.moxiecode.com/download.php

== Plugin Configuration

You need to tell tinymce_hammer what plugins, languages and theme files you
require. The TinyMCE primary library and all of the configured language,
theme and plugin files (and their language files) are combined into a single
javascript file and cached to disk.

NOTE: Some plugins and themes have their own language files. These language
files are auto combined as well for each language you configure.

Valid configuration options (and their defaults) are:

* install_path - '/javascripts/tiny_mce'
* plugins - ['paste']
* languages - ['en']
* themes - ['advanced']

NOTE: install_path is assumed to be rooted in RAILS_ROOT/public.

Here is a sample configuration file:

Tinymce::Hammer.install_path = '/javascripts/lib/tiny_mce'
Tinymce::Hammer.plugins = %w(safari table paste paste2 tabfocus)
Tinymce::Hammer.languages = %w(en es)
Get TinyMCE here: http://tinymce.moxiecode.com/download.php

== Basic Usage

The simplest method to you TinyMCE is to use one of the view helpers that
wrap the most basic textfield.

=== Example 1: tinymce_tag helper
=== Example 1: tinymce_tag (form tag helper)

This is your basic drop-in replacement for text_area_tag:

<%= tinymce_tag('comment[body]', 'Your comment goes here ...') %>

=== Example 2, tinymce helper
=== Example 2: tinymce (form helper)

This is just like the text_area helper, it assumes there is an instance
variable, and if found will pull data from that to populate the field with.

<%= tinymce(:comment, :body) %>

=== Example 3, tinymce with form builder
=== Example 3: tinymce (form builder helepr)

<%- form_for @comment do |form| -%>
<%= form.label :body %>
Expand All @@ -94,6 +69,31 @@ You maybe:
* require multiple editors on the same page that are configured differently
* need to register javascript callbacks with TinyMCE

== Plugin Configuration

You need to tell tinymce_hammer what plugins, languages and theme files you
require. The TinyMCE primary library and all of the configured language,
theme and plugin files (and their language files) are combined into a single
javascript file and cached to disk.

NOTE: Some plugins and themes have their own language files. These language
files are auto combined as well for each language you configure.

Valid configuration options (and their defaults) are:

* install_path - '/javascripts/tiny_mce'
* plugins - ['paste']
* languages - ['en']
* themes - ['advanced']

NOTE: install_path is assumed to be rooted in RAILS_ROOT/public.

Here is a sample configuration file:

Tinymce::Hammer.install_path = '/javascripts/lib/tiny_mce'
Tinymce::Hammer.plugins = %w(safari table paste paste2 tabfocus)
Tinymce::Hammer.languages = %w(en es)




Expand Down
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ActionController::Base.send(:include, Tinymce::Hammer::ControllerMethods)
ActionView::Base.send(:include, Tinymce::Hammer::ViewHelpers)
ActionView::Helpers::FormBuilder.send(:include, Tinymce::Hammer::BuilderMethods)
9 changes: 9 additions & 0 deletions lib/tinymce/hammer/builder_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Tinymce::Hammer::BuilderMethods

def tinymce method, options = {}
@template.require_tinymce_hammer
@template.append_class_name(options, 'tinymce')
self.text_area(method, options)
end

end
12 changes: 6 additions & 6 deletions lib/tinymce/hammer/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ def tinymce_hammer_javascript_tags

def tinymce_tag name, content = '', options = {}
require_tinymce_hammer
append_tinymce_class(options)
append_class_name(options, 'tinymce')
text_area_tag(name, content, options)
end

def tinymce object_name, method, options = {}
require_tinymce_hammer
append_tinymce_class(options)
append_class_name(options, 'tinymce')
text_area(object_name, method, options)
end

def append_tinymce_class options #:nodoc
key = options.has_key?('class') ? 'class' : :class
unless options[key].to_s =~ /(^|\s+)tinymce(\s+|$)/
options[key] = "#{options[key]} tinymce".lstrip
def append_class_name options, class_name #:nodoc:
key = options.has_key?('class') ? 'class' : :class
unless options[key].to_s =~ /(^|\s+)#{class_name}(\s+|$)/
options[key] = "#{options[key]} #{class_name}".strip
end
options
end
Expand Down

0 comments on commit 8287bc2

Please sign in to comment.