Class: Inkpen::Extensions::TaskList

Inherits:
Base
  • Object
show all
Defined in:
lib/inkpen/extensions/task_list.rb

Overview

Task List extension for TipTap.

Enables interactive checkbox/task list functionality. Users can create todo lists with checkable items that persist their state.

Examples:

Basic usage

extension = Inkpen::Extensions::TaskList.new

With nested tasks disabled

extension = Inkpen::Extensions::TaskList.new(
  nested: false,
  item_class: "my-task-item"
)

See Also:

Author:

  • Inkpen Team

Since:

  • 0.2.0

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#enabled?, #initialize, #to_h, #to_json

Constructor Details

This class inherits a constructor from Inkpen::Extensions::Base

Instance Method Details

#checkbox_classString

CSS class applied to the checkbox element.

Returns:

  • (String)

    CSS class name

Since:

  • 0.2.0



75
76
77
# File 'lib/inkpen/extensions/task_list.rb', line 75

def checkbox_class
  options.fetch(:checkbox_class, "inkpen-task-checkbox")
end

#checked_classString

CSS class applied to checked task items.

Returns:

  • (String)

    CSS class name

Since:

  • 0.2.0



66
67
68
# File 'lib/inkpen/extensions/task_list.rb', line 66

def checked_class
  options.fetch(:checked_class, "inkpen-task-checked")
end

#html_attributesHash

HTML attributes for the task list element.

Returns:

  • (Hash)

    HTML attributes

Since:

  • 0.2.0



84
85
86
# File 'lib/inkpen/extensions/task_list.rb', line 84

def html_attributes
  options.fetch(:html_attributes, { class: list_class })
end

#item_classString

CSS class applied to individual task items.

Returns:

  • (String)

    CSS class name

Since:

  • 0.2.0



57
58
59
# File 'lib/inkpen/extensions/task_list.rb', line 57

def item_class
  options.fetch(:item_class, "inkpen-task-item")
end

#item_html_attributesHash

HTML attributes for task item elements.

Returns:

  • (Hash)

    HTML attributes

Since:

  • 0.2.0



93
94
95
# File 'lib/inkpen/extensions/task_list.rb', line 93

def item_html_attributes
  options.fetch(:item_html_attributes, { class: item_class })
end

#keyboard_shortcutString

Keyboard shortcut to create a task list.

Returns:

  • (String)

    keyboard shortcut

Since:

  • 0.2.0



111
112
113
# File 'lib/inkpen/extensions/task_list.rb', line 111

def keyboard_shortcut
  options.fetch(:keyboard_shortcut, "Mod-Shift-9")
end

#list_classString

CSS class applied to task list container.

Returns:

  • (String)

    CSS class name

Since:

  • 0.2.0



48
49
50
# File 'lib/inkpen/extensions/task_list.rb', line 48

def list_class
  options.fetch(:list_class, "inkpen-task-list")
end

#nameSymbol

The unique name of this extension.

Returns:

  • (Symbol)

    :task_list

Since:

  • 0.2.0



30
31
32
# File 'lib/inkpen/extensions/task_list.rb', line 30

def name
  :task_list
end

#nested?Boolean

Whether task lists can be nested.

Returns:

  • (Boolean)

    true to allow nested task lists

Since:

  • 0.2.0



39
40
41
# File 'lib/inkpen/extensions/task_list.rb', line 39

def nested?
  options.fetch(:nested, true)
end

#text_toggle?Boolean

Whether clicking on the text toggles the checkbox.

Returns:

  • (Boolean)

    true if text click toggles checkbox

Since:

  • 0.2.0



102
103
104
# File 'lib/inkpen/extensions/task_list.rb', line 102

def text_toggle?
  options.fetch(:text_toggle, false)
end

#to_configHash

Convert to configuration hash for JavaScript.

Returns:

  • (Hash)

    configuration for the TipTap extension

Since:

  • 0.2.0



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/inkpen/extensions/task_list.rb', line 120

def to_config
  {
    nested: nested?,
    listClass: list_class,
    itemClass: item_class,
    checkedClass: checked_class,
    checkboxClass: checkbox_class,
    HTMLAttributes: html_attributes,
    itemHTMLAttributes: item_html_attributes,
    textToggle: text_toggle?,
    keyboardShortcut: keyboard_shortcut
  }
end