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: CompressionDisabledError, InvalidPatchPluginError, MissingInlinePluginError, UnsupportedESModuleError
Instance Method Summary collapse
-
#external_plugin(name, **kwargs) ⇒ Object
Registers an external plugin loaded from a URL.
-
#inline_plugin(name, code, compress: true) ⇒ Object
Registers an inline plugin with raw JavaScript code.
-
#patch_plugin(plugin) ⇒ Editor::PropsPatchPlugin?
Registers a patch plugin that modifies CKEditor behavior for specific versions.
-
#plugin(name, **kwargs) ⇒ Object
Register a single plugin by name.
-
#plugins(*names, **kwargs, &block) ⇒ Object
Register multiple plugins and configure plugin settings.
-
#try_compress_inline_plugins! ⇒ void
Compresses inline plugins to reduce bundle size.
Instance Method Details
#external_plugin(name, **kwargs) ⇒ Object
Registers an external plugin loaded from a URL
31 32 33 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 31 def external_plugin(name, **kwargs) register_plugin(Editor::PropsExternalPlugin.new(name, **kwargs)) end |
#inline_plugin(name, code, compress: true) ⇒ Object
Registers an inline plugin with raw JavaScript code
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 54 def inline_plugin(name, code, compress: true) 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 compress = false if @disallow_inline_plugin_compression plugin = Editor::PropsInlinePlugin.new(name, code, compress: compress) register_plugin(plugin) end |
#patch_plugin(plugin) ⇒ Editor::PropsPatchPlugin?
Registers a patch plugin that modifies CKEditor behavior for specific versions
79 80 81 82 83 84 85 86 87 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 79 def patch_plugin(plugin) unless plugin.is_a?(Editor::PropsPatchPlugin) raise InvalidPatchPluginError, 'Provided plugin must be a PropsPatchPlugin instance' end return unless !@version || plugin.applicable_for_version?(@version) register_plugin(plugin) end |
#plugin(name, **kwargs) ⇒ Object
Register a single plugin by name
99 100 101 102 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 99 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
116 117 118 119 120 121 122 123 124 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 116 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 |
#try_compress_inline_plugins! ⇒ void
This method is called automatically when defining a preset
This method returns an undefined value.
Compresses inline plugins to reduce bundle size
133 134 135 136 137 138 139 140 141 |
# File 'lib/ckeditor5/rails/presets/concerns/plugin_methods.rb', line 133 def try_compress_inline_plugins! raise CompressionDisabledError if @disallow_inline_plugin_compression config[:plugins].each do |plugin| next unless plugin.is_a?(Editor::PropsInlinePlugin) plugin.try_compress! end end |