Module: Card::Format::Wrapper

Included in:
Card::Format
Defined in:
card/lib/card/format/wrapper.rb

Instance Method Summary collapse

Instance Method Details

#raise_wrap_error(wrapper) ⇒ Object



40
41
42
43
44
45
46
# File 'card/lib/card/format/wrapper.rb', line 40

def raise_wrap_error wrapper
  if wrapper.is_a? String
    raise Card::Error::UserError, "unknown layout card: #{wrapper}"
  else
    raise ArgumentError, "unknown wrapper: #{wrapper}"
  end
end

#render_with_card_layout(mark) ⇒ Object



34
35
36
37
38
# File 'card/lib/card/format/wrapper.rb', line 34

def render_with_card_layout mark
  return unless Card::Layout.card_layout? mark

  Card::Layout::CardLayout.new(mark, self).render
end

#render_with_wrapper(wrapper, opts) ⇒ Object



30
31
32
# File 'card/lib/card/format/wrapper.rb', line 30

def render_with_wrapper wrapper, opts
  try("wrap_with_#{wrapper}", opts) { @rendered }
end

#send_wrapper_method(method_name, opts) ⇒ Object



48
49
50
51
52
53
54
# File 'card/lib/card/format/wrapper.rb', line 48

def send_wrapper_method method_name, opts
  if method(method_name).arity.zero?
    send method_name
  else
    send method_name, (opts&.clone || {})
  end
end

#with_wrapperObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'card/lib/card/format/wrapper.rb', line 4

def with_wrapper
  if voo.layout.present?
    voo.wrap ||= []
    layout = voo.layout.to_name.key
    # don't wrap twice with modals or overlays
    # this can happen if the view is wrapped with modal
    # and is requested with layout=modal param
    voo.wrap.unshift layout unless voo.wrap.include? layout.to_sym
  end

  @rendered = yield
  wrap_with_wrapper
end

#wrap_with_wrapperObject



18
19
20
21
22
23
24
25
26
27
28
# File 'card/lib/card/format/wrapper.rb', line 18

def wrap_with_wrapper
  return @rendered unless voo.wrap.present?

  voo.wrap.reverse.each do |wrapper, opts|
    @rendered =
      render_with_wrapper(wrapper, opts) ||
      render_with_card_layout(wrapper) ||
      raise_wrap_error(wrapper)
  end
  @rendered
end