Class: Ea::Theme::Registry
- Inherits:
-
Object
- Object
- Ea::Theme::Registry
- Defined in:
- lib/ea/theme/registry.rb
Overview
Central registry for theme Definitions. Lookup by ID returns a fully configured Definition object. Adding a new theme = registering it (OCP) — no existing code modified.
Built-in themes are auto-loaded from config/themes/*.yml on
first access.
Usage:
Ea::Theme::Registry.lookup(":119") # → Definition
Ea::Theme::Registry.register(my_def)
Ea::Theme::Registry.all # → [Definition, ...]
Constant Summary collapse
- CONFIG_DIR =
File.("../../../config/themes", __dir__)
Class Method Summary collapse
-
.all ⇒ Array<Ea::Theme::Definition>
Returns all registered themes.
-
.default ⇒ Ea::Theme::Definition
The default theme (no overrides, element-stored values).
-
.load_dir(dir) ⇒ Object
Load themes from a directory of YAML files.
-
.lookup(theme_id) ⇒ Ea::Theme::Definition
Look up a theme by ID.
-
.register(definition) ⇒ Object
Register a new theme.
Class Method Details
.all ⇒ Array<Ea::Theme::Definition>
Returns all registered themes.
24 25 26 |
# File 'lib/ea/theme/registry.rb', line 24 def all themes.values end |
.default ⇒ Ea::Theme::Definition
The default theme (no overrides, element-stored values).
55 56 57 58 |
# File 'lib/ea/theme/registry.rb', line 55 def default ensure_loaded @themes["default"] end |
.load_dir(dir) ⇒ Object
Load themes from a directory of YAML files. Each .yml file produces one Definition.
63 64 65 66 |
# File 'lib/ea/theme/registry.rb', line 63 def load_dir(dir) ensure_loaded Loader.load_dir(dir).each { |d| @themes[d.id] = d } end |
.lookup(theme_id) ⇒ Ea::Theme::Definition
Look up a theme by ID. Returns the default theme when the ID is nil, empty, or unknown.
EA stores theme IDs with a leading colon (":119"). The lookup normalizes by stripping the colon.
36 37 38 39 40 41 42 |
# File 'lib/ea/theme/registry.rb', line 36 def lookup(theme_id) ensure_loaded return default if theme_id.nil? || theme_id.to_s.empty? key = normalize_key(theme_id) @themes[key] || default end |
.register(definition) ⇒ Object
Register a new theme. Adding a theme does NOT modify existing code (OCP).
48 49 50 51 |
# File 'lib/ea/theme/registry.rb', line 48 def register(definition) ensure_loaded @themes[definition.id] = definition end |