lib/tiny_mce.rb in krasivotokak-tiny_mce-0.0.1 vs lib/tiny_mce.rb in krasivotokak-tiny_mce-0.0.2

- old
+ new

@@ -1,40 +1,19 @@ -# The base module we include into ActionController::Base module TinyMCE +end - # When this module is included, extend it with the available class methods - def self.included(base) - base.extend(ClassMethods) - end +# Require all the necessary files to run TinyMCE +require 'tiny_mce/controller.rb' +require 'tiny_mce/options_validator' +require 'tiny_mce/spellchecker' +require 'tiny_mce/helpers' - module ClassMethods +# Load up the available configuration options (we do it here because +# the result doesn't, so we don't want to load it per request) +TinyMCE::OptionValidator.load - # 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 = {}) - tiny_mce_options = options.delete(:options) || {} - raw_tiny_mce_options = options.delete(:raw_options) || '' +# Include the TinyMCE methods and TinyMCE Helpers into ActionController::Base - # 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 !tiny_mce_options[:plugins].blank? && tiny_mce_options[:plugins].include?('spellchecker') - tiny_mce_options.reverse_merge!(:spellchecker_rpc_url => "/" + self.controller_name + "/spellchecker") - self.class_eval do - include TinyMCE::SpellChecker - end - end - - # Set instance vars in the current class - proc = Proc.new do |c| - c.instance_variable_set(:@tiny_mce_options, tiny_mce_options) - c.instance_variable_set(:@raw_tiny_mce_options, raw_tiny_mce_options) - 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) - end - - end - +if defined?(Rails) && defined?(ActionController) + ActionController::Base.send(:include, TinyMCE::Controller) + ActionController::Base.send(:helper, TinyMCEHelpers) end