class TinyMCE::Rails::Configuration

Constants

COMMA
OPTION_SEPARATORS
SEMICOLON
SPACE

Attributes

options[R]

Public Class Methods

assets() click to toggle source
# File lib/tinymce/rails/configuration.rb, line 109
def self.assets
  Rails.application.assets
end
available_languages() click to toggle source

Searches asset paths for TinyMCE language files.

# File lib/tinymce/rails/configuration.rb, line 99
def self.available_languages
  assets.paths.map { |path|
    files = assets.entries(File.join(path, "tinymce/langs"))
    files.select { |file| file.to_s =~ /\.js/ }.map { |file|
      asset = assets.attributes_for(File.join(path, file))
      asset.logical_path.sub(/\.js$/, "")
    }
  }.flatten.uniq
end
default_language() click to toggle source

Default language falls back to English if current locale is not available.

# File lib/tinymce/rails/configuration.rb, line 94
def self.default_language
  I18n.locale.to_s if available_languages.include?(I18n.locale.to_s)
end
defaults() click to toggle source
# File lib/tinymce/rails/configuration.rb, line 11
def self.defaults
  {
    "selector" => "textarea.tinymce"
  }
end
new(options) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 45
def initialize(options)
  @options = options
end
new_with_defaults(options={}) click to toggle source
# File lib/tinymce/rails/configuration.rb, line 49
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 89
def merge(options)
  self.class.new(self.options.merge(options))
end
options_for_tinymce() click to toggle source
# File lib/tinymce/rails/configuration.rb, line 55
def options_for_tinymce
  result = {}
  
  options.each do |key, value|
    if OPTION_SEPARATORS[key] && value.is_a?(Array)
      result[key] = value.join(OPTION_SEPARATORS[key])
    elsif value.to_s.starts_with?("function(")
      result[key] = Function.new(value)
    else
      result[key] = value
    end
  end
  
  if self.class.default_language
    result["language"] ||= self.class.default_language
  end
  
  result
end
to_javascript() click to toggle source
# File lib/tinymce/rails/configuration.rb, line 75
def to_javascript
  pairs = options_for_tinymce.inject([]) do |result, (k, v)|
    if 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#{pairs.join(",\n")}\n}"
end