Class: Card::View
- Inherits:
-
Object
- Object
- Card::View
- Extended by:
- Cache::ClassMethods
- Includes:
- Cache, Classy, Options, Permission
- Defined in:
- lib/card/view.rb,
lib/card/view/cache.rb,
lib/card/view/classy.rb,
lib/card/view/options.rb,
lib/card/view/cache/stub.rb,
lib/card/view/permission.rb,
lib/card/view/options/voo_api.rb,
lib/card/view/options/key_lists.rb,
lib/card/view/cache/cache_action.rb,
lib/card/view/options/visibility.rb
Overview
Card::View manages view options, view caching, and view permissions.
View objects, which are instantiated whenever a view is rendered, are available as
in views and other format methods. The view objects can be accessed using #voo
.
We sometimes feebly pretend VOO is an acronym for "view option object," but really
we just needed a way not to confuse these Card::View options with the countless
references to viewnames that naturally arise when rendering views within views within
views.
When view A renders view B within the same format object, A's voo is the parent of B's voo. When card C nests card D, a new (sub)format object is initialized. C is then the parent format of D, but D has its own root voo.
So a lineage might look something like this:
F1V1 -> F1V2 -> F1V3 -> F2V1 -> F2V2 -> F3V1 ...
Defined Under Namespace
Modules: Cache, Classy, Options, Permission
Constant Summary
Constants included from Options::Visibility
Options::Visibility::VIZ_SETTING
Instance Attribute Summary collapse
-
#card ⇒ Object
readonly
Returns the value of attribute card.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Attributes included from Options::VooApi
Class Method Summary collapse
-
.normalize(view) ⇒ Symbol
Viewname as Symbol.
-
.normalize_list(val) ⇒ Array
List of viewnames as Symbols.
Instance Method Summary collapse
-
#deep_root ⇒ Object
the root voo of the root format.
-
#deep_root? ⇒ true/false
neither view nor format has a parent.
-
#initialize(format, view, raw_options = {}, parent = nil) ⇒ View
constructor
A new instance of View.
-
#next_ancestor(across_format = true) ⇒ Card::View
next voo object found tracing ancestry through parent voos and/or parent formats.
-
#next_format_ancestor ⇒ Object
voo object of format's parent.
-
#ok_view ⇒ Symbol
the final view.
-
#process ⇒ rendered view or a stub
handle rendering, including optional visibility, permissions, and caching.
-
#requested_view ⇒ Symbol
the view to "attempt".
- #root ⇒ Card::View
- #root? ⇒ true/false
Methods included from Cache::ClassMethods
Methods included from Permission
Methods included from Classy
#add_extra_classes, #class_down, #class_up, #classy, #deep_extra_classes, #extra_classes, #remove_extra_classes, #with_class_up, #without_upped_class
Methods included from Options
Methods included from Options::KeyLists
#accessible_keys, #all_keys, #heir_keys, #reset_key_lists, #shark_keys, #slot_keys
Methods included from Options::Visibility
#hide, #hide!, #hide?, #optional?, #process_visibility, #show, #show!, #show?, #visible?, #viz, #viz_hash
Methods included from Options::VooApi
define_getter, define_setter, included, #items, #normalize_cache, #normalize_edit, #normalize_input_type, #normalize_special_options!, #normalize_wrap, #slot_options, #special_option_value
Constructor Details
#initialize(format, view, raw_options = {}, parent = nil) ⇒ View
Returns a new instance of View.
55 56 57 58 59 60 61 62 63 |
# File 'lib/card/view.rb', line 55 def initialize format, view, ={}, parent=nil @format = format @raw_view = view @raw_options = @parent = parent @card = @format.card end |
Instance Attribute Details
#card ⇒ Object (readonly)
Returns the value of attribute card.
29 30 31 |
# File 'lib/card/view.rb', line 29 def card @card end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
29 30 31 |
# File 'lib/card/view.rb', line 29 def format @format end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
29 30 31 |
# File 'lib/card/view.rb', line 29 def parent @parent end |
Class Method Details
.normalize(view) ⇒ Symbol
Returns viewname as Symbol.
33 34 35 |
# File 'lib/card/view.rb', line 33 def normalize view view.present? ? view.to_sym : nil end |
.normalize_list(val) ⇒ Array
Returns list of viewnames as Symbols.
38 39 40 41 42 43 44 45 46 |
# File 'lib/card/view.rb', line 38 def normalize_list val case val when NilClass then [] when Array then val when String then val.split(/[\s,]+/) when Symbol then [val] else raise Card::Error, "bad show/hide argument: #{val}" end end |
Instance Method Details
#deep_root ⇒ Object
the root voo of the root format
98 99 100 |
# File 'lib/card/view.rb', line 98 def deep_root format.root.voo end |
#deep_root? ⇒ true/false
neither view nor format has a parent
104 105 106 |
# File 'lib/card/view.rb', line 104 def deep_root? !parent && !format.parent end |
#next_ancestor(across_format = true) ⇒ Card::View
next voo object found tracing ancestry through parent voos and/or parent formats
110 111 112 |
# File 'lib/card/view.rb', line 110 def next_ancestor across_format=true parent || (across_format && next_format_ancestor) || nil end |
#next_format_ancestor ⇒ Object
voo object of format's parent
115 116 117 |
# File 'lib/card/view.rb', line 115 def next_format_ancestor format.parent&.voo end |
#ok_view ⇒ Symbol
the final view. can be different from @requested_view when there are issues with permissions, recursions, unknown cards, etc.
83 84 85 |
# File 'lib/card/view.rb', line 83 def ok_view @ok_view ||= format.monitor_depth { altered_view || requested_view } end |
#process ⇒ rendered view or a stub
handle rendering, including optional visibility, permissions, and caching
67 68 69 70 71 |
# File 'lib/card/view.rb', line 67 def process return if == :hide fetch { yield ok_view } end |
#requested_view ⇒ Symbol
the view to "attempt". Typically the same as @raw_view, but @raw_view can be overridden, eg for the main view (top view of the main card on a page)
76 77 78 |
# File 'lib/card/view.rb', line 76 def requested_view @requested_view ||= View.normalize [:view] end |
#root ⇒ Card::View
88 89 90 |
# File 'lib/card/view.rb', line 88 def root @root = parent ? parent.root : self end |
#root? ⇒ true/false
93 94 95 |
# File 'lib/card/view.rb', line 93 def root? !parent end |