Class: RailsBase::Configuration::Appearance

Inherits:
Base
  • Object
show all
Defined in:
lib/rails_base/configuration/appearance.rb

Constant Summary collapse

BUTTONS =
[
  :btn_primary,
  :btn_secondary,
  :btn_success,
  :btn_danger,
  :btn_warning,
  :btn_info,
  :btn_light,
  :btn_dark,
  :bg_light,

]
DOWNSTREAM_CLASSES =
[
  :t_header,
  :t_body,
  :bg_color,
  :navbar,
  :text,
  :card,
  :footer,
  :header,
  :back_to_top,
] + BUTTONS
SKIP_DOWNSTREAM_CLASSES =
[:footer, :header, :back_to_top]
DARK_MODE =
:dark
LIGHT_MODE =
:light
MATCH_OS =
:match_os
ALLOWABLE_TYPES =
{
  DARK_MODE => 'Dark Mode',
  LIGHT_MODE => 'Light Mode',
}
APPEARANCE_TYPES =
ALLOWABLE_TYPES.merge(MATCH_OS => 'Match System')
DEFAULT_VALUES =
{
  enabled: {
    type: :boolean,
    default: true,
    description: 'When disabled, the user will be forced into default_mode when appropriate'
  },
  default_mode: {
    type: :values,
    expect_values: APPEARANCE_TYPES.keys,
    default: LIGHT_MODE,
    description: 'Default mode to set when mode not found in cookies/session',
  },

  math_os_dark: {
    type: :values,
    expect_values: ALLOWABLE_TYPES.keys,
    default: DARK_MODE,
    description: 'Mode to set when OS returns dark mode (useful when more than light/dark mode',
  },
}

Constants inherited from Base

Base::ALLOWED_TYPES

Instance Method Summary collapse

Methods inherited from Base

_allow_write_block?, _unset_allow_write!, #dig, #override_methods!

Constructor Details

#initializeAppearance

Returns a new instance of Appearance.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rails_base/configuration/appearance.rb', line 86

def initialize
  #####
  # all display classes are required to have ALLOWABLE_TYPES as default values
  #####
  @t_header = Configuration::Display::TableHeader.new
  @t_body = Configuration::Display::TableBody.new
  @bg_color = Configuration::Display::BackgroundColor.new
  @navbar = Configuration::Display::Navbar.new
  @text = Configuration::Display::Text.new
  @card = Configuration::Display::Card.new
  @footer = Configuration::Display::Footer.new
  @header = Configuration::Display::Header.new
  @back_to_top = Configuration::Display::BackTotop.new
  @bg_light = Configuration::Display::BgLight.new

  @btn_primary = Configuration::Display::BtnPrimary.new
  @btn_secondary = Configuration::Display::BtnSecondary.new
  @btn_success = Configuration::Display::BtnSuccess.new
  @btn_danger = Configuration::Display::BtnDanger.new
  @btn_warning = Configuration::Display::BtnWarning.new
  @btn_info = Configuration::Display::BtnInfo.new
  @btn_light = Configuration::Display::BtnLight.new
  @btn_dark = Configuration::Display::BtnDark.new

  _validate_values
  super()
end

Instance Method Details

#assign_default_values!Object



121
122
123
124
125
126
# File 'lib/rails_base/configuration/appearance.rb', line 121

def assign_default_values!
  super()
  DOWNSTREAM_CLASSES.each do |variable|
    instance_variable_get("@#{variable}").assign_default_values!
  end
end

#validate!Object



114
115
116
117
118
119
# File 'lib/rails_base/configuration/appearance.rb', line 114

def validate!
  super()
  DOWNSTREAM_CLASSES.each do |variable|
    instance_variable_get("@#{variable}").validate!
  end
end