tinymce-rails-config-manager 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 ITHouse Latvia and Arturs Meisters
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # TinymceRailsConfigManager
2
+ Simple tinyMCE configuration manager
3
+
4
+ ## Instructions
5
+
6
+ 1. Add **tinymce-rails-config-manager**
7
+
8
+ ```ruby
9
+ gem 'tinymce-rails-config-manager'
10
+ ```
11
+
12
+ 2. Include asset in your JS manifest file
13
+
14
+ ` //= require tinymce-rails-config-manager `
15
+
16
+ ## Usage
17
+
18
+ ### How to change setting properties
19
+
20
+ * To add new property (added only once)
21
+
22
+ This will add **template** to plugin option existing value
23
+
24
+ ```javascript
25
+ TinyMCEConfigManager.get().config.add("plugin", "template")
26
+ ```
27
+
28
+ * To add new value after some other (added only once; buttons is shortcut to all theme_advanced_buttonsX)
29
+
30
+ This will add fullscreen button after bold
31
+
32
+ ```javascript
33
+ TinyMCEConfigManager.get().config.addAfter("buttons", "fullscreen", "bold")
34
+ ```
35
+
36
+ * To add new value before some other (added only once)
37
+
38
+ This will add fullscreen button before bold
39
+
40
+ ```javascript
41
+ TinyMCEConfigManager.get().config.addBefore("buttons", "fullscreen", "bold")
42
+ ```
43
+
44
+ * To set property
45
+
46
+ This will set value **right** for theme_advanced_toolbar_align
47
+
48
+ ```javascript
49
+ TinyMCEConfigManager.get().config.set("theme_advanced_toolbar_align", "right")
50
+ ```
51
+
52
+ * To add callback (new callback function will be added with every call)
53
+
54
+ This will add callback for **setup**
55
+
56
+ ```javascript
57
+ TinyMCEConfigManager.get().config.addFunction("setup", function(editor){ /*do something here*/})
58
+ ```
59
+
60
+
61
+ ### How to change settings
62
+
63
+ To add or change settings for specific textareas use
64
+
65
+ ```javascript
66
+ TinyMCEConfigManager.get().configFor("#my_special_textarea")
67
+ ```
68
+
69
+ and then use all property modifiers as mentioned above. Default settings will be loaded for all other textareas.
70
+
71
+ ### How to load
72
+
73
+ Simply call `load()`. Also it is possible to pass some specific configuration there, but that will overwrite existing and
74
+ that is not recommended.
75
+
76
+ ```javascript
77
+ TinyMCEConfigManager.get().load()
78
+ ```
79
+
80
+ ## Roadmap
81
+
82
+ * Make it possible to change order of existing values
83
+ * add tests
84
+
85
+ This project rocks and uses MIT-LICENSE.
86
+
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TinymceRailsConfigManager'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ require 'jasmine'
24
+ load 'jasmine/tasks/jasmine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ namespace :jasmine do
29
+ desc "Compile CoffeeScript files"
30
+ task :compile do
31
+ require 'coffee-script'
32
+ source_files = Dir["./app/assets/javascripts/**/*.coffee"]
33
+ source_specs = Dir["./spec/javascripts/**/*.coffee"]
34
+
35
+ dest_dir = "./spec/javascripts/generated"
36
+ spec_dest_dir = File.join(dest_dir, "spec")
37
+ js_dest_dir = File.join(dest_dir, "javascripts")
38
+
39
+ [spec_dest_dir, js_dest_dir].each do |dir|
40
+ unless File.directory?(dir)
41
+ Dir.mkdir(dir)
42
+ end
43
+ end
44
+
45
+ { spec_dest_dir => source_specs, js_dest_dir => source_files}.each do |dest_dir, files|
46
+ files.each do |file_path|
47
+ dest_path = File.join(dest_dir, File.basename(file_path, ".coffee"))
48
+ File.open(dest_path, "w") do |f|
49
+ f.write(CoffeeScript.compile(File.read(file_path)))
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ namespace :ci do
56
+ desc "Run Jasmine CI for CoffeeScripts"
57
+ task :coffee do
58
+ Rake::Task['jasmine:compile'].invoke
59
+ Rake::Task['jasmine:ci'].invoke
60
+ end
61
+ end
62
+
63
+ desc "Run Jasmine for CoffeeScripts"
64
+ task :coffee do
65
+ Rake::Task['jasmine:compile'].invoke
66
+ Rake::Task['jasmine'].invoke
67
+ end
68
+ end
@@ -0,0 +1,194 @@
1
+ # TinyMCEConfigManager class makes it easier to manage configuration for TinyMCE.
2
+ # There are only one instance of TinyMCEConfigManager and to access it call
3
+ # TinyMCEConfigManager.get()
4
+ # To access default configuration call
5
+ # TinyMCEConfigManager.get().config.[someMethod]
6
+ # To access configuration for specific selector call
7
+ # TinyMCEConfigManager.get().configFor("#myTextFieldID").[someMethod]
8
+ # To load tinymce call
9
+ # TinyMCEConfigManager.load([optional settings here])
10
+ # Those selector that are used with selector specific configurations are not used with default selector in when tinyMCE is initialized with default selector
11
+ class TinyMCEConfigManager
12
+
13
+ TEXTAREA_SELECTOR = "textarea[data-simple!=true]"
14
+ DEFAULT_SETTINGS = {
15
+ theme: "advanced",
16
+ skin: "cirkuit",
17
+ mode: "textareas",
18
+ plugins: "table,fullscreen,lists,paste",
19
+ theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,formatselect,|,image,removeformat,code,fullscreen",
20
+ theme_advanced_buttons2 : "tablecontrols,|,paste,pastetext,pasteword,|,anchor,link,unlink",
21
+ theme_advanced_buttons3 : "",
22
+ theme_advanced_toolbar_location: "top",
23
+ theme_advanced_toolbar_align: "left",
24
+ }
25
+
26
+ @_instance: null
27
+
28
+ @get: ->
29
+ if not @_instance?
30
+ @_instance = new @
31
+ @_instance.init()
32
+ @_instance
33
+
34
+ init: ->
35
+ @defaultConfig = @_createNewConfiguration()
36
+ @defaultConfig.setAsDefault()
37
+ @config = @defaultConfig
38
+ @_configs = {}
39
+
40
+ #TODO any configuration added to specific selectors should go in queue and only when load is called
41
+ # then those commands should be applied to real settings. Then always any other selector will use latest
42
+ # default config settings, and in right order will apply their settings to it
43
+ configFor: (selector) ->
44
+ unless @_configs[selector]
45
+ @_configs[selector] = @_createNewConfiguration(@config.settings)
46
+ @_configs[selector]
47
+
48
+ load: (extendedSettings) ->
49
+ for selector, config of @_configs
50
+ @_initializeTinyMCEFor(selector, config, extendedSettings)
51
+ @_initializeDefaultTinyMCE(extendedSettings)
52
+
53
+ defaultSettings: ->
54
+ DEFAULT_SETTINGS
55
+
56
+ textareaSelector: ->
57
+ TEXTAREA_SELECTOR
58
+
59
+ _createNewConfiguration: (givenSettings) ->
60
+ new TinyMCEConfigManagerConfiguration(@_settings(givenSettings))
61
+
62
+ _settings: (givenSettings) ->
63
+ newSettings = $.extend(true, {}, @defaultSettings())
64
+ if givenSettings
65
+ $.extend(true, newSettings, givenSettings)
66
+ newSettings
67
+
68
+ _initializeTinyMCEFor: (selector, config, extendedSettings) ->
69
+ newSettings = $.extend(true, $.extend(true, {}, config.settings), extendedSettings)
70
+ $(selector).tinymce(newSettings)
71
+
72
+ _initializeDefaultTinyMCE: (extendedSettings) ->
73
+ newSettings = $.extend(true, $.extend(true, {}, @config.settings), extendedSettings)
74
+ $selector = $(@textareaSelector())
75
+ for selector, config of @_configs
76
+ $selector = $selector.not(selector)
77
+ $selector.tinymce(newSettings)
78
+
79
+ # TinyMCEConfigManagerConfiguration allow to change values of tinyMCE configuration.
80
+ @TinyMCEConfigManagerConfiguration = class TinyMCEConfigManagerConfiguration
81
+
82
+ constructor: (settings) ->
83
+ @settings = settings
84
+ @callbacks = {}
85
+ @default = false
86
+
87
+ add: (keyName, newValue) ->
88
+ listManager = new TinyMCEListSettingManager(this)
89
+ listManager.add(keyName, newValue)
90
+
91
+ addAfter: (keyName, newValue, oldValue) ->
92
+ listManager = new TinyMCEListSettingManager(this)
93
+ listManager.addAfter(keyName, newValue, oldValue)
94
+
95
+ addBefore: (keyName, newValue, oldValue) ->
96
+ listManager = new TinyMCEListSettingManager(this)
97
+ listManager.addBefore(keyName, newValue, oldValue)
98
+
99
+ set: (keyName, newValue) ->
100
+ valueManager = new TinyMCEValueSettingManager(this)
101
+ valueManager.set(keyName, newValue)
102
+
103
+ addFunction: (keyName, newFunction) ->
104
+ functionManager = new TinyMCEFunctionSettingManager(this)
105
+ functionManager.add(keyName, newFunction)
106
+
107
+ callCallbacksOn: (callbackName, args) ->
108
+ for callback in @callbacks[callbackName]
109
+ callback.apply(window, args)
110
+
111
+ setValue: (keyName, newValue) ->
112
+ @settings[keyName] = newValue
113
+
114
+ setAsDefault: ->
115
+ @default = true
116
+
117
+
118
+ class TinyMCESettingManager
119
+ constructor: (config) ->
120
+ @config = config
121
+
122
+ _getValue: (keyName) ->
123
+ @config.settings[keyName]
124
+
125
+ _setValue: (keyName, newValue) ->
126
+ @config.setValue(keyName, newValue)
127
+
128
+ # Manage options that consist of string values that are seperated with commas
129
+ class TinyMCEListSettingManager extends TinyMCESettingManager
130
+ COMPLEX_OPTIONS = {
131
+ buttons: ['theme_advanced_buttons1', 'theme_advanced_buttons2', 'theme_advanced_buttons3']
132
+ }
133
+
134
+ add:(keyName, newValue) ->
135
+ for listKeyName, list of @_valuesList(keyName)
136
+ if list
137
+ if list.length > 0
138
+ newList = list + "," + newValue
139
+ else
140
+ newList = newValue
141
+ @_setValue(listKeyName, newList)
142
+
143
+ addAfter: (keyName, newValue, oldValue) ->
144
+ for listKeyName, list of @_valuesList(keyName)
145
+ if list && @_valueExist(list, oldValue) and not @_valueExist(list, newValue)
146
+ newList = list.replace(@_valueRegExp(oldValue), oldValue + "," + newValue)
147
+ @_setValue(listKeyName, newList)
148
+
149
+ addBefore: (keyName, newValue, oldValue) ->
150
+ for listKeyName, list of @_valuesList(keyName)
151
+ if list && @_valueExist(list, oldValue) and not @_valueExist(list, newValue)
152
+ newList = list.replace(@_valueRegExp(oldValue), newValue + "," + oldValue)
153
+ @_setValue(listKeyName, newList)
154
+
155
+ _valueRegExp: (value)->
156
+ new RegExp("\\b" + value + "\\b")
157
+
158
+ _valueExist: (list, value) ->
159
+ list.match(@_valueRegExp(value))
160
+
161
+ _valuesList: (keyName) ->
162
+ complexKeys = COMPLEX_OPTIONS[keyName]
163
+ result = {}
164
+ if complexKeys
165
+ for key in complexKeys
166
+ result[key] = @_getValue(key)
167
+ else
168
+ result[keyName] = @_getValue(keyName)
169
+ result
170
+
171
+
172
+ class TinyMCEValueSettingManager extends TinyMCESettingManager
173
+
174
+ set: (keyName, newValue) ->
175
+ @_setValue(keyName, newValue)
176
+
177
+ class TinyMCEFunctionSettingManager extends TinyMCESettingManager
178
+
179
+ add: (keyName, newFunction) ->
180
+ @_addCallback(keyName, newFunction)
181
+ config = @config
182
+ @_setValue(keyName, (@arguments)->
183
+ config.callCallbacksOn(keyName, arguments)
184
+ )
185
+
186
+ _addCallback: (keyName, newFunction) ->
187
+ unless @config.callbacks[keyName]
188
+ @config.callbacks[keyName] = [newFunction]
189
+ else
190
+ @config.callbacks[keyName].push(newFunction)
191
+
192
+
193
+ window.TinyMCEConfigManager = TinyMCEConfigManager
194
+
@@ -0,0 +1 @@
1
+ //= require_directory ./tinymce-rails-config-manager
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'jasmine'
3
+ load 'jasmine/tasks/jasmine.rake'
4
+ rescue LoadError
5
+ task :jasmine do
6
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tinymce-rails-config-manager do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ module TinymceRailsConfigManager
2
+ class Engine < Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module TinymceRailsConfigManager
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,7 @@
1
+ module TinymceRailsConfigManager
2
+ def self.load!
3
+ require 'tinymce-rails-config-manager/engine'
4
+ end
5
+ end
6
+
7
+ TinymceRailsConfigManager.load!
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinymce-rails-config-manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ITHouse (Latvia) and Arturs Meisters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.8
30
+ description: Simple tinyMCE configuration manager that makes it easier to manage different
31
+ configurations without changing templates
32
+ email:
33
+ - support@ithouse.lv
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - app/assets/javascripts/tinymce-rails-config-manager/manager.js.coffee
39
+ - app/assets/javascripts/tinymce-rails-config-manager.js
40
+ - lib/tinymce-rails-config-manager/version.rb
41
+ - lib/tinymce-rails-config-manager/engine.rb
42
+ - lib/tinymce-rails-config-manager.rb
43
+ - lib/tasks/tinymce-rails-config-manager_tasks.rake
44
+ - lib/tasks/jasmine.rake
45
+ - MIT-LICENSE
46
+ - Rakefile
47
+ - README.md
48
+ homepage: http://github.com/ithouse/tinymce-rails-config-manager
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ segments:
61
+ - 0
62
+ hash: 2286425305098803774
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: 2286425305098803774
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Simple tinyMCE configuration manager.
78
+ test_files: []