Module: Fatty::Themes::Manager
- Defined in:
- lib/fatty/themes/manager.rb
Constant Summary collapse
- FALLBACK_THEME =
:terminal
Instance Attribute Summary collapse
-
#warning ⇒ Object
readonly
Returns the value of attribute warning.
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
- .warning ⇒ Object
Instance Attribute Details
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
6 7 8 |
# File 'lib/fatty/themes/manager.rb', line 6 def warning @warning end |
Class Method Details
.current ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fatty/themes/manager.rb', line 36 def self.current return @current if @current theme = Fatty::Config.config[:theme] @current = if theme && !theme.to_s.strip.empty? set(theme) else FALLBACK_THEME end end |
.cycle ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/fatty/themes/manager.rb', line 63 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
71 72 73 |
# File 'lib/fatty/themes/manager.rb', line 71 def self.fetch(name) Resolver.resolve(registry, name) end |
.load! ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/fatty/themes/manager.rb', line 24 def self.load! @warning = nil 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
79 80 81 |
# File 'lib/fatty/themes/manager.rb', line 79 def self.markdown(name = current) fetch(name)[:markdown] end |
.registry ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/fatty/themes/manager.rb', line 14 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
75 76 77 |
# File 'lib/fatty/themes/manager.rb', line 75 def self.roles(name = current) fetch(name)[:roles] end |
.set(theme) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fatty/themes/manager.rb', line 48 def self.set(theme) return current unless theme t = theme.to_sym if theme_names.include?(t) @warning = nil @current = t else @warning = "Unknown theme in config: '#{theme}'; using '#{FALLBACK_THEME}'" Fatty.warn(@warning, tag: :theme) @current = FALLBACK_THEME end end |
.theme_names ⇒ Object
32 33 34 |
# File 'lib/fatty/themes/manager.rb', line 32 def self.theme_names registry.names.sort end |
.warning ⇒ Object
10 11 12 |
# File 'lib/fatty/themes/manager.rb', line 10 def self.warning @warning end |