• Stars
    star
    418
  • Rank 103,620 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby on Rails plugin (pre-Rails 3.1) that allows easy implementation of the TinyMCE editor into your applications.

TinyMCE for RailsĀ¶ ā†‘

This gem is being depreciated because I donā€™t have time to maintain it and the code base is in an inconsistent state! Seem following notes.

Note for Rails 3.1 users: in light of the improvements for JavaScript libraries in Rails 3.1ā€™s asset pipeline, this gem/plugin is NOT recommended for Rails 3.1 or above. Use github.com/spohlenz/tinymce-rails!

Note for Rails 3.0 users: consider if github.com/mikehoward/use_tinymce will suit your needs.

Note for Rails 2.3x users: I recommend checking the commit messags on forks of this gem at github.com/kete/tiny_mce/network. Youā€™ll probably have to do a bit of trial and error to get one that works for you. Learn how to build and install a gem from local source.

Final note: I may come back to fixing this gemā€™s codebase, but I canā€™t guarantee it, thus I recommend you explore alternatives.

This gem/plugin provides for the installation and utilization of TinyMCE in Ruby on Rails applications of version 2.3.5 and onward.

TinyMCE is a WYSIWYG HTML editing component released under the GNU Lesser General Public License 2.1 (LGPL 2.1) by Moxiecode Systems (tinymce.moxiecode.com/).

DenpendencyĀ¶ ā†‘

As of 0.1.7, this gem depends on jQuery being loaded before the TinyMCE init declaration. If you are like me and also load Prototype, consider adding something like this after your jQuery load:

<%= javascript_tag('jQuery.noConflict();') -%>

InstallationĀ¶ ā†‘

Installing TinyMCE for Rails takes no more than a few minutes to install.

Step 1Ā¶ ā†‘

The recommended installation method for getting tiny_mce working in your application is to use the gem version. To do so, open the console and run:

[sudo] gem install tiny_mce

Then add this to config/environment.rb of your Rails application:

config.gem 'tiny_mce'

For Rails 3, you will need to add the following line to file Gemfile:

gem 'tiny_mce'

Alternatively, you can install it as a plugin. To do so, open a console, and in the root of you Rails application, install the plugin by running one of the following (depending on the method you use to import plugins):

  • script/plugin install git://github.com/kete/tiny_mce.git

  • piston import git://github.com/kete/tiny_mce.git vendor/plugins/tiny_mce

  • git submodule add git://github.com/kete/tiny_mce.git vendor/plugins/tiny_mce

  • Download the latest files ( github.com/kete/tiny_mce/tarball/master ) and extract to vendor/plugins/tiny_mce

Step 2Ā¶ ā†‘

For the page you want to add TinyMCE, go to the viewā€™s controller and add:

uses_tiny_mce

Then append the following to the text area you want to transform into a TinyMCE editor. You can change the name of the class you want to use by editing the ā€˜editor_selectorā€™ param in the controller code options.

:class => "mceEditor"

Lastly, add the following line(s) under the <head> element of your application view. Note you may need to add this to the viewā€™s layout.

<%= include_tiny_mce_if_needed %>

Now youā€™re all set! Start your server. The gem/plugin will automatically copy the sources to the public javascripts directory when the server is started.

ConfigurationĀ¶ ā†‘

There are several ways to configure the plugin to get the desirable effect youā€™re looking for. The following ways can be combined to create complex tiny mce setups

Load OrderĀ¶ ā†‘

A load order is present so that you have finer grained control over what shows up where. The load order currently looks like this. The later ones receive more power, that is, the overwrite similar settings in previous configurations.

  1. The default tiny_mce plugin settings. Sets it to work on textareas with class of mceEditor, with the english advanced theme.

  2. config/tiny_mce.yml if present. You set your own options here, used across all editors on the site.

  3. uses_tiny_mce declaration. You set you own options here, used across all editors in the controller.

  4. include_tiny_mce_if_needed declaration. You set your own options here, used across all editors contained within that layout.

Below, Iā€™ll cover how to use #2, and #3, which are the most likely ones youā€™ll want to use.

Global OptionsĀ¶ ā†‘

If you have a set of default options that is used throughout all editors in your application, you might want to make them global. You can do this by putting your settings into config/tiny_mce.yml. If the file exists, the tiny_mce plugin will parse the options in it first.

ExampleĀ¶ ā†‘

theme: advanced
plugins:
- table
- fullscreen

TinyMCE optionsĀ¶ ā†‘

You can change the theme, order/choice of buttons, selectors Id, plugins, and many more by passing an :options hash to the uses_tiny_mce declaration.

The options hash can contain any number of settings available in lib/tiny_mce/valid_tinymce_options.yml (a copy of the settings available per version).

If an option is misspelled, invalid, or deprecated (no longer in TinyMCE), when you go to a page containing your editor, you will receive an Exception, which must be dealt with before continuing.

You can read about all these options at tinymce.moxiecode.com/documentation.php

ExampleĀ¶ ā†‘

uses_tiny_mce :options => {
                            :theme => 'advanced',
                            :theme_advanced_resizing => true,
                            :theme_advanced_resize_horizontal => false,
                            :plugins => %w{ table fullscreen }
                          }

Filter optionsĀ¶ ā†‘

If, like most applications, you only need the editor on the new, create, edit, and update pages, then tell the uses_tiny_mce declaration this, so it doesnā€™t load up all the files unnecessarily.

The declaration accepts any number of default parameters a normal controller filter would.

ExampleĀ¶ ā†‘

uses_tiny_mce :only => [:new, :create, :edit, :update]

Additional Javascript optionsĀ¶ ā†‘

Sometimes, when you need complex arrays of data for plugins or such, the plugin helpers arenā€™t complex enough to do what you need. But you can always fall back to supplying your own options. You can this by passing a raw javascript (no <script> tags) to the uses_tiny_mce declaration. Consider the following example for the template plugin.

uses_tiny_mce :raw_options => "template_templates : [ {
                                                        title : 'Editor Details',
                                                        src : 'editor_details.htm',
                                                        description : 'Adds Editors Name and Staff ID'
                                                    } ]"

MethodsĀ¶ ā†‘

TinyMCE has a range of convenience methods for loading TinyMCE. Besides the uses_tiny_mce shown above, they include:

using_tiny_mce?
    Check whether the uses_tiny_mce declaration has been made in the current controller

raw_tiny_mce_init
    Creates a string of javascript formed from the options declared to uses_tiny_mce (is not wrapped in a JS tag though, use tiny_mce_init for that)

tiny_mce_init
    Creates a javascript tag formed from the options declared to uses_tiny_mce (executes whether uses_tiny_mce was declared or not)
tiny_mce_init_if_needed
    Creates a javascript tag formed from the options declared to uses_tiny_mce (executes only when uses_tiny_mce has been declared)

include_tiny_mce_js
    Includes the TinyMCE core javascript file, must be declared before tiny_mce_init (executes whether uses_tiny_mce was declared or not)
include_tiny_mce_js_if_needed
    Includes the TinyMCE core javascript file, must be declared before tiny_mce_init (executes only when uses_tiny_mce has been declared)

include_tiny_mce_if_needed
    Includes the TinyMCE core javascript file, and creates a string of javascript formed from the options declared to uses_tiny_mce (executes only when uses_tiny_mce has been declared)

SpellcheckingĀ¶ ā†‘

See SPELLCHECKING_PLUGIN.rdoc . Note: Spell checking is not tested o regularly maintained. Use with caution.

github.com/kete/tiny_mce/tree/master/SPELLCHECKING_PLUGIN.rdoc

Generating new langĀ¶ ā†‘

If you have a new language to add to this plugin you can generate it:

rake tiny_mce:new:lang LANG=lang

Will generate 4 copy ā€œenā€ files:

  • tiny_mce/lib/tiny_mce/assets/tiny_mce/langs/lang.js

  • tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/advanced/langs/lang.js

  • tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/advanced/langs/lang_dlg.js

  • tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/simple/langs/lang_dlg.js

Now you can make your own translation to the basic tinyMCE by editing these files (donā€™t forget this should be done in a fork of the source code and you may want to rebuild it if you are using TinyMCE as a gem). Remember that if you use some tinyMCE plugins you will have to make translation files for those plugins manually. This commit gives a good example of the other files involved:

github.com/kete/tiny_mce/commit/a55d148588517e37d1b81627817d0fb3341dd4ce

If you want to choose a language globally, update config/tiny_mce.yml with a language entry:

language: pt-BR

You may also change this in the init process for TinyMCE (good for multilanguage sites) use the :options hash accordingly in your code.

You may wish to contribute your language translation back to the TinyMCE project. Details can be found here:

wiki.moxiecode.com/index.php/TinyMCE:Creating_Language

PluginsĀ¶ ā†‘

Plugins allow you to insert or change files of the TinyMCE editor, such as installing TinyMCE Editor plugins.

There is an example plugin at github.com/kete/tiny_mce_plugin_example

A tiny_mce plugin is very simple. github.com/kete/tiny_mce_plugin_example/blob/master/lib/tiny_mce-paste.rb

It requires tiny_mce, installs the TinyMCE sources if they arenā€™t already, creates a subclass of TinyMCE::Plugin, and calls install on it.

TinyMCE::Plugin provides a default self.install method, which copies files from self.assets_path to the tiny_mce directory under public/javascripts

You can overwrite the install method to something more complex, like remove plugins, or swap plugins. Example:

class SwapPasteForPastePlus < TinyMCE::Plugin
  def self.install
    require 'fileutils'
    FileUtils.rm(Rails.public.join('javascripts/tiny_mce/plugins/paste'))
    FileUtils.cp_r(self.assets_path, Rails.public.join('javascripts/tiny_mce'))
  end
end

TestingĀ¶ ā†‘

The plugin comes with a test suite that can be run once the plugin is installed in an application.

Change into the plugins directory and run ā€˜rakeā€™ to start them.

Note: The tests require Rails 2.2 or higher, and are currently tested on Rails 2.3 (so problems in older versions may arise - please see ā€œReporting an Issueā€ if they do)

Reporting an IssueĀ¶ ā†‘

If you have a problem, please report it on the tiny_mce plugin ticket tracker (on Ligthouseapp)

kete.lighthouseapp.com/projects/14744-tiny_mce/tickets

Be sure to include Rails version, plugin version, and when possible, a sample application that can reproduce the problem. Upload it to one of the various file hosting sites and link to it in the ticket. Donā€™t include vendored rails or the tiny_mce plugin in the archive (if I know the versions, Iā€™ll add these myself).

ContributingĀ¶ ā†‘

If youā€™ve added something, why not share it. Fork the repository (github.com/kete/tiny_mce), make the changes and send a pull request to the maintainers.

Changes with tests, and full documentation are preferred.

CreditsĀ¶ ā†‘

This plugin was created by Blake Watters <[email protected]>

This plugin is currently maintained by Kieran Pilkington <[email protected]>

Bundled TinyMCE version: 3.4

More Repositories

1

kete

Kete was developed by Horowhenua Library Trust and Katipo Communications Ltd. to build a digital library of Horowhenua material.
Ruby
57
star
2

convert_attachment_to

A plugin that will take the value of an uploaded file, convert it to either text or HTML, and insert it into specified attribute. Only works with PDF, MS Word, HTML, and plain text documents currently.
Ruby
29
star
3

oembed_provider

A Rails engine to answer oEmbed requests for application media asset models. I.e. this gem allows your application to act as an oEmbed Provider.
Ruby
18
star
4

capistrano-configuration

Write application configuration files on deployment with Ruby
Ruby
15
star
5

acts_as_licensed

Acts As Licensed is a plugin which provides a basic content licensing system to community centred Ruby On Rails applications. The plugin includes a set of Creative Commons New Zealand and Australian licenses, which can be imported (excluding the No Derivative Works variant).
Ruby
13
star
6

mongo_translatable

Rails specific I18n model localization, ala Globalize2, backed by MongoDB rather than an RDBMS. May include UI elements, too.
Ruby
7
star
7

external_search_sources

Display results from external search sources
Ruby
7
star
8

tiny_mce_plugin_example

An example gem using the tiny_mce gems plugin support
3
star
9

media_selector

A jQuery and Sammy.js based mini-application for choosing from a list of providers' media assets (images, audio, video, etc.). Used OpenSearch and oEmbed.
JavaScript
3
star
10

image_selector_tinymce_plugin

Using media_selector as the basis of a tinymce plugin for choosing from an existing image from a specified provider or uploading a new image to the provider and returning HTML for image to TinyMCE editor instance.
JavaScript
3
star
11

validates_as_sanitized_html

If you have a model that has an attribute that is user submitted HTML, such as comment, etc. this is a useful plugin for warning the user that they have submitted insecure HTML code, such as form elements, or javascript.
Ruby
3
star
12

trollied

A slightly different take on a Rails shopping cart engine.
Ruby
2
star
13

http_url_validation_improved

A variant of HTTP URL Validation is a Rails plugin that allows you to validate a URL entered in a form. It validates if the URL exists by hitting it with a HEAD request (and the improvements include retrying with other variants until it fails decisively).
Ruby
2
star
14

kete_browserid

An add-on for Kete that replaces normal login and registration with a browserid based login.
Ruby
1
star
15

kete_gets_trollied

A Kete add-on that uses the Trollied gem to deliver ordering of items from Kete.
Ruby
1
star
16

kete_translatable_content

An add-on to the Kete application to provide content translations. Relies on the mongo_translatable gem.
Ruby
1
star
17

tiny_mce_plugin_imageselector

A wrapper gem for installing https://github.com/kete/image_selector_tinymce_plugin so that the tinymce gem can use it.
Ruby
1
star
18

acts_as_zoom

A plugin to allow searching and populating of ZOOM Z39.50 servers.
Ruby
1
star
19

better_send_file

A project to provide a more efficient send_file method for Ruby on Railsā€™ ActionController by sending files directly via reverse proxy servers. Currently only supports Nginx.
Ruby
1
star