class Card::View

Card::View manages {Options view options}, {Cache view caching}, and {Permission 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 …`

Attributes

card[R]
format[R]
interior[RW]
parent[R]

Public Class Methods

new(format, view, raw_options={}) click to toggle source

@param format [Card::Format] @param view [Symbol] viewname. Note: Card::View is initialized without a view

when `voo` is called outside of a render,
eg `subformat(cardname).method_with_voo_reference`.

@param raw_options [Hash] @param parent [Card::View] (optional)

# File lib/card/view.rb, line 56
def initialize format, view, raw_options={}, parent=nil
  @format = format
  @raw_view = view
  @raw_options = raw_options
  @parent = parent

  @card = @format.card
  normalize_options
end
normalize(view) click to toggle source

@return [Symbol] viewname as Symbol

# File lib/card/view.rb, line 34
def normalize view
  view.present? ? view.to_sym : nil
end
normalize_list(val) click to toggle source

@return [Array] list of viewnames as Symbols

# 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

Public Instance Methods

deep_root() click to toggle source

the root voo of the root format

# File lib/card/view.rb, line 99
def deep_root
  format.root.voo
end
deep_root?() click to toggle source

neither view nor format has a parent @return [true/false]

# File lib/card/view.rb, line 105
def deep_root?
  !parent && !format.parent
end
depth() click to toggle source
# File lib/card/view.rb, line 109
def depth
  @depth ||= parent ? (parent.depth + 1) : 0
end
next_ancestor(across_format=true) click to toggle source

next voo object found tracing ancestry through parent voos and/or parent formats @return [Card::View]

# File lib/card/view.rb, line 115
def next_ancestor across_format=true
  parent || (across_format && next_format_ancestor) || nil
end
next_format_ancestor() click to toggle source

voo object of format’s parent

# File lib/card/view.rb, line 120
def next_format_ancestor
  format.parent&.voo
end
ok_view() click to toggle source

the final view. can be different from @requested_view when there are issues with permissions, recursions, unknown cards, etc. @return [Symbol] view name

# File lib/card/view.rb, line 84
def ok_view
  @ok_view ||= format.monitor_depth { altered_view || requested_view }
end
process() { |ok_view| ... } click to toggle source

handle rendering, including optional visibility, permissions, and caching @return [rendered view or a stub]

# File lib/card/view.rb, line 68
def process
  return if process_live_options == :hide

  fetch { yield ok_view }
end
requested_view() click to toggle source

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) @return [Symbol] view name

# File lib/card/view.rb, line 77
def requested_view
  @requested_view ||= View.normalize live_options[:view]
end
root() click to toggle source

@return [Card::View]

# File lib/card/view.rb, line 89
def root
  @root = parent ? parent.root : self
end
root?() click to toggle source

@return [true/false]

# File lib/card/view.rb, line 94
def root?
  !parent
end