tiny_mce 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/init.rb +0 -12
- data/lib/tiny_mce.rb +13 -34
- data/lib/tiny_mce/controller.rb +40 -0
- data/lib/tiny_mce/helpers.rb +91 -0
- data/lib/{options_validator.rb → tiny_mce/options_validator.rb} +0 -0
- data/lib/{spellchecker.rb → tiny_mce/spellchecker.rb} +0 -0
- data/tiny_mce.gemspec +5 -4
- metadata +5 -4
- data/lib/tiny_mce_helpers.rb +0 -91
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/init.rb
CHANGED
@@ -1,13 +1 @@
|
|
1
|
-
# Require all the necessary files to run TinyMCE
|
2
1
|
require 'tiny_mce'
|
3
|
-
require 'options_validator'
|
4
|
-
require 'spellchecker'
|
5
|
-
require 'tiny_mce_helpers'
|
6
|
-
|
7
|
-
# Load up the available configuration options (we do it here because
|
8
|
-
# the result doesn't, so we don't want to load it per request)
|
9
|
-
TinyMCE::OptionValidator.load
|
10
|
-
|
11
|
-
# Include the TinyMCE methods and TinyMCE Helpers into ActionController::Base
|
12
|
-
ActionController::Base.send(:include, TinyMCE)
|
13
|
-
ActionController::Base.send(:helper, TinyMCEHelpers)
|
data/lib/tiny_mce.rb
CHANGED
@@ -1,40 +1,19 @@
|
|
1
|
-
# The base module we include into ActionController::Base
|
2
1
|
module TinyMCE
|
2
|
+
end
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
|
11
|
-
# The controller declaration to enable tiny_mce on certain actions.
|
12
|
-
# Takes options hash, raw_options string, and any normal params you
|
13
|
-
# can send to a before_filter (only, except etc)
|
14
|
-
def uses_tiny_mce(options = {})
|
15
|
-
tiny_mce_options = options.delete(:options) || {}
|
16
|
-
raw_tiny_mce_options = options.delete(:raw_options) || ''
|
17
|
-
|
18
|
-
# If the tiny_mce plugins includes the spellchecker, then form a spellchecking path,
|
19
|
-
# add it to the tiny_mce_options, and include the SpellChecking module
|
20
|
-
if !tiny_mce_options[:plugins].blank? && tiny_mce_options[:plugins].include?('spellchecker')
|
21
|
-
tiny_mce_options.reverse_merge!(:spellchecker_rpc_url => "/" + self.controller_name + "/spellchecker")
|
22
|
-
self.class_eval do
|
23
|
-
include TinyMCE::SpellChecker
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Set instance vars in the current class
|
28
|
-
proc = Proc.new do |c|
|
29
|
-
c.instance_variable_set(:@tiny_mce_options, tiny_mce_options)
|
30
|
-
c.instance_variable_set(:@raw_tiny_mce_options, raw_tiny_mce_options)
|
31
|
-
c.instance_variable_set(:@uses_tiny_mce, true)
|
32
|
-
end
|
4
|
+
# Require all the necessary files to run TinyMCE
|
5
|
+
require 'tiny_mce/controller.rb'
|
6
|
+
require 'tiny_mce/options_validator'
|
7
|
+
require 'tiny_mce/spellchecker'
|
8
|
+
require 'tiny_mce/helpers'
|
33
9
|
|
34
|
-
|
35
|
-
|
36
|
-
|
10
|
+
# Load up the available configuration options (we do it here because
|
11
|
+
# the result doesn't, so we don't want to load it per request)
|
12
|
+
TinyMCE::OptionValidator.load
|
37
13
|
|
38
|
-
|
14
|
+
# Include the TinyMCE methods and TinyMCE Helpers into ActionController::Base
|
39
15
|
|
16
|
+
if defined?(Rails) && defined?(ActionController)
|
17
|
+
ActionController::Base.send(:include, TinyMCE::Controller)
|
18
|
+
ActionController::Base.send(:helper, TinyMCEHelpers)
|
40
19
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TinyMCE
|
2
|
+
# The base module we include into ActionController::Base
|
3
|
+
module Controller
|
4
|
+
# When this module is included, extend it with the available class methods
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
# The controller declaration to enable tiny_mce on certain actions.
|
11
|
+
# Takes options hash, raw_options string, and any normal params you
|
12
|
+
# can send to a before_filter (only, except etc)
|
13
|
+
def uses_tiny_mce(options = {})
|
14
|
+
tiny_mce_options = options.delete(:options) || {}
|
15
|
+
raw_tiny_mce_options = options.delete(:raw_options) || ''
|
16
|
+
|
17
|
+
# If the tiny_mce plugins includes the spellchecker, then form a spellchecking path,
|
18
|
+
# add it to the tiny_mce_options, and include the SpellChecking module
|
19
|
+
if !tiny_mce_options[:plugins].blank? && tiny_mce_options[:plugins].include?('spellchecker')
|
20
|
+
tiny_mce_options.reverse_merge!(:spellchecker_rpc_url => "/" + self.controller_name + "/spellchecker")
|
21
|
+
self.class_eval do
|
22
|
+
include TinyMCE::SpellChecker
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set instance vars in the current class
|
27
|
+
proc = Proc.new do |c|
|
28
|
+
c.instance_variable_set(:@tiny_mce_options, tiny_mce_options)
|
29
|
+
c.instance_variable_set(:@raw_tiny_mce_options, raw_tiny_mce_options)
|
30
|
+
c.instance_variable_set(:@uses_tiny_mce, true)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Run the above proc before each page load this method is declared in
|
34
|
+
before_filter(proc, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module TinyMCE
|
2
|
+
# The helper module we include into ActionController::Base
|
3
|
+
module Helpers
|
4
|
+
# Setup a couple of Exception classes that we use later on
|
5
|
+
class TinyMCEInvalidOption < Exception; end
|
6
|
+
class TinyMCEInvalidOptionType < Exception; end
|
7
|
+
|
8
|
+
# Has uses_tiny_mce method been declared in the controller for this page?
|
9
|
+
def using_tiny_mce?
|
10
|
+
!@uses_tiny_mce.blank?
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parse @tiny_mce_options and @raw_tiny_mce_options to create a raw JS string
|
14
|
+
# used by TinyMCE. Returns errors if the option or options type is invalid
|
15
|
+
def raw_tiny_mce_init(options = {}, raw_options = '')
|
16
|
+
# first we set some defaults, then we merge in the controller level options
|
17
|
+
# and finally merge in the view level options (to give presidence)
|
18
|
+
@tiny_mce_options ||= {}
|
19
|
+
default_options = { 'mode' => 'textareas',
|
20
|
+
'editor_selector' => 'mceEditor',
|
21
|
+
'theme' => 'simple',
|
22
|
+
'language' => (defined?(I18n) ? I18n.locale : :en) }
|
23
|
+
options = default_options.merge(@tiny_mce_options.stringify_keys).merge(options.stringify_keys)
|
24
|
+
raw_options = @raw_tiny_mce_options + raw_options unless @raw_tiny_mce_options.nil?
|
25
|
+
|
26
|
+
unless options['plugins'].nil?
|
27
|
+
raise TinyMCEInvalidOptionType.new("Invalid value of type #{options['plugins'].class} passed for TinyMCE option plugins") unless options['plugins'].kind_of?(Array)
|
28
|
+
|
29
|
+
# Append the plugins we have enabled for this field to the OptionsValidator
|
30
|
+
TinyMCE::OptionValidator.plugins += options['plugins']
|
31
|
+
end
|
32
|
+
|
33
|
+
tinymce_js = "tinyMCE.init({\n"
|
34
|
+
options.sort.each_with_index do |values, index|
|
35
|
+
key, value = values[0], values[1]
|
36
|
+
raise TinyMCEInvalidOption.new("Invalid option #{key} passed to tinymce") unless TinyMCE::OptionValidator.valid?(key)
|
37
|
+
tinymce_js += "#{key} : "
|
38
|
+
case value
|
39
|
+
when String, Symbol, Fixnum
|
40
|
+
tinymce_js += "'#{value.to_s}'"
|
41
|
+
when Array
|
42
|
+
tinymce_js += '"' + value.join(',') + '"'
|
43
|
+
when TrueClass
|
44
|
+
tinymce_js += 'true'
|
45
|
+
when FalseClass
|
46
|
+
tinymce_js += 'false'
|
47
|
+
else
|
48
|
+
raise TinyMCEInvalidOptionType.new("Invalid value of type #{value.class} passed for TinyMCE option #{key}")
|
49
|
+
end
|
50
|
+
if (index < options.size - 1)
|
51
|
+
# there are more options in this array
|
52
|
+
tinymce_js += ",\n"
|
53
|
+
else
|
54
|
+
# no more options in this array. Finish it by adding the addition JS
|
55
|
+
tinymce_js += ",\n#{raw_options}" unless raw_options.blank?
|
56
|
+
tinymce_js += "\n"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
tinymce_js += "\n});"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Form the raw JS and wrap in in a <script> tag for inclusion in the <head>
|
63
|
+
def tiny_mce_init(options = {}, raw_options = '')
|
64
|
+
javascript_tag raw_tiny_mce_init(options, raw_options)
|
65
|
+
end
|
66
|
+
# Form the raw JS and wrap in in a <script> tag for inclusion in the <head>
|
67
|
+
# (only if tiny mce is actually being used)
|
68
|
+
def tiny_mce_init_if_needed(options = {}, raw_options = '')
|
69
|
+
tiny_mce_init(options, raw_options) if using_tiny_mce?
|
70
|
+
end
|
71
|
+
|
72
|
+
# Form a JS include tag for the TinyMCE JS src for inclusion in the <head>
|
73
|
+
def include_tiny_mce_js
|
74
|
+
javascript_include_tag (Rails.env.development? ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce")
|
75
|
+
end
|
76
|
+
# Form a JS include tag for the TinyMCE JS src for inclusion in the <head>
|
77
|
+
# (only if tiny mce is actually being used)
|
78
|
+
def include_tiny_mce_js_if_needed
|
79
|
+
include_tiny_mce_js if using_tiny_mce?
|
80
|
+
end
|
81
|
+
|
82
|
+
# Form a JS include tag for the TinyMCE JS src, and form the raw JS and wrap
|
83
|
+
# in in a <script> tag for inclusion in the <head> for inclusion in the <head>
|
84
|
+
# (only if tiny mce is actually being used)
|
85
|
+
def include_tiny_mce_if_needed(options = {}, raw_options = '')
|
86
|
+
if using_tiny_mce?
|
87
|
+
include_tiny_mce_js + tiny_mce_init(options, raw_options)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
File without changes
|
File without changes
|
data/tiny_mce.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tiny_mce}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Blake Watters", "Kieran Pilkington", "Alexander Semyonov"]
|
@@ -26,10 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"init.rb",
|
28
28
|
"install.rb",
|
29
|
-
"lib/options_validator.rb",
|
30
|
-
"lib/spellchecker.rb",
|
31
29
|
"lib/tiny_mce.rb",
|
32
|
-
"lib/
|
30
|
+
"lib/tiny_mce/controller.rb",
|
31
|
+
"lib/tiny_mce/helpers.rb",
|
32
|
+
"lib/tiny_mce/options_validator.rb",
|
33
|
+
"lib/tiny_mce/spellchecker.rb",
|
33
34
|
"public/javascripts/tiny_mce/langs/ar.js",
|
34
35
|
"public/javascripts/tiny_mce/langs/az.js",
|
35
36
|
"public/javascripts/tiny_mce/langs/be.js",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_mce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Watters
|
@@ -34,10 +34,11 @@ files:
|
|
34
34
|
- VERSION
|
35
35
|
- init.rb
|
36
36
|
- install.rb
|
37
|
-
- lib/options_validator.rb
|
38
|
-
- lib/spellchecker.rb
|
39
37
|
- lib/tiny_mce.rb
|
40
|
-
- lib/
|
38
|
+
- lib/tiny_mce/controller.rb
|
39
|
+
- lib/tiny_mce/helpers.rb
|
40
|
+
- lib/tiny_mce/options_validator.rb
|
41
|
+
- lib/tiny_mce/spellchecker.rb
|
41
42
|
- public/javascripts/tiny_mce/langs/ar.js
|
42
43
|
- public/javascripts/tiny_mce/langs/az.js
|
43
44
|
- public/javascripts/tiny_mce/langs/be.js
|
data/lib/tiny_mce_helpers.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
# The helper module we include into ActionController::Base
|
2
|
-
module TinyMCEHelpers
|
3
|
-
|
4
|
-
# Setup a couple of Exception classes that we use later on
|
5
|
-
class TinyMCEInvalidOption < Exception; end
|
6
|
-
class TinyMCEInvalidOptionType < Exception; end
|
7
|
-
|
8
|
-
# Has uses_tiny_mce method been declared in the controller for this page?
|
9
|
-
def using_tiny_mce?
|
10
|
-
!@uses_tiny_mce.blank?
|
11
|
-
end
|
12
|
-
|
13
|
-
# Parse @tiny_mce_options and @raw_tiny_mce_options to create a raw JS string
|
14
|
-
# used by TinyMCE. Returns errors if the option or options type is invalid
|
15
|
-
def raw_tiny_mce_init(options = {}, raw_options = '')
|
16
|
-
# first we set some defaults, then we merge in the controller level options
|
17
|
-
# and finally merge in the view level options (to give presidence)
|
18
|
-
@tiny_mce_options ||= {}
|
19
|
-
default_options = { 'mode' => 'textareas',
|
20
|
-
'editor_selector' => 'mceEditor',
|
21
|
-
'theme' => 'simple',
|
22
|
-
'language' => (defined?(I18n) ? I18n.locale : :en) }
|
23
|
-
options = default_options.merge(@tiny_mce_options.stringify_keys).merge(options.stringify_keys)
|
24
|
-
raw_options = @raw_tiny_mce_options + raw_options unless @raw_tiny_mce_options.nil?
|
25
|
-
|
26
|
-
unless options['plugins'].nil?
|
27
|
-
raise TinyMCEInvalidOptionType.new("Invalid value of type #{options['plugins'].class} passed for TinyMCE option plugins") unless options['plugins'].kind_of?(Array)
|
28
|
-
|
29
|
-
# Append the plugins we have enabled for this field to the OptionsValidator
|
30
|
-
TinyMCE::OptionValidator.plugins += options['plugins']
|
31
|
-
end
|
32
|
-
|
33
|
-
tinymce_js = "tinyMCE.init({\n"
|
34
|
-
options.sort.each_with_index do |values, index|
|
35
|
-
key, value = values[0], values[1]
|
36
|
-
raise TinyMCEInvalidOption.new("Invalid option #{key} passed to tinymce") unless TinyMCE::OptionValidator.valid?(key)
|
37
|
-
tinymce_js += "#{key} : "
|
38
|
-
case value
|
39
|
-
when String, Symbol, Fixnum
|
40
|
-
tinymce_js += "'#{value.to_s}'"
|
41
|
-
when Array
|
42
|
-
tinymce_js += '"' + value.join(',') + '"'
|
43
|
-
when TrueClass
|
44
|
-
tinymce_js += 'true'
|
45
|
-
when FalseClass
|
46
|
-
tinymce_js += 'false'
|
47
|
-
else
|
48
|
-
raise TinyMCEInvalidOptionType.new("Invalid value of type #{value.class} passed for TinyMCE option #{key}")
|
49
|
-
end
|
50
|
-
if (index < options.size - 1)
|
51
|
-
# there are more options in this array
|
52
|
-
tinymce_js += ",\n"
|
53
|
-
else
|
54
|
-
# no more options in this array. Finish it by adding the addition JS
|
55
|
-
tinymce_js += ",\n#{raw_options}" unless raw_options.blank?
|
56
|
-
tinymce_js += "\n"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
tinymce_js += "\n});"
|
60
|
-
end
|
61
|
-
|
62
|
-
# Form the raw JS and wrap in in a <script> tag for inclusion in the <head>
|
63
|
-
def tiny_mce_init(options = {}, raw_options = '')
|
64
|
-
javascript_tag raw_tiny_mce_init(options, raw_options)
|
65
|
-
end
|
66
|
-
# Form the raw JS and wrap in in a <script> tag for inclusion in the <head>
|
67
|
-
# (only if tiny mce is actually being used)
|
68
|
-
def tiny_mce_init_if_needed(options = {}, raw_options = '')
|
69
|
-
tiny_mce_init(options, raw_options) if using_tiny_mce?
|
70
|
-
end
|
71
|
-
|
72
|
-
# Form a JS include tag for the TinyMCE JS src for inclusion in the <head>
|
73
|
-
def include_tiny_mce_js
|
74
|
-
javascript_include_tag (Rails.env.development? ? "tiny_mce/tiny_mce_src" : "tiny_mce/tiny_mce")
|
75
|
-
end
|
76
|
-
# Form a JS include tag for the TinyMCE JS src for inclusion in the <head>
|
77
|
-
# (only if tiny mce is actually being used)
|
78
|
-
def include_tiny_mce_js_if_needed
|
79
|
-
include_tiny_mce_js if using_tiny_mce?
|
80
|
-
end
|
81
|
-
|
82
|
-
# Form a JS include tag for the TinyMCE JS src, and form the raw JS and wrap
|
83
|
-
# in in a <script> tag for inclusion in the <head> for inclusion in the <head>
|
84
|
-
# (only if tiny mce is actually being used)
|
85
|
-
def include_tiny_mce_if_needed(options = {}, raw_options = '')
|
86
|
-
if using_tiny_mce?
|
87
|
-
include_tiny_mce_js + tiny_mce_init(options, raw_options)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|