Class: CKEditor5::Rails::Presets::PluginsBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::PluginsBuilder
- Defined in:
- lib/ckeditor5/rails/presets/plugins_builder.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Class Method Summary collapse
-
.create_plugin(name, **kwargs) ⇒ Editor::PropsBasePlugin
Creates a plugin instance from a name or returns the plugin if it’s already a PropsBasePlugin.
Instance Method Summary collapse
-
#append(*names, after: nil, **kwargs) ⇒ Object
Appends plugins to the end of the plugins list or after a specific plugin.
-
#initialize(plugins) ⇒ PluginsBuilder
constructor
A new instance of PluginsBuilder.
-
#prepend(*names, before: nil, **kwargs) ⇒ Object
Prepends plugins to the beginning of the plugins list or before a specific plugin.
-
#remove(*names) ⇒ Object
Removes specified plugins from the editor configuration.
Constructor Details
#initialize(plugins) ⇒ PluginsBuilder
Returns a new instance of PluginsBuilder.
7 8 9 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 7 def initialize(plugins) @items = plugins end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 5 def items @items end |
Class Method Details
.create_plugin(name, **kwargs) ⇒ Editor::PropsBasePlugin
Creates a plugin instance from a name or returns the plugin if it’s already a PropsBasePlugin
16 17 18 19 20 21 22 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 16 def self.create_plugin(name, **kwargs) if name.is_a?(Editor::PropsBasePlugin) name else Editor::PropsPlugin.new(name, **kwargs) end end |
Instance Method Details
#append(*names, after: nil, **kwargs) ⇒ Object
Appends plugins to the end of the plugins list or after a specific plugin
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 68 def append(*names, after: nil, **kwargs) new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) } if after index = items.index { |p| p.name == after } raise ArgumentError, "Plugin '#{after}' not found" unless index items.insert(index + 1, *new_plugins) else items.push(*new_plugins) end end |
#prepend(*names, before: nil, **kwargs) ⇒ Object
Prepends plugins to the beginning of the plugins list or before a specific plugin
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 45 def prepend(*names, before: nil, **kwargs) new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) } if before index = items.index { |p| p.name == before } raise ArgumentError, "Plugin '#{before}' not found" unless index items.insert(index, *new_plugins) else items.insert(0, *new_plugins) end end |
#remove(*names) ⇒ Object
Removes specified plugins from the editor configuration
31 32 33 |
# File 'lib/ckeditor5/rails/presets/plugins_builder.rb', line 31 def remove(*names) names.each { |name| items.delete_if { |plugin| plugin.name == name } } end |