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. It can only be used in situations where the card identifier, known options, and nest mode comprise all the info needed to reproduce the view as intended

Instance Method Summary collapse

Instance Method Details

#stubObject



7
8
9
# File 'lib/card/view/stub.rb', line 7

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

#stub_hashObject



15
16
17
18
19
20
21
# File 'lib/card/view/stub.rb', line 15

def stub_hash
  {
    cast: card.cast,
    options: normalized_options,
    mode: format.mode
  }
end

#stub_jsonObject



11
12
13
# File 'lib/card/view/stub.rb', line 11

def stub_json
  JSON.generate stub_hash
end

#validate_stubObject



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

def validate_stub
  return if foreign_normalized_options.empty?
  raise "INVALID STUB: #{card.name}/#{ok_view}" \
        " has foreign options: #{foreign_normalized_options}"
end