Class: CKEditor5::Rails::Presets::ToolbarBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ckeditor5/rails/presets/toolbar_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemsObject (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



26
27
28
29
30
31
32
33
34
35
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 26

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



15
16
17
18
19
20
21
22
23
24
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 15

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



11
12
13
# File 'lib/ckeditor5/rails/presets/toolbar_builder.rb', line 11

def remove(*removed_items)
  removed_items.each { |item| items.delete(item) }
end