Module: Card::Set::TypePlusRight::CustomizedBootswatchSkin::Colors

Extended by:
Card::Set
Defined in:
tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb

Overview

Set: All "+Colors" cards on "CustomizedBootswatchSkin" cards

Defined Under Namespace

Modules: HtmlFormat

Constant Summary collapse

VARIABLE_NAMES =
{
  colors: %i[blue indigo purple pink red orange yellow green teal cyan
             white gray-100 gray-200 gray-300 gray-400 gray-500 gray-600 gray-700 gray-800
             gray-900 black],
  theme_colors: %i[primary secondary success info warning danger light dark
                   body-bg body-color]
}.freeze

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Card::Set::Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/bootstrap/set/type_plus_right/customized_bootswatch_skin/colors.rb"; end

Instance Method Details

#bootstrap_variables_scssObject



48
49
50
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 48

def bootstrap_variables_scss
  @bootstrap_variables_scss ||= Type::CustomizedBootswatchSkin.read_bootstrap_variables
end

#colorsObject



52
53
54
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 52

def colors
  @colors ||= variable_group_with_values :colors
end

#default_value_from_bootstrap(name) ⇒ Object



44
45
46
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 44

def default_value_from_bootstrap name
  value_from_scss name, bootstrap_variables_scss
end

#definition_regex(name) ⇒ Object



40
41
42
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 40

def definition_regex name
  /^(?<before>\s*\$#{name}\:\s*)(?<value>.+?)(?<after> !default;)$/
end

#replace_values(group, prefix = "") ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 107

def replace_values group, prefix=""
  values = variable_values_from_params group
  values.each_pair do |name, val|
    if content.match definition_regex(name)
      content.gsub! definition_regex(name), "\\k<before>#{prefix}#{val}\\k<after>"
    else
      self.content += "$#{name}: #{prefix}#{val} !default;\n"
    end
  end
end

#theme_colorsObject



56
57
58
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 56

def theme_colors
  @theme_colors ||= variable_group_with_values :theme_colors
end

#value_from_scss(name, source) ⇒ Object



29
30
31
32
33
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 29

def value_from_scss name, source
  name = name.to_s
  name = name[1..-1] if name.start_with?("$")
  source.match(definition_regex(name))&.capture(:value)
end

#value_from_variables_card(name) ⇒ Object



35
36
37
38
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 35

def value_from_variables_card name
  return unless (var_card = left.variables_card) && var_card.content.present?
  value_from_scss name, var_card.content
end

#variable_group_with_values(group) ⇒ Object



60
61
62
63
64
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 60

def variable_group_with_values group
  VARIABLE_NAMES[group].each_with_object({}) do |name, h|
    h[name] = variable_value name
  end
end

#variable_value(name) ⇒ Object

Parameters:

  • name (String)

    a scss variable name (it can start with a $)



23
24
25
26
27
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 23

def variable_value name
  value_from_scss(name, content) ||
    value_from_variables_card(name) ||
    default_value_from_bootstrap(name)
end

#variable_values_from_params(group) ⇒ Object



118
119
120
# File 'tmpsets/set/mod026-bootstrap/type_plus_right/customized_bootswatch_skin/colors.rb', line 118

def variable_values_from_params group
  Env.params.dig(group)&.slice(*VARIABLE_NAMES[group]) || {}
end