Class: Coradoc::Html::Static::Configuration
- Inherits:
-
Object
- Object
- Coradoc::Html::Static::Configuration
- Defined in:
- lib/coradoc/html/static.rb
Overview
Configuration for Static HTML output
Plain Ruby configuration class with accessors and defaults.
Constant Summary collapse
- VALID_CSS_THEMES =
Valid CSS themes
%i[professional academic tech].freeze
- VALID_ASSET_DELIVERIES =
Valid asset delivery methods
%i[embedded external].freeze
- VALID_TOC_PLACEMENTS =
Valid TOC placements
%i[auto left right preamble].freeze
Instance Attribute Summary collapse
-
#asset_delivery ⇒ Object
How to deliver assets (:embedded, :external).
-
#css_theme ⇒ Object
CSS theme to use (:professional, :academic, :tech).
-
#custom_css ⇒ Object
Custom CSS to append.
-
#embedded ⇒ Object
Whether to embed output (no full HTML document).
-
#include_toc ⇒ Object
Whether to include table of contents.
-
#lang ⇒ Object
Language attribute for HTML.
-
#meta_tags ⇒ Object
Custom meta tags.
-
#preserve_comments ⇒ Object
Whether to preserve comments in output.
-
#section_numbering ⇒ Object
Whether to apply section numbering.
-
#section_numbering_levels ⇒ Object
Maximum section level for numbering.
-
#theme_toggle ⇒ Object
Whether to enable theme toggle (dark/light mode).
-
#toc_levels ⇒ Object
TOC levels to include (1-5).
-
#toc_placement ⇒ Object
TOC placement (:auto, :left, :right, :preamble).
-
#toc_title ⇒ Object
TOC title text.
Class Method Summary collapse
-
.defaults ⇒ Configuration
Default configuration.
Instance Method Summary collapse
-
#embed_assets? ⇒ Boolean
Check if assets should be embedded.
-
#initialize(**options) ⇒ Configuration
constructor
Initialize configuration with options.
-
#link_assets? ⇒ Boolean
Check if external assets should be linked.
-
#merge(other) ⇒ Configuration
Merge with another configuration or hash.
-
#to_h ⇒ Hash
Convert to hash.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize(**options) ⇒ Configuration
Initialize configuration with options
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/coradoc/html/static.rb', line 85 def initialize(**) @css_theme = [:css_theme] || :professional @asset_delivery = [:asset_delivery] || :embedded @include_toc = .fetch(:include_toc, false) @toc_levels = [:toc_levels] || 2 @toc_title = [:toc_title] || 'Table of Contents' @toc_placement = [:toc_placement] || :auto @theme_toggle = .fetch(:theme_toggle, true) @preserve_comments = .fetch(:preserve_comments, false) @section_numbering = .fetch(:section_numbering, false) @section_numbering_levels = [:section_numbering_levels] || 3 @lang = [:lang] || 'en' @meta_tags = [:meta_tags] || {} @custom_css = [:custom_css] @embedded = .fetch(:embedded, false) end |
Instance Attribute Details
#asset_delivery ⇒ Object
How to deliver assets (:embedded, :external)
35 36 37 |
# File 'lib/coradoc/html/static.rb', line 35 def asset_delivery @asset_delivery end |
#css_theme ⇒ Object
CSS theme to use (:professional, :academic, :tech)
32 33 34 |
# File 'lib/coradoc/html/static.rb', line 32 def css_theme @css_theme end |
#custom_css ⇒ Object
Custom CSS to append
68 69 70 |
# File 'lib/coradoc/html/static.rb', line 68 def custom_css @custom_css end |
#embedded ⇒ Object
Whether to embed output (no full HTML document)
71 72 73 |
# File 'lib/coradoc/html/static.rb', line 71 def @embedded end |
#include_toc ⇒ Object
Whether to include table of contents
38 39 40 |
# File 'lib/coradoc/html/static.rb', line 38 def include_toc @include_toc end |
#lang ⇒ Object
Language attribute for HTML
62 63 64 |
# File 'lib/coradoc/html/static.rb', line 62 def lang @lang end |
#meta_tags ⇒ Object
Custom meta tags
65 66 67 |
# File 'lib/coradoc/html/static.rb', line 65 def @meta_tags end |
#preserve_comments ⇒ Object
Whether to preserve comments in output
53 54 55 |
# File 'lib/coradoc/html/static.rb', line 53 def preserve_comments @preserve_comments end |
#section_numbering ⇒ Object
Whether to apply section numbering
56 57 58 |
# File 'lib/coradoc/html/static.rb', line 56 def section_numbering @section_numbering end |
#section_numbering_levels ⇒ Object
Maximum section level for numbering
59 60 61 |
# File 'lib/coradoc/html/static.rb', line 59 def section_numbering_levels @section_numbering_levels end |
#theme_toggle ⇒ Object
Whether to enable theme toggle (dark/light mode)
50 51 52 |
# File 'lib/coradoc/html/static.rb', line 50 def theme_toggle @theme_toggle end |
#toc_levels ⇒ Object
TOC levels to include (1-5)
41 42 43 |
# File 'lib/coradoc/html/static.rb', line 41 def toc_levels @toc_levels end |
#toc_placement ⇒ Object
TOC placement (:auto, :left, :right, :preamble)
47 48 49 |
# File 'lib/coradoc/html/static.rb', line 47 def toc_placement @toc_placement end |
#toc_title ⇒ Object
TOC title text
44 45 46 |
# File 'lib/coradoc/html/static.rb', line 44 def toc_title @toc_title end |
Class Method Details
.defaults ⇒ Configuration
Default configuration
105 106 107 |
# File 'lib/coradoc/html/static.rb', line 105 def self.defaults new end |
Instance Method Details
#embed_assets? ⇒ Boolean
Check if assets should be embedded
177 178 179 |
# File 'lib/coradoc/html/static.rb', line 177 def @asset_delivery == :embedded || @embedded end |
#link_assets? ⇒ Boolean
Check if external assets should be linked
184 185 186 |
# File 'lib/coradoc/html/static.rb', line 184 def link_assets? ! end |
#merge(other) ⇒ Configuration
Merge with another configuration or hash
113 114 115 116 |
# File 'lib/coradoc/html/static.rb', line 113 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/coradoc/html/static.rb', line 121 def to_h { css_theme: @css_theme, asset_delivery: @asset_delivery, include_toc: @include_toc, toc_levels: @toc_levels, toc_title: @toc_title, toc_placement: @toc_placement, theme_toggle: @theme_toggle, preserve_comments: @preserve_comments, section_numbering: @section_numbering, section_numbering_levels: @section_numbering_levels, lang: @lang, meta_tags: @meta_tags, custom_css: @custom_css, embedded: @embedded } end |
#validate! ⇒ Object
Validate configuration
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/coradoc/html/static.rb', line 143 def validate! unless VALID_CSS_THEMES.include?(@css_theme.to_sym) raise ConverterBase::ValidationError, "Invalid CSS theme: #{@css_theme}. " \ "Valid themes: #{VALID_CSS_THEMES.join(', ')}" end unless VALID_ASSET_DELIVERIES.include?(@asset_delivery.to_sym) raise ConverterBase::ValidationError, "Invalid asset delivery: #{@asset_delivery}. " \ "Valid options: #{VALID_ASSET_DELIVERIES.join(', ')}" end if @include_toc && !VALID_TOC_PLACEMENTS.include?(@toc_placement.to_sym) raise ConverterBase::ValidationError, "Invalid TOC placement: #{@toc_placement}. " \ "Valid options: #{VALID_TOC_PLACEMENTS.join(', ')}" end unless @toc_levels.is_a?(Integer) && @toc_levels.between?(1, 5) raise ConverterBase::ValidationError, 'TOC levels must be an integer between 1 and 5' end unless @section_numbering_levels.is_a?(Integer) && @section_numbering_levels.between?(1, 6) raise ConverterBase::ValidationError, 'Section numbering levels must be an integer between 1 and 6' end end |