Class: Lutaml::Xsd::Spa::ConfigurationLoader
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Spa::ConfigurationLoader
- Defined in:
- lib/lutaml/xsd/spa/configuration_loader.rb
Overview
Configuration loader for SPA documentation generator
Loads and validates YAML configuration files for UI theme, features, and templates. Provides type-safe access to configuration values with defaults fallback.
Constant Summary collapse
- DEFAULT_CONFIG_DIR =
Default configuration directory
File.( "../../../../config/spa", __dir__, )
Instance Attribute Summary collapse
-
#config_dir ⇒ Object
readonly
Returns the value of attribute config_dir.
Instance Method Summary collapse
-
#color(key, dark_mode: false) ⇒ String
Get color value from theme.
-
#feature_enabled?(feature) ⇒ Boolean
Check if a feature is enabled.
-
#feature_setting(feature, setting, default: nil) ⇒ Object
Get feature setting.
-
#features ⇒ Hash
(also: #load_features)
Load features configuration.
-
#initialize(config_dir: DEFAULT_CONFIG_DIR) ⇒ ConfigurationLoader
constructor
Initialize configuration loader.
-
#layout(key) ⇒ String
Get layout value from theme.
-
#partial_template(partial_name) ⇒ String?
Get partial template path.
-
#reload! ⇒ void
Reload all configurations (clears cache).
-
#template_components(layout_name: "default") ⇒ Array<String>
Get template layout components.
-
#templates ⇒ Hash
(also: #load_templates)
Load templates configuration.
-
#theme ⇒ Hash
(also: #load_ui_theme, #load_theme)
Load UI theme configuration.
-
#typography(key) ⇒ String
Get typography value from theme.
Constructor Details
#initialize(config_dir: DEFAULT_CONFIG_DIR) ⇒ ConfigurationLoader
Initialize configuration loader
35 36 37 38 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 35 def initialize(config_dir: DEFAULT_CONFIG_DIR) @config_dir = config_dir @cache = {} end |
Instance Attribute Details
#config_dir ⇒ Object (readonly)
Returns the value of attribute config_dir.
30 31 32 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 30 def config_dir @config_dir end |
Instance Method Details
#color(key, dark_mode: false) ⇒ String
Get color value from theme
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 70 def color(key, dark_mode: false) colors = if dark_mode theme.dig("theme", "dark_colors") else theme.dig("theme", "colors") end colors&.fetch(key, nil) || "#000000" end |
#feature_enabled?(feature) ⇒ Boolean
Check if a feature is enabled
101 102 103 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 101 def feature_enabled?(feature) features.dig("features", feature, "enabled") || false end |
#feature_setting(feature, setting, default: nil) ⇒ Object
Get feature setting
111 112 113 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 111 def feature_setting(feature, setting, default: nil) features.dig("features", feature, setting) || default end |
#features ⇒ Hash Also known as: load_features
Load features configuration
52 53 54 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 52 def features load_config("features", default_features) end |
#layout(key) ⇒ String
Get layout value from theme
93 94 95 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 93 def layout(key) theme.dig("theme", "layout", key) end |
#partial_template(partial_name) ⇒ String?
Get partial template path
127 128 129 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 127 def partial_template(partial_name) templates.dig("templates", "partials", partial_name, "template") end |
#reload! ⇒ void
This method returns an undefined value.
Reload all configurations (clears cache)
134 135 136 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 134 def reload! @cache.clear end |
#template_components(layout_name: "default") ⇒ Array<String>
Get template layout components
119 120 121 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 119 def template_components(layout_name: "default") templates.dig("templates", "layouts", layout_name, "components") || [] end |
#templates ⇒ Hash Also known as: load_templates
Load templates configuration
60 61 62 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 60 def templates load_config("templates", default_templates) end |
#theme ⇒ Hash Also known as: load_ui_theme, load_theme
Load UI theme configuration
43 44 45 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 43 def theme load_config("ui_theme", default_theme) end |
#typography(key) ⇒ String
Get typography value from theme
85 86 87 |
# File 'lib/lutaml/xsd/spa/configuration_loader.rb', line 85 def typography(key) theme.dig("theme", "typography", key) end |