class Card::Format

Card::Format and its subclasses ({Card::Format::HtmlFormat}, {Card::Format::JsonFormat}, {Card::Format::XmlFormat}, etc) are responsible for defining and rendering views.

However, monkeys (those who code in the Card/Decko framework) rarely write code directly in these classes. Instead they organize their code using {Cardio::Mod mods}.

{Cardio::Mod} explains how to set up a mod. {Card::Set::Format} explains how to use this and other format classes within a mod. {Card::Set::Format::AbstractFormat} introduces the view API, which is organized with these format classes.

Attributes

card[R]
error_status[RW]
form[RW]
main_opts[R]
modal_opts[R]
parent[R]
rendered[RW]

Public Class Methods

new(card, opts={}) click to toggle source
# File lib/card/format.rb, line 42
def initialize card, opts={}
  @card = card
  require_card_to_initialize!
  opts.each { |key, value| instance_variable_set "@#{key}", value }
  include_set_format_modules
end
view_caching?() click to toggle source
# File lib/card/format.rb, line 38
def self.view_caching?
  true
end

Public Instance Methods

controller() click to toggle source
# File lib/card/format.rb, line 71
def controller
  @controller || Env.controller ||= CardController.new
end
escape_literal(literal) click to toggle source
# File lib/card/format.rb, line 83
def escape_literal literal
  literal
end
include_set_format_modules() click to toggle source
# File lib/card/format.rb, line 55
def include_set_format_modules
  self.class.format_ancestry.reverse_each do |klass|
    card.set_format_modules(klass).each do |m|
      singleton_class.send :include, m
    end
  end
end
mime_type() click to toggle source
# File lib/card/format.rb, line 79
def mime_type
  "text/plain"
end
page(controller, view, slot_opts) click to toggle source
# File lib/card/format.rb, line 63
def page controller, view, slot_opts
  @controller = controller
  context_names # loads names and removes #name_context from slot_opts
  @card.run_callbacks :show_page do
    show view, slot_opts
  end
end
request_url() click to toggle source
# File lib/card/format.rb, line 75
def request_url
  controller.request&.original_url || path
end
require_card_to_initialize!() click to toggle source
# File lib/card/format.rb, line 49
def require_card_to_initialize!
  return if @card

  raise Card::Error, ::I18n.t(:lib_exception_init_without_card)
end
to_sym() click to toggle source
# File lib/card/format.rb, line 87
def to_sym
  Card::Format.format_sym self
end