Module: TinyMCE::Rails::Helper
- Defined in:
- lib/tinymce/rails/helper.rb
Class Method Summary collapse
-
.tinymce(config = :default, options = {}) ⇒ Object
Initializes TinyMCE on the current page based on the global configuration.
-
.tinymce_configuration(config = :default, options = {}) ⇒ Object
Returns the TinyMCE configuration object.
-
.tinymce_configurations_javascript(options = {}) ⇒ Object
Returns the JavaScript code for initializing each configuration defined within tinymce.yml.
-
.tinymce_javascript(config = :default, options = {}) ⇒ Object
Returns the JavaScript code required to initialize TinyMCE.
Instance Method Summary collapse
-
#tinymce(config = :default, options = {}) ⇒ Object
Initializes TinyMCE on the current page based on the global configuration.
-
#tinymce_assets ⇒ Object
Includes TinyMCE javascript assets via a script tag.
-
#tinymce_configuration(config = :default, options = {}) ⇒ Object
Returns the TinyMCE configuration object.
-
#tinymce_configurations_javascript(options = {}) ⇒ Object
Returns the JavaScript code for initializing each configuration defined within tinymce.yml.
-
#tinymce_javascript(config = :default, options = {}) ⇒ Object
Returns the JavaScript code required to initialize TinyMCE.
Class Method Details
.tinymce(config = :default, options = {}) ⇒ Object
Initializes TinyMCE on the current page based on the global configuration.
Custom options can be set via the options hash, which will be passed to the TinyMCE init function.
By default, all textareas with a class of “tinymce” will have the TinyMCE editor applied. The current locale will also be used as the language when TinyMCE language files are available, falling back to English if not available. The :editor_selector and :language options can be used to override these defaults.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tinymce/rails/helper.rb', line 18 def tinymce(config=:default, ={}) javascript_tag(nonce: true) do unless @_tinymce_configurations_added concat tinymce_configurations_javascript concat "\n" @_tinymce_configurations_added = true end concat tinymce_javascript(config, ) end end |
.tinymce_configuration(config = :default, options = {}) ⇒ Object
Returns the TinyMCE configuration object. It should be converted to JavaScript (via #to_javascript) for use within JavaScript.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tinymce/rails/helper.rb', line 52 def tinymce_configuration(config=:default, ={}) , config = config, :default if config.is_a?(Hash) .stringify_keys! base_configuration = TinyMCE::Rails.configuration if base_configuration.is_a?(MultipleConfiguration) base_configuration = base_configuration.fetch(config) end base_configuration.merge() end |
.tinymce_configurations_javascript(options = {}) ⇒ Object
Returns the JavaScript code for initializing each configuration defined within tinymce.yml.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tinymce/rails/helper.rb', line 39 def tinymce_configurations_javascript(={}) javascript = [] TinyMCE::Rails.each_configuration do |name, config| config = config.merge() if .present? javascript << "TinyMCERails.configuration.#{name} = #{config.to_javascript};".html_safe end safe_join(javascript, "\n") end |
.tinymce_javascript(config = :default, options = {}) ⇒ Object
Returns the JavaScript code required to initialize TinyMCE.
31 32 33 34 35 36 |
# File 'lib/tinymce/rails/helper.rb', line 31 def tinymce_javascript(config=:default, ={}) , config = config, :default if config.is_a?(Hash) = Configuration.new() "TinyMCERails.initialize('#{config}', #{.to_javascript});".html_safe end |
Instance Method Details
#tinymce(config = :default, options = {}) ⇒ Object
Initializes TinyMCE on the current page based on the global configuration.
Custom options can be set via the options hash, which will be passed to the TinyMCE init function.
By default, all textareas with a class of “tinymce” will have the TinyMCE editor applied. The current locale will also be used as the language when TinyMCE language files are available, falling back to English if not available. The :editor_selector and :language options can be used to override these defaults.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tinymce/rails/helper.rb', line 18 def tinymce(config=:default, ={}) javascript_tag(nonce: true) do unless @_tinymce_configurations_added concat tinymce_configurations_javascript concat "\n" @_tinymce_configurations_added = true end concat tinymce_javascript(config, ) end end |
#tinymce_assets ⇒ Object
Includes TinyMCE javascript assets via a script tag.
66 67 68 |
# File 'lib/tinymce/rails/helper.rb', line 66 def tinymce_assets javascript_include_tag "tinymce", "data-turbolinks-track" => "reload" end |
#tinymce_configuration(config = :default, options = {}) ⇒ Object
Returns the TinyMCE configuration object. It should be converted to JavaScript (via #to_javascript) for use within JavaScript.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tinymce/rails/helper.rb', line 52 def tinymce_configuration(config=:default, ={}) , config = config, :default if config.is_a?(Hash) .stringify_keys! base_configuration = TinyMCE::Rails.configuration if base_configuration.is_a?(MultipleConfiguration) base_configuration = base_configuration.fetch(config) end base_configuration.merge() end |
#tinymce_configurations_javascript(options = {}) ⇒ Object
Returns the JavaScript code for initializing each configuration defined within tinymce.yml.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tinymce/rails/helper.rb', line 39 def tinymce_configurations_javascript(={}) javascript = [] TinyMCE::Rails.each_configuration do |name, config| config = config.merge() if .present? javascript << "TinyMCERails.configuration.#{name} = #{config.to_javascript};".html_safe end safe_join(javascript, "\n") end |
#tinymce_javascript(config = :default, options = {}) ⇒ Object
Returns the JavaScript code required to initialize TinyMCE.
31 32 33 34 35 36 |
# File 'lib/tinymce/rails/helper.rb', line 31 def tinymce_javascript(config=:default, ={}) , config = config, :default if config.is_a?(Hash) = Configuration.new() "TinyMCERails.initialize('#{config}', #{.to_javascript});".html_safe end |