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.
Class Method Summary collapse
Instance Method Summary collapse
- #stub ⇒ String
- #stub_hash ⇒ Hash
-
#stub_json ⇒ String
The stub_hash as JSON.
Class Method Details
.escape(stub_json) ⇒ Object
13 14 15 |
# File 'lib/card/view/stub.rb', line 13 def escape stub_json stub_json.gsub "(", "_OParEN_" end |
.unescape(stub_json) ⇒ Object
17 18 19 |
# File 'lib/card/view/stub.rb', line 17 def unescape stub_json stub_json.gsub "_OParEN_", "(" end |
Instance Method Details
#stub ⇒ String
23 24 25 |
# File 'lib/card/view/stub.rb', line 23 def stub "(stub)#{Stub.escape stub_json}(/stub)".html_safe end |
#stub_hash ⇒ Hash
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/card/view/stub.rb', line 33 def stub_hash { cast: card.cast, view_opts: , format_opts: { nest_mode: format.nest_mode, override: root? } } # nest mode handling: # 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 end |
#stub_json ⇒ String
Returns the stub_hash as JSON.
28 29 30 |
# File 'lib/card/view/stub.rb', line 28 def stub_json JSON.generate stub_hash end |