Class: Inkpen::Toolbar

Inherits:
Object
  • Object
show all
Defined in:
lib/inkpen/toolbar.rb

Overview

PORO representing toolbar configuration.

The Toolbar class configures the floating or fixed toolbar that appears when text is selected (floating) or at the top of the editor (fixed).

Examples:

Basic floating toolbar

toolbar = Inkpen::Toolbar.new(style: :floating)

Custom button set

toolbar = Inkpen::Toolbar.new(
  style: :fixed,
  buttons: [:bold, :italic, :link, :heading]
)

Using presets

toolbar = Inkpen::Toolbar.new(
  style: :floating,
  buttons: Inkpen::Toolbar::PRESET_MINIMAL
)

See Also:

Author:

  • Nauman Tariq

Since:

  • 0.1.0

Constant Summary collapse

FORMATTING_BUTTONS =

Text formatting buttons (bold, italic, strike, underline).

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

%i[bold italic strike underline].freeze
BLOCK_BUTTONS =

Block-level formatting buttons.

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

%i[heading bullet_list ordered_list blockquote code_block].freeze
INSERT_BUTTONS =

Content insertion buttons.

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

%i[link image table horizontal_rule].freeze
PRESET_MINIMAL =

Minimal preset (bold, italic, link).

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

%i[bold italic link].freeze
PRESET_STANDARD =

Standard preset with common formatting options.

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

(FORMATTING_BUTTONS + %i[link heading bullet_list ordered_list blockquote]).freeze
PRESET_FULL =

Full preset with all available buttons.

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0

(FORMATTING_BUTTONS + BLOCK_BUTTONS + INSERT_BUTTONS).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style: :floating, buttons: nil, position: :top) ⇒ Toolbar

Initialize a new toolbar configuration.

Parameters:

  • style (Symbol) (defaults to: :floating)

    toolbar style (:floating, :fixed, :none)

  • buttons (Array<Symbol>, nil) (defaults to: nil)

    custom button list (defaults to preset)

  • position (Symbol) (defaults to: :top)

    toolbar position (:top, :bottom)

Since:

  • 0.1.0



81
82
83
84
85
# File 'lib/inkpen/toolbar.rb', line 81

def initialize(style: :floating, buttons: nil, position: :top)
  @style = style.to_sym
  @buttons = buttons || default_buttons_for_style
  @position = position.to_sym
end

Instance Attribute Details

#buttonsArray<Symbol> (readonly)

Returns list of toolbar buttons.

Returns:

  • (Array<Symbol>)

    list of toolbar buttons



42
# File 'lib/inkpen/toolbar.rb', line 42

attr_reader :style, :buttons, :position

#positionObject (readonly)

Since:

  • 0.1.0



42
# File 'lib/inkpen/toolbar.rb', line 42

attr_reader :style, :buttons, :position

#styleSymbol (readonly)

Returns toolbar display style (:floating, :fixed, :none).

Returns:

  • (Symbol)

    toolbar display style (:floating, :fixed, :none)



42
43
44
# File 'lib/inkpen/toolbar.rb', line 42

def style
  @style
end

Instance Method Details

#data_attributesHash

Generate data attributes for Stimulus controller.

Returns:

  • (Hash)

    data attributes hash

Since:

  • 0.1.0



119
120
121
122
123
124
125
# File 'lib/inkpen/toolbar.rb', line 119

def data_attributes
  {
    "inkpen--toolbar-style-value" => style.to_s,
    "inkpen--toolbar-buttons-value" => buttons.to_json,
    "inkpen--toolbar-position-value" => position.to_s
  }
end

#fixed?Boolean

Check if toolbar uses fixed style.

Returns:

  • (Boolean)

    true if fixed style

Since:

  • 0.1.0



101
102
103
# File 'lib/inkpen/toolbar.rb', line 101

def fixed?
  style == :fixed
end

#floating?Boolean

Check if toolbar uses floating (bubble menu) style.

Returns:

  • (Boolean)

    true if floating style

Since:

  • 0.1.0



92
93
94
# File 'lib/inkpen/toolbar.rb', line 92

def floating?
  style == :floating
end

#hidden?Boolean

Check if toolbar is hidden.

Returns:

  • (Boolean)

    true if toolbar is hidden

Since:

  • 0.1.0



110
111
112
# File 'lib/inkpen/toolbar.rb', line 110

def hidden?
  style == :none
end