Class: CKEditor5::Rails::Presets::ToolbarBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::ToolbarBuilder
- Defined in:
- lib/ckeditor5/rails/presets/toolbar_builder.rb
Instance Method Summary collapse
- #append(*appended_items, after: nil) ⇒ Object
-
#initialize(toolbar_config) ⇒ ToolbarBuilder
constructor
A new instance of ToolbarBuilder.
- #items ⇒ Object
- #prepend(*prepended_items, before: nil) ⇒ Object
- #remove(*removed_items) ⇒ Object
Constructor Details
#initialize(toolbar_config) ⇒ ToolbarBuilder
Returns a new instance of ToolbarBuilder.
5 6 7 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 5 def initialize() @toolbar_config = end |
Instance Method Details
#append(*appended_items, after: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 28 def append(*appended_items, after: nil) if after index = items.index(after) raise ArgumentError, "Item '#{after}' not found in toolbar" unless index items.insert(index + 1, *appended_items) else items.push(*appended_items) end end |
#items ⇒ Object
9 10 11 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 9 def items @toolbar_config[:items] end |
#prepend(*prepended_items, before: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 17 def prepend(*prepended_items, before: nil) if before index = items.index(before) raise ArgumentError, "Item '#{before}' not found in toolbar" unless index items.insert(index, *prepended_items) else items.insert(0, *prepended_items) end end |
#remove(*removed_items) ⇒ Object
13 14 15 |
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 13 def remove(*removed_items) removed_items.each { |item| items.delete(item) } end |