Module: Card::Set::Format::AbstractFormat
- Includes:
- HamlViews, ViewDefinition, ViewOpts, Wrapper
- Defined in:
- lib/card/set/format/abstract_format.rb,
lib/card/set/format/abstract_format/wrapper.rb,
lib/card/set/format/abstract_format/view_opts.rb,
lib/card/set/format/abstract_format/haml_views.rb,
lib/card/set/format/abstract_format/view_definition.rb
Overview
AbstractFormat extends all format classes
Defined Under Namespace
Modules: HamlViews, ViewDefinition, ViewOpts, Wrapper
Constant Summary
Constants included from HamlPaths
HamlPaths::CORE_MODS, HamlPaths::TEMPLATE_DIR, HamlPaths::TMPSET_REGEXP
Constants included from ViewOpts
ViewOpts::VIEW_DEF_OPTS, ViewOpts::VIEW_SETTINGS
Instance Attribute Summary
Attributes included from Wrapper
Instance Method Summary collapse
-
#before(view, &block) ⇒ Object
define code to be executed before a view is rendered.
-
#set_module ⇒ Object
Constant for set module (without format).
-
#setting(name) ⇒ Object
Defines a setting method that can be used in all formats.
-
#source_location ⇒ Object
file location where set mod is stored.
-
#view(viewname, *args, &block) ⇒ Object
Views are the primary way that both sharks and monkeys interact with cards.
-
#view_for_override(viewname) ⇒ Object
simple placeholder for views designed to be overridden elsewhere.
Methods included from Wrapper
Methods included from HamlPaths
#deep_source, #each_template_path, #haml_block_locals, #haml_template_path, #haml_to_html, #source_mod_dir, #template_location, #try_haml_template_path, #with_template_path
Instance Method Details
#before(view, &block) ⇒ Object
define code to be executed before a view is rendered
91 92 93 |
# File 'lib/card/set/format/abstract_format.rb', line 91 def before view, &block define_method "_before_#{view}", &block end |
#set_module ⇒ Object
Returns constant for set module (without format).
121 122 123 |
# File 'lib/card/set/format/abstract_format.rb', line 121 def set_module Card.const_get name.split("::")[0..-2].join("::") end |
#setting(name) ⇒ Object
Defines a setting method that can be used in all formats. Example:
format do
setting :cols
cols 5, 7
view :some_view do
cols # => [5, 7]
end
end
107 108 109 110 111 112 113 |
# File 'lib/card/set/format/abstract_format.rb', line 107 def setting name Card::Set::Format::AbstractFormat.send :define_method, name do |*args| define_method name do args end end end |
#source_location ⇒ Object
file location where set mod is stored
116 117 118 |
# File 'lib/card/set/format/abstract_format.rb', line 116 def source_location set_module.source_location end |
#view(viewname, *args, &block) ⇒ Object
Views are the primary way that both sharks and monkeys interact with cards. Sharks select views to use in nests. Monkeys can define and tweak those views. These docs will introduce the basics of view definition.
## Sample view definitions
Here is a very simple view that just defines a label for the card(its name):
view :label do
card.name
end
View definitions can take the following forms:
view :viewname[, option_hash][, &block] # standard
view :viewname, alias_to_viewname[, option_hash] # aliasing
## View definition options
-
:alias_to [Symbol] name of view to which this view should be aliased. View must already be defined in self or specified mod.
-
:async render view asynchronously by first rendering a card placeholder and then completing a request. Only applies to HtmlFormat
-
:cache directs how to handle caching for this view. Supported values:
* *:standard* - (default) * *:always* - cache even when rendered within another cached view * *:never* - don't ever cache this view. Frequently used to prevent caching problems
You should certainly learn more about caching if you want to develop mods that are safe in a caching environment.
-
:compact [True/False]. Is view acceptable for rendering inside ‘compact` view? Default is false.
-
:denial [Symbol]. View to render if permission is denied. Value can be any viewname. Default is ‘:denial`. `:blank` is a common alternative.
-
:perms restricts view permissions. Supported values:
* *:create*, *:read* (default), *:update*, *:delete* - only users with the given permission for the card viewed. * *:none* - no permission check; anyone can view * a *Proc* object. Eg `perms: ->(_fmt) { Auth.needs_setup? }`
-
:template [Symbol] view is defined in a template. Currently ‘:haml` is the only supported value. See HamlViews
-
:unknown [True/False, Symbol]. Configures handling of “unknown” cards. (See card states). Supported values:
* *true* render view even if card is unknown * *false* default unknown handling (depends on context, create permissions, etc) * a *Symbol*: name of view to render
-
:wrap wrap view dynamically. Value is Symbol for wrapper or Hash with wrappers and wrapper options. See Wrapper
77 78 79 80 |
# File 'lib/card/set/format/abstract_format.rb', line 77 def view viewname, *args, &block def_opts = process_view_opts viewname, args define_view_method viewname, def_opts, &block end |
#view_for_override(viewname) ⇒ Object
simple placeholder for views designed to be overridden elsewhere
83 84 85 86 87 88 |
# File 'lib/card/set/format/abstract_format.rb', line 83 def view_for_override viewname # LOCALIZE view viewname do "override '#{viewname}' view" end end |