Class: Inkpen::Extensions::Section
- 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).
Constant Summary collapse
- WIDTH_PRESETS =
Available width presets with their CSS values.
{ 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.
{ 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
Instance Method Summary collapse
-
#default_spacing ⇒ String
Default spacing preset for new sections.
-
#default_width ⇒ String
Default width preset for new sections.
-
#name ⇒ Symbol
The unique name of this extension.
-
#show_controls? ⇒ Boolean
Whether to show the section controls UI.
-
#spacing_presets ⇒ Hash
Available spacing presets.
-
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
-
#width_presets ⇒ Hash
Available width presets.
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_spacing ⇒ String
Default spacing preset for new sections.
67 68 69 |
# File 'lib/inkpen/extensions/section.rb', line 67 def default_spacing .fetch(:default_spacing, "normal") end |
#default_width ⇒ String
Default width preset for new sections.
58 59 60 |
# File 'lib/inkpen/extensions/section.rb', line 58 def default_width .fetch(:default_width, "default") end |
#name ⇒ Symbol
The unique name of this extension.
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.
76 77 78 |
# File 'lib/inkpen/extensions/section.rb', line 76 def show_controls? .fetch(:show_controls, true) end |
#spacing_presets ⇒ Hash
Available spacing presets.
95 96 97 98 |
# File 'lib/inkpen/extensions/section.rb', line 95 def spacing_presets custom_presets = [:spacing_presets] || {} SPACING_PRESETS.merge(custom_presets.transform_keys(&:to_sym)) end |
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
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_presets ⇒ Hash
Available width presets.
85 86 87 88 |
# File 'lib/inkpen/extensions/section.rb', line 85 def width_presets custom_presets = [:width_presets] || {} WIDTH_PRESETS.merge(custom_presets.transform_keys(&:to_sym)) end |