Module: TinyMCE::Helpers

Defined in:
lib/tiny_mce/helpers.rb

Overview

The helper module we include into ActionController::Base

Instance Method Summary collapse

Instance Method Details

#include_tiny_mce_if_needed(options = {}, raw_options = nil) ⇒ 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)



49
50
51
52
53
# File 'lib/tiny_mce/helpers.rb', line 49

def include_tiny_mce_if_needed(options = {}, raw_options = nil)
  if using_tiny_mce?
    include_tiny_mce_js + tiny_mce_init(options, raw_options)
  end
end

#include_tiny_mce_jsObject

Form a JS include tag for the TinyMCE JS src for inclusion in the <head>



37
38
39
# File 'lib/tiny_mce/helpers.rb', line 37

def include_tiny_mce_js
  javascript_include_tag (Rails.env.to_s == 'development' ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce")
end

#include_tiny_mce_js_if_neededObject

Form a JS include tag for the TinyMCE JS src for inclusion in the <head> (only if tiny mce is actually being used)



42
43
44
# File 'lib/tiny_mce/helpers.rb', line 42

def include_tiny_mce_js_if_needed
  include_tiny_mce_js if using_tiny_mce?
end

#raw_tiny_mce_init(options = {}, raw_options = nil) ⇒ 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



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tiny_mce/helpers.rb', line 12

def raw_tiny_mce_init(options = {}, raw_options = nil)
  tinymce_js = ""

  @tiny_mce_configurations ||= [Configuration.new]
  @tiny_mce_configurations.each do |configuration|
    configuration.add_options(options, raw_options)
    tinymce_js += "tinyMCE.init("
    tinymce_js += configuration.to_json
    tinymce_js += ");"
  end

  tinymce_js
end

#tiny_mce_init(options = {}, raw_options = nil) ⇒ Object

Form the raw JS and wrap in in a <script> tag for inclusion in the <head>



27
28
29
# File 'lib/tiny_mce/helpers.rb', line 27

def tiny_mce_init(options = {}, raw_options = nil)
  javascript_tag raw_tiny_mce_init(options, raw_options)
end

#tiny_mce_init_if_needed(options = {}, raw_options = nil) ⇒ 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)



32
33
34
# File 'lib/tiny_mce/helpers.rb', line 32

def tiny_mce_init_if_needed(options = {}, raw_options = nil)
  tiny_mce_init(options, raw_options) if using_tiny_mce?
end

#using_tiny_mce?Boolean

Has uses_tiny_mce method been declared in the controller for this page?

Returns:

  • (Boolean)


6
7
8
# File 'lib/tiny_mce/helpers.rb', line 6

def using_tiny_mce?
  !@uses_tiny_mce.blank?
end