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
-
#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.
Class Method Details
.escape(stub_json) ⇒ Object
14 15 16 |
# File 'lib/card/view/stub.rb', line 14 def escape stub_json stub_json.gsub "(", "_OParEN_" end |
.unescape(stub_json) ⇒ Object
18 19 20 |
# File 'lib/card/view/stub.rb', line 18 def unescape stub_json stub_json.gsub "_OParEN_", "(" end |
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
64 65 66 |
# File 'lib/card/view/stub.rb', line 64 def invalid_stub "INVALID STUB: #{card.name}/#{ok_view}" end |
#reject_foreign_options_in_stub! ⇒ Object
69 70 71 72 |
# File 'lib/card/view/stub.rb', line 69 def return if .empty? raise invalid_stub + " has foreign options: #{}" end |
#stub ⇒ String
24 25 26 |
# File 'lib/card/view/stub.rb', line 24 def stub "(stub)#{Stub.escape stub_json}(/stub)".html_safe end |
#stub_hash ⇒ Hash
34 35 36 37 38 39 |
# File 'lib/card/view/stub.rb', line 34 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.
29 30 31 |
# File 'lib/card/view/stub.rb', line 29 def stub_json JSON.generate stub_hash end |
#validate_stub! ⇒ Object
52 53 54 55 |
# File 'lib/card/view/stub.rb', line 52 def validate_stub! #reject_illegal_stub_values! end |
#with_override(hash) ⇒ Hash
handle nest_mode in stub
43 44 45 46 47 48 49 50 |
# File 'lib/card/view/stub.rb', line 43 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 |