Class: ThemeSetting

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Sluggable
Defined in:
app/models/theme_setting.rb

Constant Summary collapse

ROLES =
%i[primary dark light success warning danger accent].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sluggable

#to_param

Class Method Details

.currentObject

Returns the ThemeSetting for the current app, or a new unsaved instance.



14
15
16
# File 'app/models/theme_setting.rb', line 14

def self.current
  find_by(app_name: Studio.app_name) || new(app_name: Studio.app_name)
end

.db_column_for(role) ⇒ Object

Map DB columns (accent1/accent2) to role names (success/accent)



7
8
9
# File 'app/models/theme_setting.rb', line 7

def self.db_column_for(role)
  { success: :accent1, accent: :accent2 }[role] || role
end

Instance Method Details

#name_slugObject



27
28
29
# File 'app/models/theme_setting.rb', line 27

def name_slug
  "theme-#{app_name.parameterize}"
end

#resolved_colorsObject

Merged colors: DB values override Studio.theme_config defaults.



19
20
21
22
23
24
25
# File 'app/models/theme_setting.rb', line 19

def resolved_colors
  defaults = Studio.theme_config
  ROLES.each_with_object({}) do |role, hash|
    db_val = read_attribute(self.class.db_column_for(role))
    hash[role] = db_val.presence || defaults[role]
  end.compact
end