Class: TinyMCE::Rails::Configuration
- Inherits:
-
Object
- Object
- TinyMCE::Rails::Configuration
- Defined in:
- lib/tinymce/rails/configuration.rb
Defined Under Namespace
Classes: Function
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
- .load(filename) ⇒ Object
Instance Method Summary collapse
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #load(filename) ⇒ Object
- #merge(options) ⇒ Object
- #options_for_tinymce ⇒ Object
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 |
# File 'lib/tinymce/rails/configuration.rb', line 19 def initialize() = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/tinymce/rails/configuration.rb', line 17 def end |
Class Method Details
.assets ⇒ Object
71 72 73 |
# File 'lib/tinymce/rails/configuration.rb', line 71 def self.assets Rails.application.assets end |
.available_languages ⇒ Object
Searches asset paths for TinyMCE language files.
61 62 63 64 65 66 67 68 69 |
# File 'lib/tinymce/rails/configuration.rb', line 61 def self.available_languages assets.paths.map { |path| files = assets.entries(File.join(path, "tinymce/langs")) files.map { |file| asset = assets.attributes_for(File.join(path, file)) asset.logical_path.sub(/\.js$/, "") } }.flatten.uniq end |
.default_language ⇒ Object
Default language falls back to English if current locale is not available.
56 57 58 |
# File 'lib/tinymce/rails/configuration.rb', line 56 def self.default_language available_languages.include?(I18n.locale.to_s) ? I18n.locale.to_s : "en" end |
.defaults ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/tinymce/rails/configuration.rb', line 9 def self.defaults { "mode" => "specific_textareas", "editor_selector" => "tinymce", "theme" => "advanced" } end |
.load(filename) ⇒ Object
49 50 51 52 53 |
# File 'lib/tinymce/rails/configuration.rb', line 49 def self.load(filename) config = new(defaults) config.load(filename) if File.exists?(filename) config end |
Instance Method Details
#load(filename) ⇒ Object
45 46 47 |
# File 'lib/tinymce/rails/configuration.rb', line 45 def load(filename) .merge!(YAML::load(ERB.new(IO.read(filename)).result)) end |
#merge(options) ⇒ Object
41 42 43 |
# File 'lib/tinymce/rails/configuration.rb', line 41 def merge() self.class.new(self..merge()) end |
#options_for_tinymce ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tinymce/rails/configuration.rb', line 23 def result = {} .each do |key, value| if value.is_a?(Array) && value.all? { |v| v.is_a?(String) } result[key] = value.join(",") elsif value.to_s.starts_with?("function(") result[key] = Function.new(value) else result[key] = value end end result["language"] ||= self.class.default_language result end |