Module: Card::Set::Format

Included in:
Card::Set
Defined in:
lib/card/set/format.rb,
lib/card/set/format/wrapper.rb,
lib/card/set/format/haml_views.rb,
lib/card/set/format/abstract_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 #...your code here end

Methods are defined on the format

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

TODO: introduce view settings modal: { size: :large}, cache perms tags: :unknown_ok bridge

Defined Under Namespace

Modules: AbstractFormat, HamlViews, Wrapper

Constant Summary collapse

TEMPLATE_DIR =
%w[template set].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.layout_method_name(layout) ⇒ Object



92
93
94
# File 'lib/card/set/format.rb', line 92

def layout_method_name layout
  "_layout_#{layout.to_name.key}"
end

.view_method_name(view) ⇒ Object



100
101
102
# File 'lib/card/set/format.rb', line 100

def view_method_name view
  "_view_#{view}"
end

.wrapper_method_name(wrapper) ⇒ Object



96
97
98
# File 'lib/card/set/format.rb', line 96

def wrapper_method_name wrapper
  "_wrapper_#{wrapper}"
end

Instance Method Details

#all_set_format_mod!(format_class, mod) ⇒ Object

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



86
87
88
89
# File 'lib/card/set/format.rb', line 86

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

#before(view, &block) ⇒ Object



54
55
56
# File 'lib/card/set/format.rb', line 54

def before view, &block
  format { before view, &block }
end

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



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

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



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/card/set/format.rb', line 33

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



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/card/set/format.rb', line 73

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



46
47
48
# File 'lib/card/set/format.rb', line 46

def view *args, &block
  format { view(*args, &block) }
end

#view_for_override(*args, &block) ⇒ Object



50
51
52
# File 'lib/card/set/format.rb', line 50

def view_for_override *args, &block
  format { view_for_override(*args, &block) }
end