Module: TinyMCE::Helpers
- Defined in:
- lib/tiny_mce/helpers.rb
Overview
The helper module we include into ActionController::Base
Defined Under Namespace
Classes: TinyMCEInvalidOption, TinyMCEInvalidOptionType
Instance Method Summary collapse
-
#include_tiny_mce_if_needed(options = {}, raw_options = '') ⇒ Object
Form a JS include tag for the TinyMCE JS src, and form the raw JS and wrap in in a <script> tag for inclusion in the <head> for inclusion in the <head> (only if tiny mce is actually being used).
-
#include_tiny_mce_js ⇒ Object
Form a JS include tag for the TinyMCE JS src for inclusion in the <head>.
-
#include_tiny_mce_js_if_needed ⇒ Object
Form a JS include tag for the TinyMCE JS src for inclusion in the <head> (only if tiny mce is actually being used).
-
#raw_tiny_mce_init(options = {}, raw_options = '') ⇒ Object
Parse @tiny_mce_options and @raw_tiny_mce_options to create a raw JS string used by TinyMCE.
-
#tiny_mce_init(options = {}, raw_options = '') ⇒ Object
Form the raw JS and wrap in in a <script> tag for inclusion in the <head>.
-
#tiny_mce_init_if_needed(options = {}, raw_options = '') ⇒ Object
Form the raw JS and wrap in in a <script> tag for inclusion in the <head> (only if tiny mce is actually being used).
-
#using_tiny_mce? ⇒ Boolean
Has uses_tiny_mce method been declared in the controller for this page?.
Instance Method Details
#include_tiny_mce_if_needed(options = {}, raw_options = '') ⇒ Object
Form a JS include tag for the TinyMCE JS src, and form the raw JS and wrap in in a <script> tag for inclusion in the <head> for inclusion in the <head> (only if tiny mce is actually being used)
85 86 87 88 89 |
# File 'lib/tiny_mce/helpers.rb', line 85 def include_tiny_mce_if_needed( = {}, = '') if using_tiny_mce? include_tiny_mce_js + tiny_mce_init(, ) end end |
#include_tiny_mce_js ⇒ Object
Form a JS include tag for the TinyMCE JS src for inclusion in the <head>
73 74 75 |
# File 'lib/tiny_mce/helpers.rb', line 73 def include_tiny_mce_js javascript_include_tag (Rails.env.development? ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce") end |
#include_tiny_mce_js_if_needed ⇒ Object
Form a JS include tag for the TinyMCE JS src for inclusion in the <head> (only if tiny mce is actually being used)
78 79 80 |
# File 'lib/tiny_mce/helpers.rb', line 78 def include_tiny_mce_js_if_needed include_tiny_mce_js if using_tiny_mce? end |
#raw_tiny_mce_init(options = {}, raw_options = '') ⇒ Object
Parse @tiny_mce_options and @raw_tiny_mce_options to create a raw JS string used by TinyMCE. Returns errors if the option or options type is invalid
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tiny_mce/helpers.rb', line 15 def raw_tiny_mce_init( = {}, = '') # first we set some defaults, then we merge in the controller level options # and finally merge in the view level options (to give presidence) ||= {} = { 'mode' => 'textareas', 'editor_selector' => 'mceEditor', 'theme' => 'simple', 'language' => (defined?(I18n) ? I18n.locale : :en) } = .merge(.stringify_keys).merge(.stringify_keys) = + unless .nil? unless ['plugins'].nil? raise TinyMCEInvalidOptionType.new("Invalid value of type #{options['plugins'].class} passed for TinyMCE option plugins") unless ['plugins'].kind_of?(Array) # Append the plugins we have enabled for this field to the OptionsValidator TinyMCE::OptionValidator.plugins += ['plugins'] end tinymce_js = "tinyMCE.init({\n" .sort.each_with_index do |values, index| key, value = values[0], values[1] raise TinyMCEInvalidOption.new("Invalid option #{key} passed to tinymce") unless TinyMCE::OptionValidator.valid?(key) tinymce_js += "#{key} : " case value when String, Symbol, Fixnum tinymce_js += "'#{value.to_s}'" when Array tinymce_js += '"' + value.join(',') + '"' when TrueClass tinymce_js += 'true' when FalseClass tinymce_js += 'false' else raise TinyMCEInvalidOptionType.new("Invalid value of type #{value.class} passed for TinyMCE option #{key}") end if (index < .size - 1) # there are more options in this array tinymce_js += ",\n" else # no more options in this array. Finish it by adding the addition JS tinymce_js += ",\n#{raw_options}" unless .blank? tinymce_js += "\n" end end tinymce_js += "\n});" end |
#tiny_mce_init(options = {}, raw_options = '') ⇒ Object
Form the raw JS and wrap in in a <script> tag for inclusion in the <head>
63 64 65 |
# File 'lib/tiny_mce/helpers.rb', line 63 def tiny_mce_init( = {}, = '') javascript_tag raw_tiny_mce_init(, ) end |
#tiny_mce_init_if_needed(options = {}, raw_options = '') ⇒ Object
Form the raw JS and wrap in in a <script> tag for inclusion in the <head> (only if tiny mce is actually being used)
68 69 70 |
# File 'lib/tiny_mce/helpers.rb', line 68 def tiny_mce_init_if_needed( = {}, = '') tiny_mce_init(, ) if using_tiny_mce? end |
#using_tiny_mce? ⇒ Boolean
Has uses_tiny_mce method been declared in the controller for this page?
9 10 11 |
# File 'lib/tiny_mce/helpers.rb', line 9 def using_tiny_mce? !@uses_tiny_mce.blank? end |