Class: Lookbook::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/theme.rb

Constant Summary collapse

BASE_THEMES =
{
  indigo: {
    favicon_light_mode: "#4F46E5",
    favicon_dark_mode: "#818CF8"
  },
  zinc: {
    favicon_light_mode: "#52525b",
    favicon_dark_mode: "#E4E4E7"
  },
  blue: {
    favicon_light_mode: "#2563EB",
    favicon_dark_mode: "#60A5FA"
  },
  green: {
    favicon_light_mode: "#16a34a",
    favicon_dark_mode: "#66E093"
  },
  rose: {
    favicon_light_mode: "#E11D48",
    favicon_dark_mode: "#FFA0B5"
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_theme, overrides = {}) ⇒ Theme

Returns a new instance of Theme.



26
27
28
29
30
# File 'lib/lookbook/theme.rb', line 26

def initialize(base_theme, overrides = {})
  @base_theme = base_theme
  @overrides = overrides
  @css = nil
end

Class Method Details

.valid_theme?(name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/lookbook/theme.rb', line 58

def self.valid_theme?(name)
  BASE_THEMES.key? name.to_sym
end

Instance Method Details

#favicon_dark_modeObject



38
39
40
41
42
# File 'lib/lookbook/theme.rb', line 38

def favicon_dark_mode
  @overrides[:favicon_dark_mode].presence ||
    @overrides[:favicon].presence ||
    BASE_THEMES[@base_theme.to_sym][:favicon_dark_mode]
end

#favicon_light_modeObject



32
33
34
35
36
# File 'lib/lookbook/theme.rb', line 32

def favicon_light_mode
  @overrides[:favicon_light_mode].presence ||
    @overrides[:favicon].presence ||
    BASE_THEMES[@base_theme.to_sym][:favicon_light_mode]
end

#to_cssObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lookbook/theme.rb', line 44

def to_css
  return @css unless @css.nil?
  @css ||= if @overrides.present?
    styles = [":root {"]
    styles << @overrides.reject { |key| key.to_s.start_with?("favicon") }.map do |key, value|
      "  --lookbook-#{key.to_s.underscore.tr("_", "-")}: #{value};"
    end
    styles.push "}"
    styles.join("\n")
  else
    ""
  end
end