Module: CKEditor5::Rails::Presets::Concerns::PluginMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Context::PresetBuilder, PresetBuilder
- Defined in:
- lib/ckeditor5/rails/presets/concerns/plugin_methods.rb
Defined Under Namespace
Classes: DisallowedInlinePluginError, MissingInlinePluginError, UnsupportedESModuleError
Instance Method Summary collapse
-
#external_plugin(name, **kwargs) ⇒ Object
Registers an external plugin loaded from a URL.
-
#inline_plugin(name, code) ⇒ Object
Registers an inline plugin with raw JavaScript code.
-
#plugin(name, **kwargs) ⇒ Object
Register a single plugin by name.
-
#plugins(*names, **kwargs, &block) ⇒ Object
Register multiple plugins and configure plugin settings.
Instance Method Details
#external_plugin(name, **kwargs) ⇒ Object
Registers an external plugin loaded from a URL
30 31 32 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 30 def external_plugin(name, **kwargs) register_plugin(Editor::PropsExternalPlugin.new(name, **kwargs)) end |
#inline_plugin(name, code) ⇒ Object
Registers an inline plugin with raw JavaScript code
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 52 def inline_plugin(name, code) if code.match?(/export default/) raise UnsupportedESModuleError, 'Inline plugins must not use ES module syntax!' \ 'Use async async imports instead!' end unless code.match?(/return class(\s+\w+)?\s+extends\s+Plugin/) raise MissingInlinePluginError, 'Plugin code must return a class that extends Plugin!' end plugin = Editor::PropsInlinePlugin.new(name, code) plugin.compress! unless disallow_inline_plugin_compression register_plugin(plugin) end |
#plugin(name, **kwargs) ⇒ Object
Register a single plugin by name
80 81 82 83 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 80 def plugin(name, **kwargs) premium(true) if kwargs[:premium] && respond_to?(:premium) register_plugin(PluginsBuilder.create_plugin(name, **kwargs)) end |
#plugins(*names, **kwargs, &block) ⇒ Object
Register multiple plugins and configure plugin settings
97 98 99 100 101 102 103 104 105 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 97 def plugins(*names, **kwargs, &block) config[:plugins] ||= [] names.each { |name| plugin(name, **kwargs) } unless names.empty? builder = PluginsBuilder.new(config[:plugins]) builder.instance_eval(&block) if block_given? builder end |