Module: Card::Set::Format
- Included in:
- Card::Set
- Defined in:
- lib/card/set/format.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)
Defined Under Namespace
Modules: AbstractFormat, HamlViews
Constant Summary collapse
- TEMPLATE_DIR =
%w[template set].freeze
Instance Method Summary collapse
-
#all_set_format_mod!(format_class, mod) ⇒ Object
make mod ready to include in base (non-set-specific) format classes.
- #before(view, &block) ⇒ Object
- #define_on_format(format_name = :base, &block) ⇒ Object
- #format(*format_names, &block) ⇒ Object
- #register_set_format(format_class, mod) ⇒ Object
- #view(*args, &block) ⇒ Object
- #view_for_override(*args, &block) ⇒ Object
Instance Method Details
#all_set_format_mod!(format_class, mod) ⇒ Object
make mod ready to include in base (non-set-specific) format classes
79 80 81 82 |
# File 'lib/card/set/format.rb', line 79 def all_set_format_mod! format_class, mod modules[:base_format][format_class] ||= [] modules[:base_format][format_class] << mod end |
#before(view, &block) ⇒ Object
47 48 49 |
# File 'lib/card/set/format.rb', line 47 def before view, &block format { before view, &block } end |
#define_on_format(format_name = :base, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/card/set/format.rb', line 51 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
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/card/set/format.rb', line 26 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
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/card/set/format.rb', line 66 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
39 40 41 |
# File 'lib/card/set/format.rb', line 39 def view *args, &block format { view(*args, &block) } end |
#view_for_override(*args, &block) ⇒ Object
43 44 45 |
# File 'lib/card/set/format.rb', line 43 def view_for_override *args, &block format { view_for_override(*args, &block) } end |