module CyberarmEngine::Theme
Constants
- THEME
Public Instance Methods
deep_merge(original, intergrate, &block)
click to toggle source
Derived from Rails Hash#deep_merge! Enables passing partial themes through Element
options without issue
# File lib/cyberarm_engine/ui/theme.rb, line 38 def deep_merge(original, intergrate, &block) original.merge(intergrate) do |key, this_val, other_val| if this_val.is_a?(Hash) && other_val.is_a?(Hash) deep_merge(this_val, other_val, &block) elsif block_given? block.call(key, this_val, other_val) else other_val end end end
default(*args)
click to toggle source
# File lib/cyberarm_engine/ui/theme.rb, line 3 def default(*args) value = @options args.each do |arg| value = value.dig(arg) end value end
theme_defaults(options)
click to toggle source
# File lib/cyberarm_engine/ui/theme.rb, line 12 def theme_defaults(options) raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element) _theme = THEME _theme = deep_merge(_theme, options[:theme]) if options[:theme] _theme.delete(:theme) if options[:theme] hash = {} class_names = self.class.ancestors class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! do |c| c.to_s.split("::").last.to_sym end.reverse! class_names.each do |klass| next unless data = _theme.dig(klass) data.each do |_key, _value| hash.merge!(data) end end deep_merge(hash, options) end