Module: Card::View::Options

Included in:
Card::View
Defined in:
lib/card/view/options.rb

Overview

normalizes and manages standard view options

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.keymapObject (readonly)

Returns the value of attribute keymap.



42
43
44
# File 'lib/card/view/options.rb', line 42

def keymap
  @keymap
end

Instance Attribute Details

#normalized_optionsObject (readonly)

There are two primary options hashes:

  • @normalized_options are determined upon initialization and do not change after that.
  • @live_options are created during the "process" phase, and they can be altered via the "voo" API at any time


66
67
68
# File 'lib/card/view/options.rb', line 66

def normalized_options
  @normalized_options
end

Class Method Details

.all_keysObject

all standard option keys



45
46
47
# File 'lib/card/view/options.rb', line 45

def all_keys
  @all_keys ||= keymap.each_with_object([]) { |(_k, v), a| a.push(*v) }
end

.heir_keysObject

keys that follow simple standard inheritance pattern from parent views



55
56
57
# File 'lib/card/view/options.rb', line 55

def heir_keys
  @heir_keys ||= ::Set.new(keymap[:both]) + keymap[:heir]
end

.nest_keysObject

keys whose values can be set by Wagneers in card nests



50
51
52
# File 'lib/card/view/options.rb', line 50

def nest_keys
  @nest_keys ||= ::Set.new(keymap[:both]) + keymap[:nest]
end

Instance Method Details

#itemsObject

The following methods comprise the primary voo API. They allow developers to read and write options dynamically



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

def items
  live_options[:items] ||= {}
end

#live_optionsObject



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

def live_options
  @live_options ||= process_live_options
end

#normalize_editor(value) ⇒ Object



91
92
93
# File 'lib/card/view/options.rb', line 91

def normalize_editor value
  value && value.to_sym
end

#slot_optionsObject

options to be used in data attributes of card slots (normalized options with standard keys)



97
98
99
# File 'lib/card/view/options.rb', line 97

def slot_options
  normalized_options.select { |k, _v| Options.all_keys.include? k }
end