Class: Pageflow::Themes
- Inherits:
-
Object
- Object
- Pageflow::Themes
- Includes:
- Enumerable
- Defined in:
- lib/pageflow/themes.rb
Overview
rubocop:todo Style/Documentation
Instance Method Summary collapse
-
#apply_default_options(options, entry:) ⇒ Object
private
Apply all registered defaults to theme options.
- #each ⇒ Object
- #get(name) ⇒ Object
-
#initialize ⇒ Themes
constructor
A new instance of Themes.
- #names ⇒ Object
-
#register(name, options = {}) ⇒ Object
Register a theme and supply theme options.
-
#register_default_options(options) ⇒ Object
Register default options that apply to all themes.
-
#register_options_transform(callable) ⇒ Object
Register a transform that can conditionally modify theme options.
Constructor Details
#initialize ⇒ Themes
Returns a new instance of Themes.
5 6 7 8 9 |
# File 'lib/pageflow/themes.rb', line 5 def initialize @themes = HashWithIndifferentAccess.new = {} = [] end |
Instance Method Details
#apply_default_options(options, entry:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply all registered defaults to theme options.
40 41 42 43 44 45 46 47 48 |
# File 'lib/pageflow/themes.rb', line 40 def (, entry:) # First merge hash defaults under theme options (theme wins) result = .deep_merge() # Then apply callable transforms (they can see theme options) .reduce(result) do |opts, transform| transform.call(opts, entry:) end end |
#each ⇒ Object
96 97 98 |
# File 'lib/pageflow/themes.rb', line 96 def each(&) @themes.values.each(&) end |
#get(name) ⇒ Object
88 89 90 |
# File 'lib/pageflow/themes.rb', line 88 def get(name) @themes.fetch(name) { raise(ArgumentError, "Unknown theme '#{name}'.") } end |
#names ⇒ Object
92 93 94 |
# File 'lib/pageflow/themes.rb', line 92 def names map(&:name) end |
#register(name, options = {}) ⇒ Object
Register a theme and supply theme options.
84 85 86 |
# File 'lib/pageflow/themes.rb', line 84 def register(name, = {}) @themes[name] = Theme.new(name, ) end |
#register_default_options(options) ⇒ Object
Register default options that apply to all themes. Can be called multiple times to accumulate defaults from different sources (gem, plugins, host app). Later calls override earlier ones for the same keys. Theme options always take precedence over defaults.
20 21 22 |
# File 'lib/pageflow/themes.rb', line 20 def () = .deep_merge() end |
#register_options_transform(callable) ⇒ Object
Register a transform that can conditionally modify theme options. Transforms run after defaults are merged with theme options, so they can inspect what the theme defines and add conditional defaults.
33 34 35 |
# File 'lib/pageflow/themes.rb', line 33 def (callable) << callable end |