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

Extended by:
Card::Set
Defined in:
tmpsets/set/mod003-core/all/templating.rb

Overview

Set: All cards (Templating)

Class Method Summary collapse

Instance Method Summary collapse

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

#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore

Methods included from Card::Set::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 Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'tmpsets/set/mod003-core/all/templating.rb', line 7

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

Instance Method Details

#assign_type_to?(structure) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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_id(default_card = nil) ⇒ Object



35
36
37
# File 'tmpsets/set/mod003-core/all/templating.rb', line 35

def default_type_id default_card=nil
  default_card ? default_card.type_id : Card.default_type_id
end

#is_structure?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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
47
48
49
50
51
52
# File 'tmpsets/set/mod003-core/all/templating.rb', line 39

def new_card_template
  default = rule_card :default, skip_modules: true

  dup_card = dup
  dup_card.type_id = default_type_id default

  if (structure = dup_card.structure_rule_card)
    @virtual = true if junction?
    self.type_id = structure.type_id if assign_type_to?(structure)
    structure
  else
    default
  end
end

#structureObject



69
70
71
72
# File 'tmpsets/set/mod003-core/all/templating.rb', line 69

def structure
  return unless template && template.is_structure?
  template
end

#structure_rule_cardObject



74
75
76
77
78
# File 'tmpsets/set/mod003-core/all/templating.rb', line 74

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 'tmpsets/set/mod003-core/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