Class: Canon::DiffFormatter::Theme::Resolver
- Inherits:
-
Object
- Object
- Canon::DiffFormatter::Theme::Resolver
- Defined in:
- lib/canon/diff_formatter/theme.rb
Overview
Resolves the actual theme hash from configuration. Priority:
-
ENV (highest)
-
config.xml.diff.theme
-
:dark default
Also supports:
-
Theme inheritance via config.xml.diff.theme_inheritance
-
Custom theme via config.xml.diff.custom_theme
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ Resolver
constructor
Initialize with a config object (optional).
-
#resolve ⇒ Hash
Resolve the theme hash to use for rendering.
-
#theme_name ⇒ Symbol
Get theme by name from ENV or config.
Constructor Details
#initialize(config = nil) ⇒ Resolver
Initialize with a config object (optional)
788 789 790 |
# File 'lib/canon/diff_formatter/theme.rb', line 788 def initialize(config = nil) @config = config end |
Instance Method Details
#resolve ⇒ Hash
Resolve the theme hash to use for rendering
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
# File 'lib/canon/diff_formatter/theme.rb', line 794 def resolve # Check ENV first env_theme = resolve_from_env return env_theme if env_theme # Check config theme_inheritance (custom theme with base + overrides) if @config.respond_to?(:xml) && @config.xml.diff.respond_to?(:theme_inheritance) inheritance = @config.xml.diff.theme_inheritance return resolve_inheritance_theme(inheritance) if inheritance end # Check config custom_theme (full custom theme hash) if @config.respond_to?(:xml) && @config.xml.diff.respond_to?(:custom_theme) custom = @config.xml.diff.custom_theme return custom if custom.is_a?(Hash) && !custom.empty? end # Check config theme name if @config.respond_to?(:xml) && @config.xml.diff.respond_to?(:theme) theme_name = @config.xml.diff.theme return Theme[theme_name] if Theme.include?(theme_name) end # Default to :dark Theme[:dark] end |
#theme_name ⇒ Symbol
Get theme by name from ENV or config
823 824 825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'lib/canon/diff_formatter/theme.rb', line 823 def theme_name # ENV takes precedence env_name = ENV["CANON_DIFF_THEME"]&.to_sym return env_name if env_name && Theme.include?(env_name) # Check config if @config.respond_to?(:xml) && @config.xml.diff.respond_to?(:theme) theme_name = @config.xml.diff.theme return theme_name if Theme.include?(theme_name) end # Default :dark end |