Module: Card::Set::Format

Included in:
Card::Set
Defined in:
lib/card/set/format.rb

Overview

Whenever a Format object is instantiated for a card, it includes all views associated with BOTH (a) sets of which the card is a member and (b) the current format or its ancestors. More on defining views below.

View definitions

When you declare: view :view_name do |args| #...your code here end

Methods are defined on the format

The external api with checks: render(:viewname, args)

Defined Under Namespace

Modules: AbstractFormat

Instance Method Summary collapse

Instance Method Details

#all_set_format_mod!(format_class, mod) ⇒ Object

make mod ready to include in base (non-set-specific) format classes



70
71
72
73
# File 'lib/card/set/format.rb', line 70

def all_set_format_mod! format_class, mod
  modules[:base_format][format_class] ||= []
  modules[:base_format][format_class] << mod
end

#define_on_format(format_name = :base, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/card/set/format.rb', line 42

def define_on_format format_name=:base, &block
  # format class name, eg. HtmlFormat
  klass = Card::Format.format_class_name format_name

  # called on current set module, eg Card::Set::Type::Pointer
  mod = const_get_or_set klass do
    # yielding set format module, eg Card::Set::Type::Pointer::HtmlFormat
    m = Module.new
    register_set_format Card::Format.class_from_name(klass), m
    m.extend Card::Set::AbstractFormat
    m
  end
  mod.class_eval(&block)
end

#format(*format_names, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/card/set/format.rb', line 23

def format *format_names, &block
  format_names.compact!
  if format_names.empty?
    format_names = [:base]
  elsif format_names.first == :all
    format_names =
      Card::Format.registered.reject { |f| Card::Format.aliases[f] }
  end
  format_names.each do |f|
    define_on_format f, &block
  end
end

#register_set_format(format_class, mod) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/card/set/format.rb', line 57

def register_set_format format_class, mod
  if all_set?
    all_set_format_mod! format_class, mod
  else
    format_type = abstract_set? ? :abstract_format : :nonbase_format
    # ready to include dynamically in set members' format singletons
    format_hash = modules[format_type][format_class] ||= {}
    format_hash[shortname] ||= []
    format_hash[shortname] << mod
  end
end

#view(*args, &block) ⇒ Object



36
37
38
39
40
# File 'lib/card/set/format.rb', line 36

def view *args, &block
  format do
    view(*args, &block)
  end
end