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,
mod/format/lib/card/format/js_format.rb,
card/lib/card/format/card_action_view.rb,
mod/format/lib/card/format/css_format.rb,
mod/format/lib/card/format/csv_format.rb,
mod/format/lib/card/format/rss_format.rb,
mod/format/lib/card/format/xml_format.rb,
card/lib/card/format/method_delegation.rb,
card/lib/card/format/nesting/subformat.rb,
mod/format/lib/card/format/data_format.rb,
mod/format/lib/card/format/file_format.rb,
mod/format/lib/card/format/html_format.rb,
mod/format/lib/card/format/json_format.rb,
mod/format/lib/card/format/scss_format.rb,
mod/format/lib/card/format/text_format.rb,
mod/format/lib/card/format/yaml_format.rb,
mod/email/lib/card/format/email_html_format.rb,
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, ScssFormat, TextFormat, XmlFormat, YamlFormat

Constant Summary

Constants included from MethodDelegation

MethodDelegation::RENDER_METHOD_RE

Class Attribute Summary collapse

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, 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_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.



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

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

Class Attribute Details

.symbol=(value) ⇒ Object (writeonly)

Sets the attribute symbol

Parameters:

  • value

    the value to set the attribute symbol to.



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

def symbol=(value)
  @symbol = value
end

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)


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

def view_caching?
  true
end

Instance Method Details

#controllerObject



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

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

#escape_literal(literal) ⇒ Object



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

def escape_literal literal
  literal
end

#include_set_format_modulesObject



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

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



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

def mime_type
  "text/plain"
end

#page(controller, view, slot_opts) ⇒ Object



70
71
72
73
74
75
76
# File 'card/lib/card/format.rb', line 70

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



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

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

#require_card_to_initialize!Object

Raises:



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

def require_card_to_initialize!
  return if @card

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

#symbolObject Also known as: to_sym



94
95
96
# File 'card/lib/card/format.rb', line 94

def symbol
  self.class.symbol
end