Class: QTimetrap::Styles::Theme

Inherits:
Object
  • Object
show all
Defined in:
app/styles/theme.rb

Overview

Loads and composes QSS theme assets for the application.

Constant Summary collapse

FILES =
%w[application project_sidebar tracker_controls entries_list].freeze
DEFAULT =
'light'
SUPPORTED =
%w[light dark].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, root:) ⇒ Theme

Returns a new instance of Theme.



11
12
13
14
15
# File 'app/styles/theme.rb', line 11

def initialize(name:, root:)
  @name = normalize_name(name)
  @root = root
  @cache = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'app/styles/theme.rb', line 17

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



17
18
19
# File 'app/styles/theme.rb', line 17

def root
  @root
end

Instance Method Details

#application_stylesheetObject



19
20
21
# File 'app/styles/theme.rb', line 19

def application_stylesheet
  FILES.map { |file| stylesheet(file) }.join("\n")
end

#snippet(snippet_name) ⇒ Object



27
28
29
# File 'app/styles/theme.rb', line 27

def snippet(snippet_name)
  File.read(path_for_snippet(snippet_name))
end

#stylesheet(file_name) ⇒ Object



31
32
33
34
35
# File 'app/styles/theme.rb', line 31

def stylesheet(file_name)
  cache.fetch(file_name) do
    cache[file_name] = File.read(path_for(file_name))
  end
end

#with_name(next_name) ⇒ Object



23
24
25
# File 'app/styles/theme.rb', line 23

def with_name(next_name)
  self.class.new(name: next_name, root: root)
end