Class: Card::Content::Chunk::ViewStub
- Inherits:
-
Abstract
- Object
- Abstract
- Card::Content::Chunk::ViewStub
- Defined in:
- lib/card/content/chunk/view_stub.rb
Overview
handle chunks of card content that are “stubbed” versions of views (stubs allow caching of containers)
Instance Method Summary collapse
- #hex_to_bin(string) ⇒ Object
- #initial_stub_hash(string) ⇒ Object
- #interpret(match, _content) ⇒ Object
- #interpret_cast ⇒ Object
- #interpret_format_opts ⇒ Object
- #interpret_hash_values ⇒ Object
- #interpret_view_opts ⇒ Object
- #process_chunk ⇒ Object
- #result ⇒ Object
Instance Method Details
#hex_to_bin(string) ⇒ Object
24 25 26 |
# File 'lib/card/content/chunk/view_stub.rb', line 24 def hex_to_bin string string.scan(/../).map { |x| x.hex.chr }.join end |
#initial_stub_hash(string) ⇒ Object
19 20 21 22 |
# File 'lib/card/content/chunk/view_stub.rb', line 19 def initial_stub_hash string JSON.parse(string).symbolize_keys # MessagePack.unpack(hex_to_bin(string)).symbolize_keys end |
#interpret(match, _content) ⇒ Object
14 15 16 17 |
# File 'lib/card/content/chunk/view_stub.rb', line 14 def interpret match, _content @stub_hash = initial_stub_hash match[1] interpret_hash_values end |
#interpret_cast ⇒ Object
34 35 36 |
# File 'lib/card/content/chunk/view_stub.rb', line 34 def interpret_cast @stub_hash[:cast].symbolize_keys! end |
#interpret_format_opts ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/card/content/chunk/view_stub.rb', line 42 def interpret_format_opts hash = @stub_hash[:format_opts] hash.symbolize_keys! hash[:nest_mode] = hash[:nest_mode].to_sym hash[:override] = hash[:override] == "true" hash[:context_names].map!(&:to_name) end |
#interpret_hash_values ⇒ Object
28 29 30 31 32 |
# File 'lib/card/content/chunk/view_stub.rb', line 28 def interpret_hash_values @stub_hash.each_key do |key| send "interpret_#{key}" end end |
#interpret_view_opts ⇒ Object
38 39 40 |
# File 'lib/card/content/chunk/view_stub.rb', line 38 def interpret_view_opts @stub_hash[:view_opts].symbolize_keys! end |
#process_chunk ⇒ Object
50 51 52 |
# File 'lib/card/content/chunk/view_stub.rb', line 50 def process_chunk @processed = format.stub_nest @stub_hash end |
#result ⇒ Object
54 55 56 |
# File 'lib/card/content/chunk/view_stub.rb', line 54 def result @processed end |