Giter Club home page Giter Club logo

tinymce-rails's Introduction

Rails Integration for TinyMCE

The tinymce-rails gem integrates the TinyMCE editor with the Rails asset pipeline.

This gem is compatible with Rails 5.0 and higher.

This is the branch for TinyMCE 7.
Please see alternate branches for TinyMCE 6, TinyMCE 5, TinyMCE 4 & TinyMCE 3.5.x.

Important

Please note that as of version 7, TinyMCE (and therefore this project) is now licensed under the GPL.

Build Status

Instructions

1. Add tinymce-rails to your Gemfile

gem 'tinymce-rails'

Be sure to add to the global group, not the assets group. Then run bundle install.

2. Create a config/tinymce.yml file with your global configuration options:

toolbar:
  - styleselect | bold italic | undo redo
  - image | link
plugins:
  - image
  - link

The Rails server no longer needs to be restarted when this file is updated in development mode.

To define multiple configuration sets, follow this syntax (a default configuration must be specified):

default: &default
  plugins:
    - image
    - link

alternate:
  <<: *default
  toolbar: styleselect | bold italic | undo redo | table
  plugins:
    - table

See the TinyMCE 7 Documentation for a full list of configuration options.

3. Include the TinyMCE assets

Use one of the following options to include TinyMCE assets.

(1) Add to your application.js:

//= require tinymce

or (2) add the script tag to your layout using the tinymce_assets helper:

<%= tinymce_assets %>
#=> <script type="text/javascript" src="/assets/tinymce.js">

4. Initialize TinyMCE

For each textarea that you want to use with TinyMCE, add the "tinymce" class and ensure it has a unique ID:

<%= text_area_tag :content, "", class: "tinymce", rows: 40, cols: 120 %>

or if you are using Rails' form builders:

<%= f.text_area :content, class: "tinymce", rows: 40, cols: 120 %>

Then invoke the tinymce helper to initialize TinyMCE:

<%= tinymce %>

Custom options can be passed to tinymce to override the global options specified in config/tinymce.yml:

<%= tinymce theme: "simple", language: "de", plugins: ["wordcount", "paste"] %>

Alternate configurations defined in 'config/tinymce.yml' can be used with:

<%= tinymce :alternate %>

Language Packs

See the tinymce-rails-langs gem for additional language packs for TinyMCE.

Manual Initialization

Using the tinymce helper and global configuration file is entirely optional. The tinymce.init JS function can be invoked manually if desired.

<%= text_area_tag :editor, "", rows: 40, cols: 120 %>

<script type="text/javascript">
  tinymce.init({
    selector: 'textarea.editor'
  });
</script>

Asset Compilation

Since TinyMCE loads most of its files dynamically, some workarounds are required to ensure that the TinyMCE asset files are accessible using non-digested filenames.

As of tinymce-rails 3.5.11, 4.1.10 and 4.2.1, two alternative asset installation methods are available, which can be changed by setting config.tinymce.install within your config/application.rb file. These methods are called when you run rake asset:precompile (via Rake::Task#enhance) after the regular application assets are compiled.

The default method (as of 4.5.2), compile, adds the TinyMCE paths to the Sprockets precompilation paths and then creates symlinks from the non-digested filenames to their digested versions.

config.tinymce.install = :compile

If you experience issues with the compile method, you may wish to use the copy method instead, which copies the TinyMCE assets directly into public/assets and appends the file information into the asset manifest. The copy_no_preserve method is also available of you do not wish to or cannot preserve file modes on your filesystem.

config.tinymce.install = :copy

If you are including TinyMCE via application.js or using the tinymce_assets helper, you do not need to manually add the scripts to the Sprockets precompile paths.

Custom Plugins & Skins

To use custom plugins or skins, simply add the files to your asset load path so that they are locatable at a path beneath tinymce/plugins/ or tinymce/skins/.

For example, a plugin called mycustomplugin could have its main JS file at app/assets/javascripts/tinymce/plugins/mycustomplugin/plugin.js.

You should also ensure that your custom paths are added to the asset precompile paths.

Using tinymce-rails as an Engine Dependency

Ensure that you explicitly require tinymce-rails within your engine file. Including tinymce-rails as a dependency in your gemspec is not enough.

Updating

When new versions of TinyMCE are released, simply update the tinymce-rails gem to the latest version. There is no need to run any extra rake tasks (apart from rake assets:precompile).

tinymce-rails's People

Contributors

botimer avatar domon avatar ferdinandrosario avatar frederikspang avatar frenkel avatar gombally avatar graaff avatar heaven avatar jitnaught avatar jmeridth avatar juliendargelos avatar madding avatar musaffa avatar nexneo avatar panissupraomnia avatar pmatsinopoulos avatar rgc avatar spohlenz avatar sprestel avatar tagliala avatar tscolari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinymce-rails's Issues

using with form partial

I am having a problem using with a form partial. When I try to save the comment it throws a validation error (validates_presence_of :text). The text will save from the original form but not from the partial.

 <div id="create-comment">
 <%= render 'comments/form', :order_id => params[:order_id] %>
 </div>

here is the form

 <%= simple_form_for @comment, :html => { :class => 'form-horizontal' } do |f| %>
 <fieldset>
 <legend>Add Comment</legend>

 <%= f.input :text, :input_html => {:class => 'tinymce comment span6', :rows => '10', :cols => '40' } %>
  <%= tinymce %>
 <div class="form-actions">
  <%= f.submit nil, :class => 'btn btn-primary' %>
  <%= link_to 'Cancel', root_path, :class => 'btn' %>
</div>
 </fieldset>
 <% end %>

Thanks for the help,

Option for using the helper without script tags

The helper is very handy. But we load our js assets at the bottom of the page, so the helper doesn't work for us as tinymce is not loaded yet.

I would like to do something like this:

<script type="text/javascript">
    $(function(){
        <%= tinymce :wrap => false %>
    });
</script>

Where I have an option to tell the helper not to output the script tags.

plugins not synced when using a cdn

so I setup asset_sync to upload my assets to be served from cloudfront. However, none of the js files for plugins were copied over, causing the whole thing to break. The template files for the plugins copied over just fine. Any ideas?

Use engine instead of railtie & remove assets precompile tasks

I noticed that your gem copies the asstes to the applications public folder. I think it's not the way the rails 3.1 asset pipeline is meant to be used.

Looking at your code I think when using a rails engine instead of a railtie the whole assets handling code in the initializers and assets.rake can be removed.

At least it works great in my swfobject-rails gem: https://github.com/gucki/swfobject-rails/blob/master/lib/swfobject/rails/engine.rb

What do you think?

install issue - TinyMCE JS files not installed?

I'm probably missing something, but followed the directions in the Readme to add tinymce-rails to my gemfile, then run bundle update. So, now the gem is installed, but it doesn't appear that any of the tinymce JS appears anywhere in my asset pipeline.

Is there a require, an extra path, or some extra installation I'm supposed to do beyond what's listed in the Readme? Am I supposed to separately install the TinyMCE JS from TinyMCE? If so ... does it matter what version I grab?

JS files not in Rails.application.config.assets.paths

I'm using tinymce-rails 3.4.7 in a Rails 3.1.3 application with Spree 0.70.3. The spree-editor plugin requires tinymce-rails, and it is installed. However, the include line:

//= require tinymce-jquery

...in the spree-editor.js file generates an error:

Error compiling asset admin/all.js:
Sprockets::FileNotFound: couldn't find file 'tinymce-jquery'

When I query Sprockets' include path, I find that none of the tinymce-rails paths are in Rails.application.config.assets.paths. Is this intentional? Where in the stack should that have appeared in the path?

URLs within javascript do not respect config.action_controller.asset_host

I'm currently using tinymce-rails on a heroku deployed application that leverages config.action_controller.asset_host and asset_sync to serve static assets via cloudfront rather than from my app. It looks like the tinymce assets are still being served from heroku and the urls within the javascript are not being properly rewritten to respect my config.action_controller.asset_host setting.

Default plugins and translations are not precompiled

I'm migrating to rails 3.1.0 and decided to use tinymce-rails 3.4.6. It works fine in "development" environment, but it is not usable in "production" environment, however. I have
//= require tinymce-jquery
in my application.js. rake assets:precompile "successfully" executes, but when I start server in production mode, it complains that it can't find tinymce/langs/en.js?3.4.6, tinymce/themes/advanced/editor_template.js?3.4.6, tinymce/plugins/autosave/editor_plugin.js?3.4.6, etc. I can see gzipped tinymce-rails.js and some other related files in public/assets directory, but there is no gzipped version of those editor_plugin.js files. Is there any way to fix this?
Thanks

Assets pre-compile error with Rails 3.2

Hi,

I am using gem version 3.4.8, and having an issue when i use the command rake assets:precompile to compile the assets.

Every time it aborted at

mkdir -p /path_to_app/public/assets
cp -r /home/nazar2/.rvm/gems/[email protected]/bundler/gems/tinymce-rails-f7dd26ee75b5/assets/precompiled/tinymce /path_to_app/public/assets
/path_to_app/config/Gemfile not found
rake aborted!
Command failed with status (10): [/home/nazar2/.rvm/rubies/ruby-1.9.2-p290/b...]
/home/nazar2/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/home/nazar2/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
/home/nazar2/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
/home/nazar2/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
/home/nazar2/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'

I also tried the latest code by direct github url but still facing the same issue. Can you suggest any solution for it?

Popup Dialog for Link is broken with asset_host

I have my static assets on a s3, that include assets/tinymce. Unfortunately the dialog for add link will also be there and that caused the dialog to be blank page(assets/tinymce/themes/advanced/link.htm)

Dynamic Content

First of all, great gem! Works like a charm.

I was wondering if you guys have a good way of overriding the content_css, the inlinepopups skin, and any of the other skins while using this gem and rails 3.1

Seems like a real pain as you don't know what the css file path is going to be, and since the code is precompiled in the gem, i can't add skins etc, nor will I know where they will be.

Any ideas on the best way to do this?

Easy migration from tiny_mce gem?

Hello!

-1.This is not bug, this is just a question.
-2.It would be great have a easy way to migrate from tiny_mce gem on your gem. Are you planning to add config.yml file to configure editor features that exists at tiny_mce gem & helpers that exists at tiny_mce gem? These are 2 feature that prevent me from migration.

Sincerely yours,
Artem Rufanov.

P.S.
Have a good day!

Popup dialogues not working when asset_host is set.

When I click on a popup dialogue (e.g. html editor, link editor etc), it brings up a blank dialogue when I have set the asset_host to something different.

error: "Unsafe JavaScript attempt to access frame with URL"
rails: 3.2.2
tinymce-rails: 3.4.9
browser: chrome
os: macos

Owen

Custom skins/plugins?

Thanks for this gem, it makes it really easy to get a basic editor in place but is it possible to use custom skins and plugins using the Rails 3.1 asset pipeline?

production site being served from sub-directory

Is there a way to make tinymce-rails aware that the app. is being served from a sub-directory on the production server? I notice that it appends 2 additional js files into the page at runtime; langs/en.js and themes/advanced/editor_template.js. In my production setup, the assets directory sits under a sub-directory on my server, however, tinymce-rails doesn't account for this in the url path to the files mentioned above. Am I missing something?

Pop up dialog??

When I have clicked on "insert/edit link" dialog is shown in new blank page with full screen. In original tinymce its like pop up window inserted in the middle in new small and nice formated window. What is wrong??

Precompiled assets in production mode

In development mode, TinyMCE is working great, but in production mode, I seem unable to load precompiled TinyMCE assets. However, the assets are in my public/assets directory as expected. The page with the TinyMCE textareas does not render any textareas.

Detail: Command and logs:

bin/rake assets:precompile
RAILS_ENV=production bin/rails server thin

Started GET "/assets/tinymce/themes/advanced/editor_template.js?3.4.7" for 10.0.2.2 at 2012-01-07 16:09:06 +0000 
Served asset /tinymce/themes/advanced/editor_template.js - 404 Not Found (4ms)
ActionController::RoutingError (No route matches [GET] "/assets/tinymce/themes/advanced/editor_template.js"):

ls -l public/assets/tinymce/themes/advanced/editor_template.js 
-rw-r--r-- 1 dkennedy dkennedy 25166 2012-01-07 16:06 public/assets/tinymce/themes/advanced/editor_template.js

I am unclear if this is a routing issue on my part, but I don't see anything in the documentation about needing to tweak config/routes

Integration: as per instructions: Gem installed via bundler, in my app/assets/javascripts/application.js I have

//= require tinymce-jquery

On each page I require a page specific manifest.js which includes several files, including one with the TinyMCE javascript hook customised for my preferred buttons etc; I can see this manifest.js in my public/assets.

Versions: I'm using Rails 3.1.0, and Ruby 1.9.3. I've cleared out all gemsets etc, and have tried building the tinymce-rails Gem directly from GitHub.

Any advice?

Multiple Instance on same page

Hi, Your gem is great in reference to including the tinnyMCE,

I was having an issue with your current version 3.4.8, I want to have multiple tinnyMCE instances on the same page.

I tried it out as:

$('textarea.editor').tinymce({
            theme:'simple'
        });

This makes all textareas with editor available but when i post the form for each editor new text does not posted.

if i use it like

$("textarea.editor").live('focus', function () {
        $(this).tinymce({
            theme:'simple'
        });
    });

Every time i focus on any of the text-area, only the first text-area in the DOM is converted into the editor.

Why is i am facing such a behavior?

error: $("textarea").tinymce is not a function

Hello, Thank you for offer nice gem plugins.
I've got a problem with using it.

I added below in Gemfile.
gem 'tinymce-rails'
And then run bundle install.

Add to my application.js:
//= require tinymce-jquery

<script src="/assets/tinymce/preinit.js?body=1" type="text/javascript"></script> <script src="/assets/tinymce/tiny_mce_jquery.js?body=1" type="text/javascript"></script> <script src="/assets/tinymce/jquery-tinymce.js?body=1" type="text/javascript"></script> <script src="/assets/tinymce-jquery.js?body=1" type="text/javascript"></script>

These script files loaded well.

But when I tried below code to use tinymce, I got the Error message.

$(function() {
$('textarea').tinymce({
theme: 'advanced'
});
});

$("textarea").tinymce is not a function

How could I fix this problem?

Regards.

Localization

I've found lang dirs in vendor/assets/javascripts in your gem. However there are only files for English locale. Is there a special decision and you don't want to add localizations in your gem or just you havn't done it yet (I can help in this case)?

can't Overwrite themes

I want to overwrite themes/advanced/editor_template.js, but when I precompile assets it doesn't compile my editor_template.js but compile gem's editor_template.js.

Issue when running automated testing

The gem seems to work fine but when I run my automated testing (Capybara / RSPEC) I get the following:

  ActionView::Template::Error:
    undefined local variable or method `tinymce_assets' for #<#<Class:0x4ae66dc>:0x49a8310>

Any idea how to fix that?

Multiple File Includes

I just switched to tinymce-rails from the tiny_mce gem after upgrading my app to Rails 3.1. I'm noticing that the gem seems to include 4 separate javascript files in the <head> of the page:

<script src="/assets/tinymce/preinit.js?body=1" type="text/javascript"></script>
<script src="/assets/tinymce/tiny_mce_jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/tinymce/jquery-tinymce.js?body=1" type="text/javascript"></script>
<script src="/assets/tinymce-jquery.js?body=1" type="text/javascript"></script>

Is there any way these could be consolidated into one file? It would be nice to cut down on the number on HTTP requests.

Also, the tinymce-jquery.js file seems to be blank.

Thanks for your work on this!

Some Javascript files missing on Heroku

Hi,

i am using tinymce-rails in one of my heroku apps. When I run it on my local sstem, all things work fine, but when I run it on heroku it throws out following errors:

404 Not Found /assets/tinymce/langs/en.js?3.4.8"

404 Not Found /assets/tinymce/themes/advanced/editor_template.js?3.4.8"

Have I done any mistake. I use Rails 3.2 and have added //= require tinymce-jquery in my application.js

tiny_mce should work with assets_enabled = false

Since the previous tiny_mce plugin is deprecated and this is the recommended one for Rails 3.1 it should work with assets_enabled = false.

Right now starting rails dies with:
/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/whiny_nil.rb:48:in method_missing': undefined methodfingerprinting_enabled=' for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/fingerprintless-assets-1.0/lib/fingerprintless_assets/railtie.rb:19

production precompile

Hi,

when I precompile my assets in production, it only seems to include:

"tinymce/jquery-tinymce.js",
"tinymce/tiny_mce.js",
"tinymce/tiny_mce_jquery.js",
"tinymce/preinit.js",
"tinymce-jquery.js",
"tinymce.js"

while when I precompile in development, it includes all themes and plugins like it should.

Remove link to digestion in read me.

While trying to figure out why access to assets was failing for tiny-mce themes, etc. I thought the lack of digestion may have been the issue. It is not and the link is misleading. I still have not figured out my issue but it was not that.

Set content_css to application css

Is it possible to add a method to be able to include all stylesheets from the application when compiled using the rails 3.1 asset pipeline so that the editor styling is the same as the rest of the website.

As a work around, I have implemented a dirty hack where the content_css init variable is set to the following:

stylesheet_link_tag('application').split("\n").map{|stylesheet| stylesheet.match(/href="([^"]+)"/).to_a[1]}.join(",")

If anyone has any other ideas of a better way of achieving this, that would be great.

Thanks,

Owen

Don't know how to install/use

I followed the instructions by adding the Gem into my Gemfile:

gem "tinymce-rails"

followed by the 'bundle install'

Then when I add <%= tinymce_assets %> into my view, I get

undefined local variable or method `tinymce_assets' for #<#Class:0x4087c08:0x407cb38>

I tried adding

gem "tinymce-rails", :require => "tinymce-rails"

and still the same thing. It seems that my app can't see the file.

Custom Plugin image not reflecting in editor

Hi i made one custom plugin named upload_image and mentioned as below. its gettting complied but not reflected in editor.
how can customize editor like add/remove plugins from editor.

<script type="text/javascript"> $(function() { $('textarea').tinymce({ theme: 'advanced', plugins: 'upload_image' }); }); </script>

New language file

Hi,

how to add new language file with translations?

Thanks,
Marek

Adding different elements like font, fontsize etc

Hi,
Previously I used tinymce. I used to have so many options like font selection, fontsize selection, But now those options are not available in the current GEM.
Could you please help me on what I am missing to get those options.

Under Rails 3.1.1 and config.assets.initialize_on_precompile = false, tinymce assets are not precompile during rake assets:precompile

I believe this is because of this change in 3.1.1:

"rake assets:precompile loads the application but does not initialize it.

To the app developer, this means configuration add in config/initializers/* will not be executed.

Plugins developers need to special case their initializers that are meant to be run in the assets group by adding :group => :assets. [José Valim]"

I attached a simple fix to force the initializer to run in all groups.

using the helper method doesn't seem to work when using jQuery

The helper <%= tinymce %> which generates:

<script>
//<![CDATA[
tinyMCE.init({"mode":"textareas","theme":"advanced","editor_selector":"tinymce","theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left","theme_advanced_statusbar_location":"bottom","theme_advanced_buttons3_add":"tablecontrols,fullscreen","plugins":"table,fullscreen","language":"en"});
//]]>
</script>

returns a 'tinyMCE is not defined' error.

It works fine when I call it directly. ie:

jQuery ->
    $('.tinymce').tinymce({
        theme_advanced_toolbar_location : 'top', 
        theme: 'simple'  
       })

I'm guessing this is a bug?

Rails 3.2 compatibility

Hey mate,

your gem doesn't work with Rails 3.2. Bundling fails because of the dependency on railties ~> 3.1.0.

IMO it's safe to assume that Rails adheres to Semantic Versioning, so I propose you change the dependency to ~> 3.1 instead so the gem is compatible with the whole Rails 3.x branch.

Cheers,

  • C.

Invalid UTF-8 byte sequence (spellchecker/editor_plugin.js)

Hi,

With last master branch i have this issues :

/home/pierre/projects/xxxx/vendor/gems/spree_editor/vendor/assets/javascripts/tinymce/plugins/spellchecker/editor_plugin.js has a invalid UTF-8 byte sequence

Tasks: TOP => assets:precompile:primary

Add possibility to only load certain plugins and languages via config

One should have the possibility to set which plugins and languages to be used.
So that only these gets processed via the asset pipeline.

Please have a look into my fork of the tinymce_hammer plugin, which has this feature, but is not Rails 3.1 ready.

Maybe we could join forces and merge this feature from tinymce_hammer into your gem?
That would be great since you already made all the rails 3.1 stuff I have to do now, just for having this one really nice feature.

Please let me know if I could help you with this.

Regards, Thomas

tinymce-rails breaks assets:precompile rake task

When having tinymce-rails in the Gemfile only application.js and application.css get precompiled by rake assets:precompile. All other assets like images don't get precompiled anymore.

Removingtinymce-rails from the Gemfile makes everything work as it should.

Secure HTML

I suggest that you add an API method to do white list security check before saving the model data coming from tinymce. This will prevent users from posting raw HTML.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.