Class: CKEditor5::Rails::Presets::ToolbarBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::ToolbarBuilder
- Defined in:
- lib/ckeditor5/rails/presets/toolbar_builder.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#append(*appended_items, after: nil) ⇒ Object
Append items to the editor toolbar.
-
#initialize(items) ⇒ ToolbarBuilder
constructor
A new instance of ToolbarBuilder.
-
#prepend(*prepended_items, before: nil) ⇒ Object
Prepend items to the editor toolbar.
-
#remove(*removed_items) ⇒ Object
Remove items from the editor toolbar.
Constructor Details
#initialize(items) ⇒ ToolbarBuilder
Returns a new instance of ToolbarBuilder.
7 8 9 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 7 def initialize(items) @items = items end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 5 def items @items end |
Instance Method Details
#append(*appended_items, after: nil) ⇒ Object
Append items to the editor toolbar.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 59 def append(*appended_items, after: nil) if after index = items.index(after) raise ArgumentError, "Item '#{after}' not found in array" unless index items.insert(index + 1, *appended_items) else items.push(*appended_items) end end |
#prepend(*prepended_items, before: nil) ⇒ Object
Prepend items to the editor toolbar.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 35 def prepend(*prepended_items, before: nil) if before index = items.index(before) raise ArgumentError, "Item '#{before}' not found in array" unless index items.insert(index, *prepended_items) else items.insert(0, *prepended_items) end end |
#remove(*removed_items) ⇒ Object
Remove items from the editor toolbar.
18 19 20 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 18 def remove(*removed_items) removed_items.each { |item| items.delete(item) } end |