class TinyMCE::Rails::Configuration

Constants

COMMA
FUNCTION_REGEX
OPTION_SEPARATORS
OPTION_TRANSFORMERS
RELATIVE_PATH_REGEX
SEMICOLON
SPACE

Attributes

options[R]

Public Class Methods

defaults() click to toggle source
# File lib/tinymce/rails/configuration.rb, line 11
def self.defaults
  {
    "selector"     => "textarea.tinymce",
    "cache_suffix" => "?v=#{VERSION}"
  }
end
new(options) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 63
def initialize(options)
  @options = options
end
new_with_defaults(options={}) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 67
def self.new_with_defaults(options={})
  config = new(defaults)
  config = config.merge(options) if options
  config
end

Public Instance Methods

merge(options) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 88
def merge(options)
  self.class.new(self.options.merge(options))
end
options_for_tinymce() click to toggle source

Converts options into a TinyMCE-friendly format.

1. Joins array values using OPTION_SEPARATORS
2. Converts JavaScript function() strings to Function objects
3. Applies transformations from OPTION_TRANSFORMERS
# File lib/tinymce/rails/configuration.rb, line 84
def options_for_tinymce
  preprocess_options(options)
end
to_javascript() click to toggle source

Converts options into a String representing a JavaScript object that can be passed directly to tinyMCE.init

# File lib/tinymce/rails/configuration.rb, line 75
def to_javascript
  options_to_javascript(options_for_tinymce)
end

Private Instance Methods

array_option?(key, value) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 93
def array_option?(key, value)
  value.is_a?(Array) && OPTION_SEPARATORS[key]
end
function_option?(value) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 97
def function_option?(value)
  FUNCTION_REGEX =~ value.to_s
end
options_to_javascript(options, indent="") click to toggle source
# File lib/tinymce/rails/configuration.rb, line 129
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
preprocess_option(key, value) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 111
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
preprocess_options(options) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 101
def preprocess_options(options)
  result = {}

  options.each do |key, value|
    result[key] = preprocess_option(key, value)
  end

  result
end