Class: TinyMCE::Rails::Configuration
- Inherits:
-
Object
- Object
- TinyMCE::Rails::Configuration
- Defined in:
- lib/tinymce/rails/configuration.rb
Defined Under Namespace
Classes: Function
Constant Summary collapse
- COMMA =
",".freeze
- SPACE =
" ".freeze
- SEMICOLON =
";".freeze
- OPTION_SEPARATORS =
{ "plugins" => COMMA, "custom_elements" => COMMA, "entities" => COMMA, "extended_valid_elements" => COMMA, "font_formats" => SEMICOLON, "fontsize_formats" => COMMA, "invalid_elements" => COMMA, "block_formats" => SEMICOLON, "valid_children" => COMMA, "valid_elements" => COMMA, "body_id" => COMMA, "body_class" => COMMA, "content_css" => COMMA, "tabfocus_elements" => COMMA, "table_clone_elements" => SPACE, "paste_word_valid_elements" => COMMA, "paste_webkit_styles" => SPACE, "paste_retain_style_properties" => SPACE, "spellchecker_languages" => COMMA }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .assets ⇒ Object
-
.available_languages ⇒ Object
Searches asset paths for TinyMCE language files.
-
.default_language ⇒ Object
Default language falls back to English if current locale is not available.
- .defaults ⇒ Object
- .new_with_defaults(options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(options) ⇒ Object
- #options_for_tinymce ⇒ Object
- #to_javascript ⇒ Object
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
45 46 47 |
# File 'lib/tinymce/rails/configuration.rb', line 45 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/tinymce/rails/configuration.rb', line 43 def @options end |
Class Method Details
.assets ⇒ Object
119 120 121 |
# File 'lib/tinymce/rails/configuration.rb', line 119 def self.assets Rails.application.assets end |
.available_languages ⇒ Object
Searches asset paths for TinyMCE language files.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tinymce/rails/configuration.rb', line 99 def self.available_languages assets.paths.map { |path| # Find all assets within tinymce/langs entries = assets.entries(File.join(path, "tinymce/langs")) entries.map { |entry| if assets.respond_to?(:attributes_for) assets.attributes_for(File.join(path, entry)) else assets.find_asset(File.join("tinymce/langs", entry)) end }.select { |asset| # Select only JavaScript files asset.logical_path =~ /\.js$/ }.map { |asset| # Strip path and extension asset.logical_path.sub(/^tinymce\/langs\//, "").sub(/\.js$/, "") } }.flatten.uniq end |
.default_language ⇒ Object
Default language falls back to English if current locale is not available.
94 95 96 |
# 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 ⇒ Object
11 12 13 14 15 |
# File 'lib/tinymce/rails/configuration.rb', line 11 def self.defaults { "selector" => "textarea.tinymce" } end |
.new_with_defaults(options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/tinymce/rails/configuration.rb', line 49 def self.new_with_defaults(={}) config = new(defaults) config = config.merge() if config end |
Instance Method Details
#merge(options) ⇒ Object
89 90 91 |
# File 'lib/tinymce/rails/configuration.rb', line 89 def merge() self.class.new(self..merge()) end |
#options_for_tinymce ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tinymce/rails/configuration.rb', line 55 def result = {} .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 ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tinymce/rails/configuration.rb', line 75 def to_javascript pairs = .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 |