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
-
#invalid_stub ⇒ Object
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.
- #reject_foreign_options_in_stub! ⇒ Object
- #stub ⇒ String
- #stub_hash ⇒ Hash
-
#stub_json ⇒ String
The stub_hash as JSON.
- #validate_stub! ⇒ Object
-
#with_override(hash) ⇒ Hash
handle nest_mode in stub.
Instance Method Details
#invalid_stub ⇒ Object
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 return if .empty? raise invalid_stub + " has foreign options: #{}" end |
#stub ⇒ String
13 14 15 |
# File 'lib/card/view/stub.rb', line 13 def stub "<card-view>#{stub_json}</card-view>".html_safe end |
#stub_hash ⇒ 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: , override: root? end |
#stub_json ⇒ String
Returns 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_illegal_stub_values! end |
#with_override(hash) ⇒ Hash
handle nest_mode in stub
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 |