Class: TailwindTheme::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/tailwind_theme/factory.rb

Overview

Theme factory to load and cache a theme.

Examples:


TailwindTheme::Factory.new.theme

TailwindTheme::Factory.new.theme :admin

Instance Method Summary collapse

Constructor Details

#initializeFactory

Returns a new instance of Factory.



15
16
17
# File 'lib/tailwind_theme/factory.rb', line 15

def initialize
  @themes = {}
end

Instance Method Details

#theme(name = nil) ⇒ TailwindTheme::Theme, NilClass

Load and cache the theme.

The default theme load order:

1) themes/default.yml(.erb)
2) theme.yml(.erb)

Parameters:

  • name (String, Symbol) (defaults to: nil)

    the name of the theme to load. Nil will load the default theme.

Returns:

  • (TailwindTheme::Theme, NilClass)

    returns the theme or nil if the theme cannot be found.



28
29
30
31
32
33
34
# File 'lib/tailwind_theme/factory.rb', line 28

def theme(name = nil)
  if name.nil? || name.to_s == "default"
    @themes[:default] ||= load_default_theme
  else
    @themes[name.to_sym] = load_by_name name.to_sym
  end
end