The TinyMCE::Rails::Configuration class manages the conversion of Ruby configuration hashes into a JavaScript object format compatible with tinymce.init().
Default Options
By default, the configuration includes:
selector: "textarea.tinymce"cache_suffix: A versioned string used for cache busting.
Key Features
- Array Joining: Arrays passed in the configuration are automatically joined into strings using specific separators required by TinyMCE (e.g.,
plugins uses commas, while font_formats uses semicolons). - Function Support: Strings that match JavaScript function patterns (e.g.,
function(arg) { ... } or arrow functions) are treated as Function objects to ensure they are passed correctly to the JavaScript runtime. - Asset Path Resolution: The
content_css option automatically attempts to resolve relative file paths to their actual Rails stylesheet paths using stylesheet_path.
# Example of how configuration is structured conceptually
# (Note: Actual usage typically happens via the gem's helper methods)
config = TinyMCE::Rails::Configuration.new_with_defaults({
"plugins" => ["advlist", "autolink", "lists"],
"content_css" => ["application.css"],
"toolbar" => "undo redo | styleselect | bold italic"
})
# The resulting JavaScript string for tinymce.init() would look like:
# {
# 'plugins': 'advlist,autolink,lists',
# 'content_css': '/assets/application-hash.css',
# 'toolbar': 'undo redo | styleselect | bold italic'
# }