Module: Card::Set::Type::CustomizedBootswatchSkin

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb,
card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin/html_views.rb,
card/tmpsets/set/mod022-card-mod-bootstrap/type/customized_bootswatch_skin.rb,
card/tmpsets/set/mod022-card-mod-bootstrap/type/customized_bootswatch_skin/html_views.rb

Overview

Set: All “CustomizedBootswatchSkin” cards

Defined Under Namespace

Modules: HtmlFormat, HtmlViews

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

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, #define_set_from_error, #ensure_set, #setting_opts, #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 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 7

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

Instance Method Details

#add_bootswatch_subfieldObject



100
101
102
103
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 100

def add_bootswatch_subfield
  add_subfield :bootswatch, type_id: Card::ScssID,
                            content: content_from_theme(:bootswatch)
end

#add_stylesheets_subfield(style_items = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 79

def add_stylesheets_subfield style_items=nil
  opts = { type_id: Card::SkinID }
  if theme_name
    theme_style = add_bootswatch_subfield
    opts[:content] = "[[#{theme_style.name}]]"
  end
  if style_items
    opts[:content] = [opts[:content], style_items].flatten.compact.to_pointer_content
  end

  add_subfield :stylesheets, opts
end

#add_variables_subfieldObject



92
93
94
95
96
97
98
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 92

def add_variables_subfield
  theme_content = content_from_theme(:variables)
  default_content = read_bootstrap_variables
  add_subfield :variables,
               type_id: Card::ScssID,
               content: "#{theme_content}\n\n\n#{default_content}"
end

#content_from_theme(subfield) ⇒ Object



109
110
111
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 109

def content_from_theme subfield
  theme_card&.scss_from_theme_file subfield
end

#editable_item_cardsObject



22
23
24
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 22

def editable_item_cards
  [colors_card, variables_card, stylesheets_card]
end

#event: copy_themeObject



69
70
71
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 69

event :copy_theme, :prepare_to_store, on: :create do
  initialize_theme
end

#event: initialize_because_of_type_changeObject



57
58
59
60
61
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 57

event :initialize_because_of_type_change, :prepare_to_store,
      on: :update, changed: :type do
  self.content = content
  initialize_theme old_skin_items
end

#event: validate_theme_templateObject



46
47
48
49
50
51
52
53
54
55
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 46

event :validate_theme_template, :validate, on: :create do
  if theme_name
    if Card.fetch_type_id(theme_card_name) != Card::BootswatchSkinID
      errors.add :abort, tr(:not_valid_theme, theme_name: theme_name)
    elsif !Dir.exist? source_dir
      puts method(:source_dir).source_location
      errors.add :abort, tr(:cannot_source_theme, theme_name: theme_name)
    end
  end
end

#initialize_theme(style_item_names = nil) ⇒ Object



73
74
75
76
77
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 73

def initialize_theme style_item_names=nil
  add_subfield :colors, type_id: Card::ScssID
  add_variables_subfield
  add_stylesheets_subfield style_item_names
end

#old_skin_itemsObject



63
64
65
66
67
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 63

def old_skin_items
  skin = Card.new(type: :pointer, content: db_content_before_act)
  skin.drop_item "bootstrap default skin"
  skin.item_names
end

#stylesheets_card_namesObject



30
31
32
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 30

def stylesheets_card_names
  [Card.fetch_name(name, :stylesheets)]
end

#theme_cardObject



105
106
107
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 105

def theme_card
  @theme_card ||= theme_codename ? Card[theme_codename] : nil
end

#theme_card_nameObject



34
35
36
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 34

def theme_card_name
  "#{theme_name} skin"
end

#theme_codenameObject



42
43
44
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 42

def theme_codename
  theme_name && "#{theme_name}_skin".to_sym
end

#theme_error_typeObject



52
53
54
55
56
57
58
59
# File 'card/tmpsets/set/mod022-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 52

def theme_error_type
  if Card.fetch_type_id(theme_card_name) != Card::BootswatchSkinID
    :not_valid_theme
  elsif !Dir.exist? source_dir
    # puts method(:source_dir).source_location
    :cannot_source_theme
  end
end

#theme_nameObject



38
39
40
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 38

def theme_name
  Env.params[:theme].present? && Env.params[:theme]
end

#top_level_item_cardsObject



14
15
16
17
18
19
20
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 14

def top_level_item_cards
  cards = PRE_VARIABLES_CARD_NAMES.map { |n| Card[n] }
  cards += [colors_card, variables_card]
  cards += POST_VARIABLES_CARD_NAMES.map { |n| Card[n] }
  cards << stylesheets_card
  cards
end

#variables_card_namesObject



26
27
28
# File 'card/tmpsets/set/mod021-card-mod-bootstrap/type/customized_bootswatch_skin.rb', line 26

def variables_card_names
  %i[colors variables].map { |s| Card.fetch_name name, s }
end