Module: Card::View::Stub

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

Overview

A "stub" is a placeholder for a card view.

Cached views use stubs so that nesting content can remained cached even while nested content changes. The nested content's place is held by a stub.

A stub must contain all the information necessary to produce the view as intended.

Instance Method Summary collapse

Instance Method Details

#invalid_stubObject

def reject_illegal_stub_values! normalized_options.each do |key, value| next unless value =~ /</ raise invalid_stub + " has illegal value for #key: #value" end end



53
54
55
# File 'lib/card/view/stub.rb', line 53

def invalid_stub
  "INVALID STUB: #{card.name}/#{ok_view}"
end

#reject_foreign_options_in_stub!Object



58
59
60
61
# File 'lib/card/view/stub.rb', line 58

def reject_foreign_options_in_stub!
  return if foreign_normalized_options.empty?
  raise invalid_stub + " has foreign options: #{foreign_normalized_options}"
end

#stubString

Returns:

  • (String)


13
14
15
# File 'lib/card/view/stub.rb', line 13

def stub
  "<card-view>#{stub_json}</card-view>".html_safe
end

#stub_hashHash

Returns:

  • (Hash)


23
24
25
26
27
28
# File 'lib/card/view/stub.rb', line 23

def stub_hash
  with_override mode: format.nest_mode,
                cast: card.cast,
                options: normalized_options,
                override: root?
end

#stub_jsonString

Returns the stub_hash as JSON.

Returns:

  • (String)

    the stub_hash as JSON



18
19
20
# File 'lib/card/view/stub.rb', line 18

def stub_json
  JSON.generate stub_hash
end

#validate_stub!Object



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

def validate_stub!
  reject_foreign_options_in_stub!
  #reject_illegal_stub_values!
end

#with_override(hash) ⇒ Hash

handle nest_mode in stub

Returns:

  • (Hash)


32
33
34
35
36
37
38
39
# File 'lib/card/view/stub.rb', line 32

def with_override hash

  # typically modes only override views on nests, but stubs create non-standard nests
  # mode-based view overrides should NOT apply to standard render calls that have
  # been replaced with stubs - only to standard nest calls. therefore modes are not
  # stored in non-standard nest stubs
  hash
end