Module: Fatty::Themes::Manager
- Defined in:
- lib/fatty/themes/manager.rb
Constant Summary collapse
- FALLBACK_THEME =
:terminal
Class Method Summary collapse
- .current ⇒ Object
- .cycle ⇒ Object
- .fetch(name) ⇒ Object
- .load! ⇒ Object
- .markdown(name = current) ⇒ Object
- .registry ⇒ Object
- .roles(name = current) ⇒ Object
- .set(theme) ⇒ Object
- .theme_names ⇒ Object
Class Method Details
.current ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fatty/themes/manager.rb', line 27 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 |
.cycle ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/fatty/themes/manager.rb', line 50 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
58 59 60 |
# File 'lib/fatty/themes/manager.rb', line 58 def self.fetch(name) Resolver.resolve(registry, name) end |
.load! ⇒ Object
17 18 19 20 21 |
# File 'lib/fatty/themes/manager.rb', line 17 def self.load! registry.clear Loader.load_dir(Fatty::Config.user_themes_dir, registry: registry) registry end |
.markdown(name = current) ⇒ Object
66 67 68 |
# File 'lib/fatty/themes/manager.rb', line 66 def self.markdown(name = current) fetch(name)[:markdown] end |
.registry ⇒ Object
8 9 10 11 12 13 14 15 |
# 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) reg end end |
.roles(name = current) ⇒ Object
62 63 64 |
# File 'lib/fatty/themes/manager.rb', line 62 def self.roles(name = current) fetch(name)[:roles] end |
.set(theme) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/fatty/themes/manager.rb', line 40 def self.set(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_names ⇒ Object
23 24 25 |
# File 'lib/fatty/themes/manager.rb', line 23 def self.theme_names registry.names.sort end |