Module: Card::Set::All::Templating

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod007-card-mod-content/all/templating.rb,
card/tmpsets/set/mod006-card-mod-content/all/templating.rb

Overview

Set: All cards (Templating)

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 Card::Set::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 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/mod007-card-mod-content/all/templating.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-content/set/all/templating.rb"; end

Instance Method Details

#assign_type_to?(structure) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 54

def assign_type_to? structure
  return if type_id == structure.type_id
  structure.assigns_type?
end

#assigns_type?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 59

def assigns_type?
  # needed because not all *structure templates govern the type of set members
  # for example, X+*type+*structure governs all cards of type X,
  # but the content rule does not (in fact cannot) have the type X.
  pattern_code = Card.quick_fetch(name.trunk_name.tag_name)&.codename
  return unless pattern_code && (set_class = Set::Pattern.find pattern_code)

  set_class.assigns_type
end

#default_type_idObject



35
36
37
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 35

def default_type_id
  Card.default_type_id
end

#dup_structure(type_id) ⇒ Object



48
49
50
51
52
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 48

def dup_structure type_id
  dup_card = dup
  dup_card.type_id = type_id || default_type_id
  dup_card.structure_rule_card
end

#is_structure?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 15

def is_structure?
  return @is_structure unless @is_structure.nil?

  @is_structure = name.trait_name? :structure
end

#is_template?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 9

def is_template?
  return @is_template unless @is_template.nil?

  @is_template = name.trait_name? :structure, :default
end

#new_card_templateObject



39
40
41
42
43
44
45
46
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 39

def new_card_template
  default = rule_card :default, skip_modules: true
  return default unless (structure = dup_structure default&.type_id)

  @virtual = true if compound?
  self.type_id = structure.type_id if assign_type_to?(structure)
  structure
end

#structureObject



69
70
71
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 69

def structure
  template&.is_structure? ? template : nil
end

#structure_rule_cardObject



73
74
75
76
77
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 73

def structure_rule_card
  return unless (card = rule_card :structure, skip_modules: true)

  card.db_content&.strip == "_self" ? nil : card
end

#templateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'card/tmpsets/set/mod007-card-mod-content/all/templating.rb', line 21

def template
  # currently applicable templating card.
  # note that a *default template is never returned for an existing card.
  @template ||= begin
    @virtual = false

    if new_card?
      new_card_template
    else
      structure_rule_card
    end
  end
end