Class: Card::Format
- Inherits:
-
Object
- Object
- Card::Format
- Extended by:
- ActiveSupport::Autoload, Registration
- Includes:
- Env::Location, Content, ContextNames, Error, MethodDelegation, Nesting, Render
- 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/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/method_delegation.rb,
lib/card/format/nesting/subformat.rb,
mod/core/format/data_format.rb,
mod/core/format/html_format.rb,
mod/core/format/text_format.rb,
mod/basic_formats/format/js_format.rb,
mod/email/format/email_html_format.rb,
mod/email/format/email_text_format.rb,
mod/basic_formats/format/css_format.rb,
mod/basic_formats/format/csv_format.rb,
mod/basic_formats/format/rss_format.rb,
mod/basic_formats/format/xml_format.rb,
mod/basic_formats/format/file_format.rb,
mod/basic_formats/format/json_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.
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.
Direct Known Subclasses
CssFormat, DataFormat, FileFormat, HtmlFormat, JsFormat, TextFormat
Defined Under Namespace
Modules: Content, ContextNames, Error, MethodDelegation, Nesting, Registration, Render Classes: 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
-
#card ⇒ Object
readonly
Returns the value of attribute card.
-
#error_status ⇒ Object
Returns the value of attribute error_status.
-
#form ⇒ Object
Returns the value of attribute form.
-
#main_opts ⇒ Object
readonly
Returns the value of attribute main_opts.
-
#modal_opts ⇒ Object
readonly
Returns the value of attribute modal_opts.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#rendered ⇒ Object
Returns the value of attribute rendered.
Class Method Summary collapse
Instance Method Summary collapse
- #controller ⇒ Object
- #escape_literal(literal) ⇒ Object
- #include_set_format_modules ⇒ Object
-
#initialize(card, opts = {}) ⇒ Format
constructor
A new instance of Format.
- #mime_type ⇒ Object
- #page(controller, view, slot_opts) ⇒ Object
- #params ⇒ Object
- #require_card_to_initialize! ⇒ Object
- #session ⇒ Object
- #template ⇒ Object
- #to_sym ⇒ Object
Methods included from Registration
class_from_name, format_ancestry, format_class, format_class_name, format_sym, new, register
Methods included from MethodDelegation
#api_render, #method_missing, #pass_method_to_template_object, #render_args, #respond_to_missing?
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 Render
#add_debug_info, #before_view, #current_view, #expand_stubs, #final_render, #final_render_call, #prepare_stub_nest, #pretty_path, #raise_wrap_error, #render!, #render_with_card_layout, #render_with_wrapper, #show_debug_info?, #show_view?, #stub_debugging, #stub_nest, #stub_render, #supports_view?, #view_cache_setting, #view_method, #view_setting, #voo, #with_voo, #with_wrapper, #wrap_with_wrapper
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.
39 40 41 42 43 44 |
# File 'lib/card/format.rb', line 39 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
#card ⇒ Object (readonly)
Returns the value of attribute card.
32 33 34 |
# File 'lib/card/format.rb', line 32 def card @card end |
#error_status ⇒ Object
Returns the value of attribute error_status.
33 34 35 |
# File 'lib/card/format.rb', line 33 def error_status @error_status end |
#form ⇒ Object
Returns the value of attribute form.
33 34 35 |
# File 'lib/card/format.rb', line 33 def form @form end |
#main_opts ⇒ Object (readonly)
Returns the value of attribute main_opts.
32 33 34 |
# File 'lib/card/format.rb', line 32 def main_opts @main_opts end |
#modal_opts ⇒ Object (readonly)
Returns the value of attribute modal_opts.
32 33 34 |
# File 'lib/card/format.rb', line 32 def modal_opts @modal_opts end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
32 33 34 |
# File 'lib/card/format.rb', line 32 def parent @parent end |
#rendered ⇒ Object
Returns the value of attribute rendered.
33 34 35 |
# File 'lib/card/format.rb', line 33 def rendered @rendered end |
Class Method Details
.view_caching? ⇒ Boolean
35 36 37 |
# File 'lib/card/format.rb', line 35 def self.view_caching? true end |
Instance Method Details
#controller ⇒ Object
73 74 75 |
# File 'lib/card/format.rb', line 73 def controller @controller || Env[:controller] ||= CardController.new end |
#escape_literal(literal) ⇒ Object
97 98 99 |
# File 'lib/card/format.rb', line 97 def escape_literal literal literal end |
#include_set_format_modules ⇒ Object
53 54 55 56 57 58 59 |
# File '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_type ⇒ Object
93 94 95 |
# File 'lib/card/format.rb', line 93 def mime_type "text/plain" end |
#page(controller, view, slot_opts) ⇒ Object
61 62 63 64 65 66 67 |
# File '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 |
#require_card_to_initialize! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/card/format.rb', line 46 def require_card_to_initialize! return if @card msg = I18n.t :exception_init_without_card, scope: "lib.card.format" raise Card::Error, msg end |
#template ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/card/format.rb', line 81 def template @template ||= begin c = controller lookup_context = ActionView::LookupContext.new c.class.view_paths t = ActionView::Base.new( lookup_context, { _routes: c._routes }, c ) t.extend c.class._helpers t end end |
#to_sym ⇒ Object
101 102 103 |
# File 'lib/card/format.rb', line 101 def to_sym Card::Format.format_sym self end |