Module: TinyMCE::OptionValidator

Included in:
Base
Defined in:
lib/tiny_mce/option_validator.rb

Overview

We use this to validate whether options passed in by the users are valid tiny mce configuration settings. Also loads which options are valid, and provides an plugins attribute to allow more configuration options dynamicly

Class Method Summary collapse

Class Method Details

.loadObject

Parse the options file and load it into an array (this method is called when tiny_mce is initialized - see init.rb)



14
15
16
17
# File 'lib/tiny_mce/option_validator.rb', line 14

def load
  @@valid_options = File.open(File.dirname(__FILE__) + '/valid_tinymce_options.yml') { |f| YAML.load(f.read) }
  self.plugins = Array.new
end

.optionsObject

If we need to get the array of valid options, we can call this method



30
31
32
# File 'lib/tiny_mce/option_validator.rb', line 30

def options
  @@valid_options
end

.valid?(option) ⇒ Boolean

Does the check to see if the option is valid. It checks the valid_options array (see above), checks if the start of the option name is in the plugin list or checks if it’s an theme_advanced_container setting

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/tiny_mce/option_validator.rb', line 22

def valid?(option)
  option = option.to_s
  @@valid_options.include?(option) ||
    (plugins && plugins.include?(option.split('_')[0])) ||
    option =~ /^theme_advanced_container_\w+$/
end