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)


67
68
69
70
71
# File 'lib/tiny_mce/helpers.rb', line 67

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> Attempt to use the jQuery plugin if the application appears to be using jquery


51
52
53
54
55
56
57
# File 'lib/tiny_mce/helpers.rb', line 51

def include_tiny_mce_js
  if uses_jquery?
    javascript_include_tag "tiny_mce/jquery.tinymce"
  else
    javascript_include_tag(Rails.env.to_s == 'development' ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce")
  end
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)


60
61
62
# File 'lib/tiny_mce/helpers.rb', line 60

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


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tiny_mce/helpers.rb', line 16

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

  tiny_mce_configurations.each do |configuration|
    configuration.add_options(options, raw_options)
    
    if uses_jquery?
      #TODO: Use dynamic editor_selector from configuration
      tinymce_js += "$(function(){ $('textarea.mceEditor').tinymce("
      tinymce_js += configuration.to_json
      tinymce_js += ");"
      tinymce_js += "});"
    else
      tinymce_js += "tinyMCE.init("
      tinymce_js += configuration.to_json
      tinymce_js += ");"
    end
    
  end

  tinymce_js
end

#tiny_mce_configurationsObject


10
11
12
# File 'lib/tiny_mce/helpers.rb', line 10

def tiny_mce_configurations
  @tiny_mce_configurations ||= [Configuration.new]
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>


40
41
42
# File 'lib/tiny_mce/helpers.rb', line 40

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)


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

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