Class: Coradoc::Html::Static::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

Initialize configuration with options

Parameters:

  • options (Hash)

    Configuration 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(**options)
  @css_theme = options[:css_theme] || :professional
  @asset_delivery = options[:asset_delivery] || :embedded
  @include_toc = options.fetch(:include_toc, false)
  @toc_levels = options[:toc_levels] || 2
  @toc_title = options[:toc_title] || 'Table of Contents'
  @toc_placement = options[:toc_placement] || :auto
  @theme_toggle = options.fetch(:theme_toggle, true)
  @preserve_comments = options.fetch(:preserve_comments, false)
  @section_numbering = options.fetch(:section_numbering, false)
  @section_numbering_levels = options[:section_numbering_levels] || 3
  @lang = options[:lang] || 'en'
  @meta_tags = options[:meta_tags] || {}
  @custom_css = options[:custom_css]
  @embedded = options.fetch(:embedded, false)
end

Instance Attribute Details

#asset_deliveryObject

How to deliver assets (:embedded, :external)



35
36
37
# File 'lib/coradoc/html/static.rb', line 35

def asset_delivery
  @asset_delivery
end

#css_themeObject

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_cssObject

Custom CSS to append



68
69
70
# File 'lib/coradoc/html/static.rb', line 68

def custom_css
  @custom_css
end

#embeddedObject

Whether to embed output (no full HTML document)



71
72
73
# File 'lib/coradoc/html/static.rb', line 71

def embedded
  @embedded
end

#include_tocObject

Whether to include table of contents



38
39
40
# File 'lib/coradoc/html/static.rb', line 38

def include_toc
  @include_toc
end

#langObject

Language attribute for HTML



62
63
64
# File 'lib/coradoc/html/static.rb', line 62

def lang
  @lang
end

#meta_tagsObject

Custom meta tags



65
66
67
# File 'lib/coradoc/html/static.rb', line 65

def meta_tags
  @meta_tags
end

#preserve_commentsObject

Whether to preserve comments in output



53
54
55
# File 'lib/coradoc/html/static.rb', line 53

def preserve_comments
  @preserve_comments
end

#section_numberingObject

Whether to apply section numbering



56
57
58
# File 'lib/coradoc/html/static.rb', line 56

def section_numbering
  @section_numbering
end

#section_numbering_levelsObject

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_toggleObject

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_levelsObject

TOC levels to include (1-5)



41
42
43
# File 'lib/coradoc/html/static.rb', line 41

def toc_levels
  @toc_levels
end

#toc_placementObject

TOC placement (:auto, :left, :right, :preamble)



47
48
49
# File 'lib/coradoc/html/static.rb', line 47

def toc_placement
  @toc_placement
end

#toc_titleObject

TOC title text



44
45
46
# File 'lib/coradoc/html/static.rb', line 44

def toc_title
  @toc_title
end

Class Method Details

.defaultsConfiguration

Default configuration

Returns:



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

Returns:

  • (Boolean)

    true if assets should be embedded



177
178
179
# File 'lib/coradoc/html/static.rb', line 177

def embed_assets?
  @asset_delivery == :embedded || @embedded
end

Check if external assets should be linked

Returns:

  • (Boolean)

    true if assets should be linked



184
185
186
# File 'lib/coradoc/html/static.rb', line 184

def link_assets?
  !embed_assets?
end

#merge(other) ⇒ Configuration

Merge with another configuration or hash

Parameters:

Returns:



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_hHash

Convert to hash

Returns:

  • (Hash)

    Configuration as 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

Raises:



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