Class: Card::View

Inherits:
Object
  • Object
show all
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

Attributes included from Options::VooApi

#normalized_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cache::ClassMethods

cache, caching, caching?

Methods included from Permission

#view_perms

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

add_option

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.

Parameters:

  • format (Card::Format)
  • 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.

  • raw_options (Hash) (defaults to: {})
  • parent (Card::View) (defaults to: nil)

    (optional)



55
56
57
58
59
60
61
62
63
# File 'lib/card/view.rb', line 55

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

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



29
30
31
# File 'lib/card/view.rb', line 29

def card
  @card
end

#formatObject (readonly)

Returns the value of attribute format.



29
30
31
# File 'lib/card/view.rb', line 29

def format
  @format
end

#parentObject (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.

Returns:

  • (Symbol)

    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.

Returns:

  • (Array)

    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_rootObject

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

Returns:

  • (true/false)


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

Returns:



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_ancestorObject

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_viewSymbol

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

Returns:

  • (Symbol)

    view name



83
84
85
# File 'lib/card/view.rb', line 83

def ok_view
  @ok_view ||= format.monitor_depth { altered_view || requested_view }
end

#processrendered view or a stub

handle rendering, including optional visibility, permissions, and caching

Returns:

  • (rendered view or a stub)


67
68
69
70
71
# File 'lib/card/view.rb', line 67

def process
  return if process_live_options == :hide

  fetch { yield ok_view }
end

#requested_viewSymbol

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)

Returns:

  • (Symbol)

    view name



76
77
78
# File 'lib/card/view.rb', line 76

def requested_view
  @requested_view ||= View.normalize live_options[:view]
end

#rootCard::View

Returns:



88
89
90
# File 'lib/card/view.rb', line 88

def root
  @root = parent ? parent.root : self
end

#root?true/false

Returns:

  • (true/false)


93
94
95
# File 'lib/card/view.rb', line 93

def root?
  !parent
end