Module: Fatty::Themes::Manager

Defined in:
lib/fatty/themes/manager.rb

Constant Summary collapse

FALLBACK_THEME =
:terminal

Class Method Summary collapse

Class Method Details

.currentObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fatty/themes/manager.rb', line 29

def self.current
  return @current if @current

  theme = Fatty::Config.config[:theme]

  @current =
    if theme && !theme.to_s.strip.empty?
      theme.to_sym
    else
      FALLBACK_THEME
    end
end

.cycleObject



54
55
56
57
58
59
60
# File 'lib/fatty/themes/manager.rb', line 54

def self.cycle
  names = theme_names
  return set(FALLBACK_THEME) if names.empty?

  idx = names.index(current) || 0
  set(names[(idx + 1) % names.length])
end

.fetch(name) ⇒ Object



62
63
64
# File 'lib/fatty/themes/manager.rb', line 62

def self.fetch(name)
  Resolver.resolve(registry, name)
end

.load!Object



18
19
20
21
22
23
# File 'lib/fatty/themes/manager.rb', line 18

def self.load!
  registry.clear
  Loader.load_dir(Fatty::Config.user_themes_dir, registry: registry)
  Loader.load_dir(Fatty::Config.app_themes_dir, registry: registry) if Fatty::Config.app_themes_dir
  registry
end

.markdown(name = current) ⇒ Object



70
71
72
# File 'lib/fatty/themes/manager.rb', line 70

def self.markdown(name = current)
  fetch(name)[:markdown]
end

.registryObject



8
9
10
11
12
13
14
15
16
# File 'lib/fatty/themes/manager.rb', line 8

def self.registry
  @registry ||=
    begin
      reg = Registry.new
      Loader.load_dir(Fatty::Config.user_themes_dir, registry: reg)
      Loader.load_dir(Fatty::Config.app_themes_dir, registry: reg) if Fatty::Config.app_themes_dir
      reg
    end
end

.roles(name = current) ⇒ Object



66
67
68
# File 'lib/fatty/themes/manager.rb', line 66

def self.roles(name = current)
  fetch(name)[:roles]
end

.set(theme) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fatty/themes/manager.rb', line 42

def self.set(theme)
  return current unless theme

  t = theme.to_sym
  if theme_names.include?(t)
    @current = t
  else
    Fatty.warn("Unknown theme: #{theme}, falling back to #{FALLBACK_THEME}", tag: :theme)
    @current = FALLBACK_THEME
  end
end

.theme_namesObject



25
26
27
# File 'lib/fatty/themes/manager.rb', line 25

def self.theme_names
  registry.names.sort
end