Class: ThemeSetting
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ThemeSetting
- 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
-
.current ⇒ Object
Returns the ThemeSetting for the current app, or a new unsaved instance.
-
.db_column_for(role) ⇒ Object
Map DB columns (accent1/accent2) to role names (success/accent).
Instance Method Summary collapse
- #name_slug ⇒ Object
-
#resolved_colors ⇒ Object
Merged colors: DB values override Studio.theme_config defaults.
Methods included from Sluggable
Class Method Details
.current ⇒ Object
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_slug ⇒ Object
27 28 29 |
# File 'app/models/theme_setting.rb', line 27 def name_slug "theme-#{app_name.parameterize}" end |
#resolved_colors ⇒ Object
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 |