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 Permission
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.
-
#interior ⇒ Object
Returns the value of attribute interior.
-
#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.
- #depth ⇒ Object
-
#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
#explicit_show?, #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.
56 57 58 59 60 61 62 63 64 |
# File 'lib/card/view.rb', line 56 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 |
#interior ⇒ Object
Returns the value of attribute interior.
30 31 32 |
# File 'lib/card/view.rb', line 30 def interior @interior 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.
34 35 36 |
# File 'lib/card/view.rb', line 34 def normalize view view.present? ? view.to_sym : nil end |
.normalize_list(val) ⇒ Array
Returns list of viewnames as Symbols.
39 40 41 42 43 44 45 46 47 |
# File 'lib/card/view.rb', line 39 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
99 100 101 |
# File 'lib/card/view.rb', line 99 def deep_root format.root.voo end |
#deep_root? ⇒ true/false
neither view nor format has a parent
105 106 107 |
# File 'lib/card/view.rb', line 105 def deep_root? !parent && !format.parent end |
#depth ⇒ Object
109 110 111 |
# File 'lib/card/view.rb', line 109 def depth @depth ||= parent ? (parent.depth + 1) : 0 end |
#next_ancestor(across_format = true) ⇒ Card::View
next voo object found tracing ancestry through parent voos and/or parent formats
115 116 117 |
# File 'lib/card/view.rb', line 115 def next_ancestor across_format=true parent || (across_format && next_format_ancestor) || nil end |
#next_format_ancestor ⇒ Object
voo object of format’s parent
120 121 122 |
# File 'lib/card/view.rb', line 120 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.
84 85 86 |
# File 'lib/card/view.rb', line 84 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
68 69 70 71 72 |
# File 'lib/card/view.rb', line 68 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)
77 78 79 |
# File 'lib/card/view.rb', line 77 def requested_view @requested_view ||= View.normalize [:view] end |
#root ⇒ Card::View
89 90 91 |
# File 'lib/card/view.rb', line 89 def root @root = parent ? parent.root : self end |
#root? ⇒ true/false
94 95 96 |
# File 'lib/card/view.rb', line 94 def root? !parent end |