Class: Inkpen::Extensions::DocumentSection

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

Overview

DocumentSection extension for TipTap.

Provides true content grouping with a semantic H2 title and collapsible content. Unlike the layout Section extension (which controls width/spacing), DocumentSection groups related blocks under a heading for document structure.

Features:

  • Semantic H2 title (integrates with Table of Contents)

  • Collapsible content with left-gutter toggle

  • Nesting support (sections within sections, up to 3 levels)

  • Draggable as a group

  • Auto-generated IDs for deep linking

Examples:

Basic usage

extension = Inkpen::Extensions::DocumentSection.new

With custom options

extension = Inkpen::Extensions::DocumentSection.new(
  default_collapsed: false,
  allow_nesting: true,
  max_depth: 3,
  show_controls: true
)

See Also:

Author:

  • Inkpen Team

Since:

  • 0.8.0

Constant Summary collapse

DEFAULT_MAX_DEPTH =

Default maximum nesting depth for sections.

Since:

  • 0.8.0

3

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

#allow_nesting?Boolean

Whether sections can be nested within each other.

Returns:

  • (Boolean)

    true to allow nesting

Since:

  • 0.8.0



62
63
64
# File 'lib/inkpen/extensions/document_section.rb', line 62

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

#default_collapsedBoolean

Default collapsed state for new sections.

Returns:

  • (Boolean)

    true if sections start collapsed

Since:

  • 0.8.0



53
54
55
# File 'lib/inkpen/extensions/document_section.rb', line 53

def default_collapsed
  options.fetch(:default_collapsed, false)
end

#max_depthInteger

Maximum nesting depth for sections.

Returns:

  • (Integer)

    maximum depth allowed (1-3)

Since:

  • 0.8.0



71
72
73
74
# File 'lib/inkpen/extensions/document_section.rb', line 71

def max_depth
  depth = options.fetch(:max_depth, DEFAULT_MAX_DEPTH)
  [[depth, 1].max, 3].min # Clamp between 1 and 3
end

#nameSymbol

The unique name of this extension.

Returns:

  • (Symbol)

    :document_section

Since:

  • 0.8.0



44
45
46
# File 'lib/inkpen/extensions/document_section.rb', line 44

def name
  :document_section
end

#show_controls?Boolean

Whether to show the collapse toggle control.

Returns:

  • (Boolean)

    true to show controls

Since:

  • 0.8.0



81
82
83
# File 'lib/inkpen/extensions/document_section.rb', line 81

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

#to_configHash

Convert to configuration hash for JavaScript.

Returns:

  • (Hash)

    configuration for the TipTap extension

Since:

  • 0.8.0



90
91
92
93
94
95
96
97
# File 'lib/inkpen/extensions/document_section.rb', line 90

def to_config
  {
    defaultCollapsed: default_collapsed,
    allowNesting: allow_nesting?,
    maxDepth: max_depth,
    showControls: show_controls?
  }
end