Module: Card::Format::Wrapper
- Included in:
- Card::Format
- Defined in:
- lib/card/format/wrapper.rb
Instance Method Summary collapse
- #raise_wrap_error(wrapper) ⇒ Object
- #render_with_card_layout(mark) ⇒ Object
- #render_with_wrapper(wrapper, opts) ⇒ Object
- #send_wrapper_method(method_name, opts) ⇒ Object
- #with_wrapper ⇒ Object
- #wrap_with_wrapper ⇒ Object
Instance Method Details
#raise_wrap_error(wrapper) ⇒ Object
40 41 42 43 44 45 46 |
# File '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 '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 '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 '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_wrapper ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File '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_wrapper ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File '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 |