Class: Coradoc::Html::Spa::Configuration
- Inherits:
-
Object
- Object
- Coradoc::Html::Spa::Configuration
- Defined in:
- lib/coradoc/html/spa.rb
Overview
Configuration for SPA HTML output
Plain Ruby configuration class with accessors and defaults.
Constant Summary collapse
- VALID_THEME_VARIANTS =
Valid theme variants
%i[glass minimal vibrant].freeze
Instance Attribute Summary collapse
-
#accent_color ⇒ Object
Accent color (hex string, e.g., ‘#8b5cf6’).
-
#animation_duration ⇒ Object
Animation duration (CSS value, e.g., ‘300ms’).
-
#asset_delivery ⇒ Object
How to deliver assets (:embedded always for SPA).
-
#back_to_top ⇒ Object
Whether to show back to top button.
-
#content_width ⇒ Object
Content width (CSS value).
-
#copy_code_buttons ⇒ Object
Whether to add copy buttons to code blocks.
-
#enable_animations ⇒ Object
Whether to enable animations.
-
#lang ⇒ Object
Language attribute for HTML.
-
#lazy_load_images ⇒ Object
Whether to lazy load images.
-
#max_width ⇒ Object
Maximum width of the container (CSS value).
-
#meta_description ⇒ Object
Custom meta description.
-
#meta_keywords ⇒ Object
Custom meta keywords.
-
#open_graph ⇒ Object
Enable Open Graph meta tags.
-
#primary_color ⇒ Object
Primary color (hex string, e.g., ‘#6366f1’).
-
#reading_progress ⇒ Object
Whether to show reading progress bar.
-
#sidebar_width ⇒ Object
Sidebar width for TOC (CSS value).
-
#theme_toggle ⇒ Object
Whether to enable theme toggle (dark/light mode).
-
#theme_variant ⇒ Object
Theme appearance variant (:glass, :minimal, :vibrant).
-
#toc_levels ⇒ Object
TOC levels to include (1-5).
-
#toc_sticky ⇒ Object
Whether TOC should be sticky.
-
#toc_title ⇒ Object
TOC title text.
Class Method Summary collapse
-
.defaults ⇒ Configuration
Default configuration.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Configuration
constructor
Initialize configuration with options.
-
#merge(other) ⇒ Configuration
Merge with another configuration or hash.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_renderer_options ⇒ Hash
Convert to options hash for ModernRenderer.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize(**options) ⇒ Configuration
Initialize configuration with options
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/coradoc/html/spa.rb', line 111 def initialize(**) @asset_delivery = [:asset_delivery] || :embedded @theme_variant = [:theme_variant] || :glass @primary_color = [:primary_color] || '#6366f1' @accent_color = [:accent_color] || '#8b5cf6' @theme_toggle = .fetch(:theme_toggle, true) @reading_progress = .fetch(:reading_progress, true) @back_to_top = .fetch(:back_to_top, true) @toc_sticky = .fetch(:toc_sticky, true) @copy_code_buttons = .fetch(:copy_code_buttons, true) @toc_levels = [:toc_levels] || 2 @toc_title = [:toc_title] || 'Table of Contents' @enable_animations = .fetch(:enable_animations, true) @animation_duration = [:animation_duration] || '300ms' @lazy_load_images = .fetch(:lazy_load_images, true) @max_width = [:max_width] || '1200px' @content_width = [:content_width] || '65ch' @sidebar_width = [:sidebar_width] || '280px' @lang = [:lang] || 'en' @meta_description = [:meta_description] @meta_keywords = [:meta_keywords] @open_graph = .fetch(:open_graph, false) end |
Instance Attribute Details
#accent_color ⇒ Object
Accent color (hex string, e.g., ‘#8b5cf6’)
52 53 54 |
# File 'lib/coradoc/html/spa.rb', line 52 def accent_color @accent_color end |
#animation_duration ⇒ Object
Animation duration (CSS value, e.g., ‘300ms’)
79 80 81 |
# File 'lib/coradoc/html/spa.rb', line 79 def animation_duration @animation_duration end |
#asset_delivery ⇒ Object
How to deliver assets (:embedded always for SPA)
43 44 45 |
# File 'lib/coradoc/html/spa.rb', line 43 def asset_delivery @asset_delivery end |
#back_to_top ⇒ Object
Whether to show back to top button
61 62 63 |
# File 'lib/coradoc/html/spa.rb', line 61 def back_to_top @back_to_top end |
#content_width ⇒ Object
Content width (CSS value)
88 89 90 |
# File 'lib/coradoc/html/spa.rb', line 88 def content_width @content_width end |
#copy_code_buttons ⇒ Object
Whether to add copy buttons to code blocks
67 68 69 |
# File 'lib/coradoc/html/spa.rb', line 67 def @copy_code_buttons end |
#enable_animations ⇒ Object
Whether to enable animations
76 77 78 |
# File 'lib/coradoc/html/spa.rb', line 76 def enable_animations @enable_animations end |
#lang ⇒ Object
Language attribute for HTML
94 95 96 |
# File 'lib/coradoc/html/spa.rb', line 94 def lang @lang end |
#lazy_load_images ⇒ Object
Whether to lazy load images
82 83 84 |
# File 'lib/coradoc/html/spa.rb', line 82 def lazy_load_images @lazy_load_images end |
#max_width ⇒ Object
Maximum width of the container (CSS value)
85 86 87 |
# File 'lib/coradoc/html/spa.rb', line 85 def max_width @max_width end |
#meta_description ⇒ Object
Custom meta description
97 98 99 |
# File 'lib/coradoc/html/spa.rb', line 97 def @meta_description end |
#meta_keywords ⇒ Object
Custom meta keywords
100 101 102 |
# File 'lib/coradoc/html/spa.rb', line 100 def @meta_keywords end |
#open_graph ⇒ Object
Enable Open Graph meta tags
103 104 105 |
# File 'lib/coradoc/html/spa.rb', line 103 def open_graph @open_graph end |
#primary_color ⇒ Object
Primary color (hex string, e.g., ‘#6366f1’)
49 50 51 |
# File 'lib/coradoc/html/spa.rb', line 49 def primary_color @primary_color end |
#reading_progress ⇒ Object
Whether to show reading progress bar
58 59 60 |
# File 'lib/coradoc/html/spa.rb', line 58 def reading_progress @reading_progress end |
#sidebar_width ⇒ Object
Sidebar width for TOC (CSS value)
91 92 93 |
# File 'lib/coradoc/html/spa.rb', line 91 def @sidebar_width end |
#theme_toggle ⇒ Object
Whether to enable theme toggle (dark/light mode)
55 56 57 |
# File 'lib/coradoc/html/spa.rb', line 55 def theme_toggle @theme_toggle end |
#theme_variant ⇒ Object
Theme appearance variant (:glass, :minimal, :vibrant)
46 47 48 |
# File 'lib/coradoc/html/spa.rb', line 46 def theme_variant @theme_variant end |
#toc_levels ⇒ Object
TOC levels to include (1-5)
70 71 72 |
# File 'lib/coradoc/html/spa.rb', line 70 def toc_levels @toc_levels end |
#toc_sticky ⇒ Object
Whether TOC should be sticky
64 65 66 |
# File 'lib/coradoc/html/spa.rb', line 64 def toc_sticky @toc_sticky end |
#toc_title ⇒ Object
TOC title text
73 74 75 |
# File 'lib/coradoc/html/spa.rb', line 73 def toc_title @toc_title end |
Class Method Details
.defaults ⇒ Configuration
Default configuration
138 139 140 |
# File 'lib/coradoc/html/spa.rb', line 138 def self.defaults new end |
Instance Method Details
#merge(other) ⇒ Configuration
Merge with another configuration or hash
146 147 148 149 |
# File 'lib/coradoc/html/spa.rb', line 146 def merge(other) other_hash = other.is_a?(Configuration) ? other.to_h : other.to_h.transform_keys(&:to_sym) self.class.new(**to_h.merge(other_hash)) end |
#to_h ⇒ Hash
Convert to hash
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/coradoc/html/spa.rb', line 154 def to_h { asset_delivery: @asset_delivery, theme_variant: @theme_variant, primary_color: @primary_color, accent_color: @accent_color, theme_toggle: @theme_toggle, reading_progress: @reading_progress, back_to_top: @back_to_top, toc_sticky: @toc_sticky, copy_code_buttons: @copy_code_buttons, toc_levels: @toc_levels, toc_title: @toc_title, enable_animations: @enable_animations, animation_duration: @animation_duration, lazy_load_images: @lazy_load_images, max_width: @max_width, content_width: @content_width, sidebar_width: @sidebar_width, lang: @lang, meta_description: @meta_description, meta_keywords: @meta_keywords, open_graph: @open_graph } end |
#to_renderer_options ⇒ Hash
Convert to options hash for ModernRenderer
206 207 208 209 210 211 212 213 214 |
# File 'lib/coradoc/html/spa.rb', line 206 def { modern: to_h, lang: @lang, toc: @toc_sticky, toclevels: @toc_levels, toc_title: @toc_title } end |
#validate! ⇒ Object
Validate configuration
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/coradoc/html/spa.rb', line 183 def validate! validate_hex_color(@primary_color, 'primary_color') validate_hex_color(@accent_color, 'accent_color') validate_css_value(@max_width, 'max_width') validate_css_value(@content_width, 'content_width') validate_css_value(@sidebar_width, 'sidebar_width') validate_css_value(@animation_duration, 'animation_duration') unless VALID_THEME_VARIANTS.include?(@theme_variant.to_sym) raise ConverterBase::ValidationError, "Invalid theme variant: #{@theme_variant}. " \ "Valid variants: #{VALID_THEME_VARIANTS.join(', ')}" end return if @toc_levels.is_a?(Integer) && @toc_levels.between?(1, 5) raise ConverterBase::ValidationError, 'TOC levels must be an integer between 1 and 5' end |