class TinyMCE::Rails::Configuration
def self.defaults
def self.defaults { "selector" => "textarea.tinymce" } end
def self.new_with_defaults(options={})
def self.new_with_defaults(options={}) config = new(defaults) config = config.merge(options) if options config end
def array_option?(key, value)
def array_option?(key, value) value.is_a?(Array) && OPTION_SEPARATORS[key] end
def function_option?(value)
def function_option?(value) FUNCTION_REGEX =~ value.to_s end
def initialize(options)
def initialize(options) @options = options end
def merge(options)
def merge(options) self.class.new(self.options.merge(options)) end
def options_for_tinymce
2. Converts JavaScript function() strings to Function objects
1. Joins array values using OPTION_SEPARATORS
Converts options into a TinyMCE-friendly format.
def options_for_tinymce preprocess_options(options) end
def options_to_javascript(options, indent="")
def options_to_javascript(options, indent="") next_indent = indent + " " pairs = options.inject([]) do |result, (k, v)| if v.is_a?(Hash) v = options_to_javascript(v, next_indent) elsif v.respond_to?(:to_javascript) v = v.to_javascript elsif v.respond_to?(:to_json) v = v.to_json end result << [k, v].join(": ") end "{\n#{next_indent}#{pairs.join(",\n#{next_indent}")}\n#{indent}}" end
def preprocess_option(key, value)
def preprocess_option(key, value) result = value if result.is_a?(Hash) result = preprocess_options(value) elsif array_option?(key, value) result = value.join(OPTION_SEPARATORS[key]) elsif function_option?(value) result = Function.new(value) end if transformer = OPTION_TRANSFORMERS[key] result = transformer.call(result) end result end
def preprocess_options(options)
def preprocess_options(options) result = {} options.each do |key, value| result[key] = preprocess_option(key, value) end result end
def to_javascript
Converts options into a String representing a JavaScript object
def to_javascript options_to_javascript(options_for_tinymce) end