Module: Card::Set::Format::AbstractFormat::Wrapper
- Included in:
- Card::Set::Format::AbstractFormat
- Defined in:
- lib/card/set/format/abstract_format/wrapper.rb
Overview
The Wrapper module provides an API to define wrap methods. It is available in all formats.
Instance Attribute Summary collapse
-
#interior ⇒ Object
Returns the value of attribute interior.
Instance Method Summary collapse
- #layout(layout, opts = {}, &block) ⇒ Object
-
#wrapper(wrapper_name, *args, &wrap_block) ⇒ Object
Defines a wrapper method with the name "wrap_with_
".
Instance Attribute Details
#interior ⇒ Object
Returns the value of attribute interior.
59 60 61 |
# File 'lib/card/set/format/abstract_format/wrapper.rb', line 59 def interior @interior end |
Instance Method Details
#layout(layout, opts = {}, &block) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/card/set/format/abstract_format/wrapper.rb', line 50 def layout layout, opts={}, &block Card::Layout.register_built_in_layout layout, opts method_name = Card::Set::Format.layout_method_name(layout) define_method method_name, &block wrapper layout do send method_name end end |
#wrapper(wrapper_name, *args, &wrap_block) ⇒ Object
Defines a wrapper method with the name "wrap_with_
Example: wrapper :burger do |opts| ["#opts[:bun]-bun", interior, "bun"].join "|" end
It can be used like this: wrap_with_burger bun: "sesame" do "meat" end # => "sesame-bun|meat|bun"
It's also possible to wrap a whole view with a wrapper view :whopper, wrap: :burger do "meat" end
Options for view wrappers can be provided using a hash or, if not all wrappers need options, an array of symbols and hashes. Example view :big_mac, wrap: { burger: { bun: "sesame" }, paper: { color: :red } } view :cheese_burger, wrap: [:burger, paper: { color: :yellow }]
If you want to define a wrapper that wraps only with a single html tag then use the following syntax: wrapper :burger, :div, class: "medium"
wrap_with_burger "meat" # => "
40 41 42 43 44 45 46 47 48 |
# File 'lib/card/set/format/abstract_format/wrapper.rb', line 40 def wrapper wrapper_name, *args, &wrap_block method_name = Card::Set::Format.wrapper_method_name(wrapper_name) if block_given? define_method method_name, &wrap_block else define_tag_wrapper method_name, *args end define_wrap_with_method wrapper_name, method_name end |