Class: Inkpen::Extensions::Section

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

Overview

Section extension for TipTap.

Block-level container that controls content width and vertical spacing. Useful for page-builder style layouts where different sections need different widths (narrow for reading, wide for media, full for heroes).

Examples:

Basic usage

extension = Inkpen::Extensions::Section.new

With custom options

extension = Inkpen::Extensions::Section.new(
  default_width: "wide",
  default_spacing: "spacious",
  show_controls: true
)

See Also:

Author:

  • Inkpen Team

Since:

  • 0.3.0

Constant Summary collapse

WIDTH_PRESETS =

Available width presets with their CSS values.

Since:

  • 0.3.0

{
  narrow: { max_width: "560px", label: "Narrow" },
  default: { max_width: "680px", label: "Default" },
  wide: { max_width: "900px", label: "Wide" },
  full: { max_width: "100%", label: "Full" }
}.freeze
SPACING_PRESETS =

Available spacing presets with their CSS values.

Since:

  • 0.3.0

{
  compact: { padding: "1rem 0", label: "Compact" },
  normal: { padding: "2rem 0", label: "Normal" },
  spacious: { padding: "4rem 0", label: "Spacious" }
}.freeze

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

#default_spacingString

Default spacing preset for new sections.

Returns:

  • (String)

    the default spacing preset key

Since:

  • 0.3.0



67
68
69
# File 'lib/inkpen/extensions/section.rb', line 67

def default_spacing
  options.fetch(:default_spacing, "normal")
end

#default_widthString

Default width preset for new sections.

Returns:

  • (String)

    the default width preset key

Since:

  • 0.3.0



58
59
60
# File 'lib/inkpen/extensions/section.rb', line 58

def default_width
  options.fetch(:default_width, "default")
end

#nameSymbol

The unique name of this extension.

Returns:

  • (Symbol)

    :section

Since:

  • 0.3.0



49
50
51
# File 'lib/inkpen/extensions/section.rb', line 49

def name
  :section
end

#show_controls?Boolean

Whether to show the section controls UI.

Returns:

  • (Boolean)

    true to show controls

Since:

  • 0.3.0



76
77
78
# File 'lib/inkpen/extensions/section.rb', line 76

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

#spacing_presetsHash

Available spacing presets.

Returns:

  • (Hash)

    spacing presets with padding and label

Since:

  • 0.3.0



95
96
97
98
# File 'lib/inkpen/extensions/section.rb', line 95

def spacing_presets
  custom_presets = options[:spacing_presets] || {}
  SPACING_PRESETS.merge(custom_presets.transform_keys(&:to_sym))
end

#to_configHash

Convert to configuration hash for JavaScript.

Returns:

  • (Hash)

    configuration for the TipTap extension

Since:

  • 0.3.0



105
106
107
108
109
110
111
112
113
# File 'lib/inkpen/extensions/section.rb', line 105

def to_config
  {
    defaultWidth: default_width,
    defaultSpacing: default_spacing,
    showControls: show_controls?,
    widthPresets: serialize_presets(width_presets),
    spacingPresets: serialize_presets(spacing_presets)
  }
end

#width_presetsHash

Available width presets.

Returns:

  • (Hash)

    width presets with max_width and label

Since:

  • 0.3.0



85
86
87
88
# File 'lib/inkpen/extensions/section.rb', line 85

def width_presets
  custom_presets = options[:width_presets] || {}
  WIDTH_PRESETS.merge(custom_presets.transform_keys(&:to_sym))
end