Class: Card::Format

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload, Registration
Includes:
Env::Location, Content, ContextNames, Error, MethodDelegation, Nesting, Render, Wrapper
Defined in:
lib/card/format.rb,
lib/card/format/nest.rb,
lib/card/format/error.rb,
lib/card/format/render.rb,
lib/card/format/content.rb,
lib/card/format/nesting.rb,
lib/card/format/wrapper.rb,
lib/card/format/nest/fetch.rb,
lib/card/format/nesting/main.rb,
lib/card/format/nesting/mode.rb,
lib/card/format/registration.rb,
lib/card/format/context_names.rb,
lib/card/format/card_action_view.rb,
lib/card/format/method_delegation.rb,
lib/card/format/nesting/subformat.rb

Overview

Card::Format and its subclasses (HtmlFormat, JsonFormat, 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 mods.

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

Defined Under Namespace

Modules: Content, ContextNames, Error, MethodDelegation, Nesting, Registration, Render, Wrapper Classes: CardActionView, Nest

Constant Summary

Constants included from MethodDelegation

MethodDelegation::RENDER_METHOD_RE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Registration

class_from_name, format_ancestry, format_class, format_class_name, format_sym, new, register

Methods included from MethodDelegation

#action_view, #api_render

Methods included from Error

#anyone_can?, #error_cardname, #loud_error, #loud_error?, #monitor_depth, #ok?, #quiet_error, #rendering_error, #rescue_view, #view_for_denial, #view_for_unknown

Methods included from Content

#add_class, #content_nest, #css_classes, #format_date, #id_counter, #output, #prepend_class, #process_content, #safe_process_content, #unique_id

Methods included from ContextNames

#add_name_context, #context_names, #context_names_from_params, #context_names_to_params, #initial_context_names, #naming, #relevant_context_names, #title_in_context

Methods included from Wrapper

#raise_wrap_error, #render_with_card_layout, #render_with_wrapper, #send_wrapper_method, #with_wrapper, #wrap_with_wrapper

Methods included from Render

#add_debug_info, #before_view, #current_view, #expand_stubs, #final_render, #final_render_call, #prepare_stub_nest, #pretty_path, #render!, #show_debug_info?, #show_view?, #stub_debugging, #stub_nest, #stub_render, #supports_view?, #view_cache_setting, #view_method, #view_setting, #voo, #with_voo, #wrap_and_render

Methods included from Nesting

#default_nest_view, #field_nest, #implicit_nest_view, #nest, #nest_path

Methods included from Nesting::Mode

#configured_view_in_compact_mode, #hide_view_in_edit_mode?, #modal_nest_view, #nest_mode, #view_in_compact_mode, #view_in_edit_mode, #with_altered_nest_mode, #with_nest_mode

Methods included from Nesting::Subformat

#depth, #field_subformat, #focal?, #inherit, #main, #main?, #root, #root?, #subformat

Methods included from Nesting::Main

#already_mained?, #main!, #main_nest, #main_nest?, #main_nest_options, #main_nest_render, #wrap_main

Methods included from Env::Location

#card_path, #card_url, #cardname_from_url, #relative_url_root

Constructor Details

#initialize(card, opts = {}) ⇒ Format

Returns a new instance of Format.



43
44
45
46
47
48
# File 'lib/card/format.rb', line 43

def initialize card, opts={}
  @card = card
  require_card_to_initialize!
  opts.each { |key, value| instance_variable_set "@#{key}", value }
  include_set_format_modules
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Card::Format::MethodDelegation

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



33
34
35
# File 'lib/card/format.rb', line 33

def card
  @card
end

#error_statusObject

Returns the value of attribute error_status.



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

def error_status
  @error_status
end

#formObject

Returns the value of attribute form.



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

def form
  @form
end

#main_optsObject (readonly)

Returns the value of attribute main_opts.



33
34
35
# File 'lib/card/format.rb', line 33

def main_opts
  @main_opts
end

Returns the value of attribute modal_opts.



33
34
35
# File 'lib/card/format.rb', line 33

def modal_opts
  @modal_opts
end

#parentObject (readonly)

Returns the value of attribute parent.



33
34
35
# File 'lib/card/format.rb', line 33

def parent
  @parent
end

#renderedObject

Returns the value of attribute rendered.



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

def rendered
  @rendered
end

Class Method Details

.view_caching?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/card/format.rb', line 39

def self.view_caching?
  true
end

Instance Method Details

#controllerObject



72
73
74
# File 'lib/card/format.rb', line 72

def controller
  @controller || Env.controller ||= CardController.new
end

#escape_literal(literal) ⇒ Object



84
85
86
# File 'lib/card/format.rb', line 84

def escape_literal literal
  literal
end

#include_set_format_modulesObject



56
57
58
59
60
61
62
# File 'lib/card/format.rb', line 56

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_typeObject



80
81
82
# File 'lib/card/format.rb', line 80

def mime_type
  "text/plain"
end

#page(controller, view, slot_opts) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/card/format.rb', line 64

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_urlObject



76
77
78
# File 'lib/card/format.rb', line 76

def request_url
  controller.request&.original_url || path
end

#require_card_to_initialize!Object

Raises:



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

def require_card_to_initialize!
  return if @card

  raise Card::Error, ::I18n.t(:lib_exception_init_without_card)
end

#to_symObject



88
89
90
# File 'lib/card/format.rb', line 88

def to_sym
  Card::Format.format_sym self
end