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.



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

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


85
86
87
# File 'lib/card/view/options.rb', line 85

def normalized_options
  @normalized_options
end

Class Method Details

.accessible_keysObject



60
61
62
# File 'lib/card/view/options.rb', line 60

def accessible_keys
  heir_keys + [:nest_name, :nest_syntax] - [:items]
end

.all_keysObject

all standard option keys



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

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

.define_getter(option_key) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/card/view/options.rb', line 64

def define_getter option_key
  define_method option_key do
    norm_method = "normalize_#{option_key}"
    value = live_options[option_key]
    try(norm_method, value) || value
  end
end

.define_setter(option_key) ⇒ Object



72
73
74
75
76
# File 'lib/card/view/options.rb', line 72

def define_setter option_key
  define_method "#{option_key}=" do |value|
    live_options[option_key] = value
  end
end

.heir_keysObject

keys that follow simple standard inheritance pattern from parent views



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

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



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

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

Instance Method Details

#closest_live_option(key) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/card/view/options.rb', line 117

def closest_live_option key
  if live_options.key? key
    live_options[key]
  else
    (parent && parent.closest_live_option(key)) ||
      (format.parent && format.parent.voo &&
        format.parent.voo.closest_live_option(key))
  end
end

#itemsObject

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



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

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

#live_optionsObject



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

def live_options
  @live_options ||= process_live_options
end

#normalize_cache(value) ⇒ Object



107
108
109
# File 'lib/card/view/options.rb', line 107

def normalize_cache value
  value && value.to_sym
end

#normalize_editor(value) ⇒ Object



103
104
105
# File 'lib/card/view/options.rb', line 103

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)



113
114
115
# File 'lib/card/view/options.rb', line 113

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