Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow to use use_tiny_mce from before_filters #9

Closed
wants to merge 1 commit into from

1 participant

@franciscoj

Hi!

I've done some modifications to TinyMCE::Base so that you can call use_tiny_mce from a before filter in addition to the current method. This allows you to do things like that.

class PhotosController < ApplicationController
  before_filter :load_resources
  before_filter :set_tiny_mce

  def index
    respond_to do |format|
      format.html
      format.js
    end
  end

  protected

  def load_resources
    @article = Article.find(params[:article_id]
    @photos = @article.photos
  end

  def set_tiny_mce
    use_tiny_mce :only => [:new, :edit], :options => {
      :external_images_list_url => photos_url(@article)
    }
  end
end

I hope you find it usefult. Thanks a lot for the plugin!!

@franciscoj franciscoj closed this
@franciscoj

Closing since 2 years old :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 19, 2011
  1. Allow to use use_tiny_mce from before_filters

    Francisco J authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 14 deletions.
  1. +17 −14 lib/tiny_mce/base.rb
View
31 lib/tiny_mce/base.rb
@@ -3,24 +3,32 @@ module TinyMCE
module Base
# When this module is included, extend it with the available class methods
def self.included(base)
- base.extend(ClassMethods)
+ base.extend ClassMethods
+ base.send :include, InstanceMethods
end
module ClassMethods
+ def uses_tiny_mce(options = {})
+ before_filter(options) do |controller|
+ controller.send(:uses_tiny_mce, options)
+ end
+ end
+ end
+
+ module InstanceMethods
# The controller declaration to enable tiny_mce on certain actions.
# Takes options hash, raw_options string, and any normal params you
# can send to a before_filter (only, except etc)
def uses_tiny_mce(options = {})
configuration = TinyMCE::Configuration.new(options.delete(:options), options.delete(:raw_options))
-
-
+
# Include an option to load the main tiny_mce.js file if the app appears
# to be using jquery. (And use uncompressed script in development)
if configuration.uses_jquery?
configuration.reverse_add_options( {:script_url => (Rails.env.to_s == 'development' ? "/javascripts/tiny_mce/tiny_mce_src.js" : "/javascripts/tiny_mce/tiny_mce.js")} )
end
-
-
+
+
# If the tiny_mce plugins includes the spellchecker, then form a spellchecking path,
# add it to the tiny_mce_options, and include the SpellChecking module
if configuration.plugins.include?('spellchecker')
@@ -29,15 +37,10 @@ def uses_tiny_mce(options = {})
end
# Set instance vars in the current class
- proc = Proc.new do |c|
- configurations = c.instance_variable_get(:@tiny_mce_configurations) || []
- configurations << configuration
- c.instance_variable_set(:@tiny_mce_configurations, configurations)
- c.instance_variable_set(:@uses_tiny_mce, true)
- end
-
- # Run the above proc before each page load this method is declared in
- before_filter(proc, options)
+ configurations = @tiny_mce_configurations || []
+ configurations << configuration
+ @tiny_mce_configurations = configurations
+ @uses_tiny_mce = true
end
end
end
Something went wrong with that request. Please try again.