Class: Pageflow::Themes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pageflow/themes.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Constructor Details

#initializeThemes

Returns a new instance of Themes.



5
6
7
8
9
# File 'lib/pageflow/themes.rb', line 5

def initialize
  @themes = HashWithIndifferentAccess.new
  @default_options = {}
  @options_transforms = []
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 apply_default_options(options, entry:)
  # First merge hash defaults under theme options (theme wins)
  result = @default_options.deep_merge(options)

  # Then apply callable transforms (they can see theme options)
  @options_transforms.reduce(result) do |opts, transform|
    transform.call(opts, entry:)
  end
end

#eachObject



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

#namesObject



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.

Parameters:

  • name (Symbol)

    Used in conventional directory names.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :no_home_button (Boolean)

    Pass true if theme does not display home buttons in navigation bars.

  • :scroll_back_indicator (Boolean)

    Pass true if theme has styles for an indicator pointing to the previous page.

  • :scroll_indicator_modes (Boolean)

    Pass true if theme supports horizontal scroll indicators.

  • :emphasized_pages (Boolean)

    Pass true if theme has styles for emphasized pages in navigation bars.

  • :no_page_change_by_scrolling (Boolean)

    Pass true if changing the page by using the mouse wheel shall be deactivated.

  • :no_hide_text_on_swipe (Boolean)

    Pass true if hiding the text by swiping to left shall be deactivated on mobile devices.

  • :hide_logo_option (Boolean)

    Pass true if hiding the logo on specific pages should be supported as an option in the editor.

  • :logo_url (String)

    Pass logo url as string to turn the logo in navigation bar into a link.



84
85
86
# File 'lib/pageflow/themes.rb', line 84

def register(name, options = {})
  @themes[name] = Theme.new(name, options)
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.

Parameters:

  • options (Hash)

    Default options to deep merge into accumulated defaults.

Since:

  • 17.2



20
21
22
# File 'lib/pageflow/themes.rb', line 20

def register_default_options(options)
  @default_options = @default_options.deep_merge(options)
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.

Parameters:

  • callable (#call)

    Receives merged options hash, returns transformed options. Use for conditional defaults based on what theme defines.

Since:

  • 17.2



33
34
35
# File 'lib/pageflow/themes.rb', line 33

def register_options_transform(callable)
  @options_transforms << callable
end