Module: TinyMCEHelper

Defined in:
lib/tiny_mce_helper.rb

Defined Under Namespace

Classes: InvalidOption

Instance Method Summary collapse

Instance Method Details

#javascript_include_tiny_mceObject



41
42
43
# File 'lib/tiny_mce_helper.rb', line 41

def javascript_include_tiny_mce
  javascript_include_tag RAILS_ENV == 'development' ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce"
end

#javascript_include_tiny_mce_if_usedObject



45
46
47
# File 'lib/tiny_mce_helper.rb', line 45

def javascript_include_tiny_mce_if_used
  javascript_include_tiny_mce if @uses_tiny_mce
end

#tiny_mce_init(options = @tiny_mce_options) ⇒ Object Also known as: tiny_mce



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tiny_mce_helper.rb', line 9

def tiny_mce_init(options = @tiny_mce_options)
  options ||= {}
  default_options = {:mode => 'textareas',
                     :theme => 'simple'}
  options = default_options.merge(options)
  TinyMCE::OptionValidator.plugins = options[:plugins]
  tinymce_js = "tinyMCE.init({\n"
  i = 0    
  options.stringify_keys.sort.each do |pair|
    key, value = pair[0], pair[1]
    raise InvalidOption.new("Invalid option #{key} passed to tinymce") unless TinyMCE::OptionValidator.valid?(key)
    tinymce_js += "#{key} : "
    case value
    when String, Symbol, Fixnum
      tinymce_js += "'#{value}'"
    when Array
      tinymce_js += '"' + value.join(',') + '"'
    when TrueClass
      tinymce_js += 'true'
    when FalseClass
      tinymce_js += 'false'
    else
      raise InvalidOption.new("Invalid value of type #{value.class} passed for TinyMCE option #{key}")
    end
    (i < options.size - 1) ? tinymce_js += ",\n" : "\n"
    i += 1
  end
  tinymce_js += "\n});"
  javascript_tag tinymce_js
end

#using_tiny_mce?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/tiny_mce_helper.rb', line 5

def using_tiny_mce?
  !@uses_tiny_mce.nil?
end