Class: Card::Format

Inherits:
Object show all
Extended by:
ActiveSupport::Autoload, Registration
Includes:
Env::Location, Content, ContextNames, Error, MethodDelegation, Nesting, Render, Wrapper
Defined in:
card/lib/card/format.rb,
card/lib/card/format/nest.rb,
card/lib/card/format/error.rb,
card/lib/card/format/render.rb,
card/lib/card/format/content.rb,
card/lib/card/format/nesting.rb,
card/lib/card/format/wrapper.rb,
card/lib/card/format/nest/fetch.rb,
card/lib/card/format/nesting/main.rb,
card/lib/card/format/nesting/mode.rb,
card/lib/card/format/registration.rb,
card/lib/card/format/context_names.rb,
card/lib/card/format/card_action_view.rb,
card/lib/card/format/method_delegation.rb,
card/lib/card/format/nesting/subformat.rb,
card-mod-format/lib/card/format/js_format.rb,
card-mod-format/lib/card/format/css_format.rb,
card-mod-format/lib/card/format/csv_format.rb,
card-mod-format/lib/card/format/rss_format.rb,
card-mod-format/lib/card/format/xml_format.rb,
card-mod-format/lib/card/format/data_format.rb,
card-mod-format/lib/card/format/file_format.rb,
card-mod-format/lib/card/format/html_format.rb,
card-mod-format/lib/card/format/json_format.rb,
card-mod-format/lib/card/format/text_format.rb,
card-mod-email/lib/card/format/email_html_format.rb,
card-mod-email/lib/card/format/email_text_format.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, CssFormat, CsvFormat, DataFormat, EmailHtmlFormat, EmailTextFormat, FileFormat, HtmlFormat, JsFormat, JsonFormat, Nest, RssFormat, TextFormat, XmlFormat

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, #log_error, #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, #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

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, #protocol_and_host

Constructor Details

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

Returns a new instance of Format.



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

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 'card/lib/card/format.rb', line 33

def card
  @card
end

#error_statusObject

Returns the value of attribute error_status.



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

def error_status
  @error_status
end

#formObject

Returns the value of attribute form.



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

def form
  @form
end

#main_optsObject (readonly)

Returns the value of attribute main_opts.



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

def main_opts
  @main_opts
end

Returns the value of attribute modal_opts.



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

def modal_opts
  @modal_opts
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#renderedObject

Returns the value of attribute rendered.



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

def rendered
  @rendered
end

Class Method Details

.view_caching?Boolean

Returns:

  • (Boolean)


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

def self.view_caching?
  true
end

Instance Method Details

#controllerObject



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

def controller
  @controller || Env[:controller] ||= CardController.new
end

#escape_literal(literal) ⇒ Object



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

def escape_literal literal
  literal
end

#include_set_format_modulesObject



53
54
55
56
57
58
59
# File 'card/lib/card/format.rb', line 53

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



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

def mime_type
  "text/plain"
end

#page(controller, view, slot_opts) ⇒ Object



61
62
63
64
65
66
67
# File 'card/lib/card/format.rb', line 61

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

#paramsObject



69
70
71
# File 'card/lib/card/format.rb', line 69

def params
  Env.params
end

#require_card_to_initialize!Object

Raises:



47
48
49
50
51
# File 'card/lib/card/format.rb', line 47

def require_card_to_initialize!
  return if @card

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

#sessionObject



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

def session
  Env.session
end

#to_symObject



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

def to_sym
  Card::Format.format_sym self
end