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

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

Constant Summary

Constants included from Format

Format::TEMPLATE_DIR

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

#all_set_format_mod!, #before, #define_on_format, #format, layout_method_name, #register_set_format, #view, #view_for_override, view_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Method Details

#assign_type_to?(structure) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'tmpsets/set/mod002-core/all/templating.rb', line 42

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

#assigns_type?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'tmpsets/set/mod002-core/all/templating.rb', line 47

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.
  return unless (set_pattern = Card.fetch cardname.trunk_name.tag_name,
                                          skip_modules: true)
  return unless (pattern_code = set_pattern.codename)
  return unless (set_class = Set::Pattern.find pattern_code)
  set_class.assigns_type
end

#is_structure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'tmpsets/set/mod002-core/all/templating.rb', line 9

def is_structure?
  cardname.trait_name? :structure
end

#is_template?Boolean

~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/core/set/all/templating.rb ~~

Returns:

  • (Boolean)


5
6
7
# File 'tmpsets/set/mod002-core/all/templating.rb', line 5

def is_template?
  cardname.trait_name? :structure, :default
end

#new_card_templateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'tmpsets/set/mod002-core/all/templating.rb', line 27

def new_card_template
  default = rule_card :default, skip_modules: true

  dup_card = dup
  dup_card.type_id = default ? default.type_id : Card.default_type_id

  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



58
59
60
61
# File 'tmpsets/set/mod002-core/all/templating.rb', line 58

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

#structure_rule_cardObject



71
72
73
74
# File 'tmpsets/set/mod002-core/all/templating.rb', line 71

def structure_rule_card
  card = rule_card :structure, skip_modules: true
  card && card.db_content.strip == "_self" ? nil : card
end

#templateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'tmpsets/set/mod002-core/all/templating.rb', line 13

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

#virtual?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'tmpsets/set/mod002-core/all/templating.rb', line 63

def virtual?
  return false unless new_card?
  if @virtual.nil?
    cardname.simple? ? (@virtual = false) : template
  end
  @virtual
end