Class: Card::Format::HtmlFormat

Inherits:
Card::Format show all
Defined in:
mod/core/format/html_format.rb

Direct Known Subclasses

EmailHtmlFormat, RssFormat

Constant Summary collapse

LAYOUTS =

TODO: use CodeFile cards for these builtin layouts allow for rescue / testing

Mod::Loader.load_layouts.merge "none" => "{{_main}}"

Constants inherited from Card::Format

VIEW_VARS

Constants included from MethodDelegation

MethodDelegation::RENDER_METHOD_RE

Instance Attribute Summary collapse

Attributes inherited from Card::Format

#card, #error_status, #form, #main_opts, #parent

Instance Method Summary collapse

Methods inherited from Card::Format

#controller, #include_set_format_modules, #initialize, #page, #params, #require_card_to_initialize!, #session, #tagged, #template, #to_sym, view_caching?

Methods included from Registration

#class_from_name, #extract_class_vars, #extract_view_tags, #format_ancestry, #format_class, #format_class_name, #format_sym, #interpret_view_opts, #new, #register, #tagged, #view_cache_setting_method

Methods included from MethodDelegation

#api_render, #method_missing, #pass_method_to_template_object, #render_args, #respond_to_missing?

Methods included from Error

#error_cardname, #loud_error, #loud_error?, #quiet_error, #rendering_error, #rescue_view

Methods included from Content

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

Methods included from ContextNames

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

Methods included from Render

#add_debug_info, #before_view, #current_view, #expand_stubs, #final_render, #prepare_stub_nest, #pretty_path, #render!, #show_debug_info?, #show_view?, #stub_render, #supports_view?, #view_cache_setting, #view_method, #view_method_name, #voo, #with_voo

Methods included from Permission

#check_view, #deny_view, #handle_view_denial, #ok?, #ok_view, #permitted_view, #subformats_nested_too_deeply?, #task_denied_for_view, #unknown_disqualifies_view?, #view_always_permitted?, #view_for_unknown

Methods included from Nesting

#field_nest, #implicit_nest_view, #nest, #nest_path

Methods included from Nesting::Mode

#configured_view_in_closed_mode, #hide_view_in_edit_mode?, #modal_nest_view, #nest_mode, #view_in_closed_mode, #view_in_edit_mode, #with_altered_nest_mode, #with_nest_mode

Methods included from Nesting::Subformat

#depth, #field_subformat, #inherit, #root, #subformat

Methods included from Nesting::Main

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

Methods included from Env::Location

#card_path, #card_url, #protocol_and_host

Constructor Details

This class inherits a constructor from Card::Format

Dynamic Method Handling

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

Instance Attribute Details

#options_need_saveObject

Returns the value of attribute options_need_save.



10
11
12
# File 'mod/core/format/html_format.rb', line 10

def options_need_save
  @options_need_save
end

#skip_autosaveObject

Returns the value of attribute skip_autosave.



10
11
12
# File 'mod/core/format/html_format.rb', line 10

def skip_autosave
  @skip_autosave
end

#start_timeObject

Returns the value of attribute start_time.



10
11
12
# File 'mod/core/format/html_format.rb', line 10

def start_time
  @start_time
end

Instance Method Details

#default_item_viewObject



29
30
31
# File 'mod/core/format/html_format.rb', line 29

def default_item_view
  :closed
end

#default_nest_viewObject



24
25
26
27
# File 'mod/core/format/html_format.rb', line 24

def default_nest_view
  # FIXME: not sure this makes sense as a rule...
  card.rule(:default_html_view) || :titled
end

#focal?Boolean

meaning the current card is the requested card

Returns:

  • (Boolean)


20
21
22
# File 'mod/core/format/html_format.rb', line 20

def focal? # meaning the current card is the requested card
  show_layout? ? main? : depth.zero?
end

#get_layout_content(requested_layout) ⇒ Object

helper methods for layout view



34
35
36
37
38
39
40
41
42
# File 'mod/core/format/html_format.rb', line 34

def get_layout_content requested_layout
  Auth.as_bot do
    if requested_layout
      layout_from_card_or_code requested_layout
    else
      layout_from_rule
    end
  end
end

#html_escape_except_quotes(s) ⇒ Object



66
67
68
69
70
# File 'mod/core/format/html_format.rb', line 66

def html_escape_except_quotes s
  # to be used inside single quotes (makes for readable json attributes)
  s.to_s.gsub(/&/, "&").gsub(/\'/, "'")
   .gsub(/>/, "&gt;").gsub(/</, "&lt;")
end

#layout_from_card_or_code(name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'mod/core/format/html_format.rb', line 52

def layout_from_card_or_code name
  layout_card = Card.quick_fetch name
  if layout_card && layout_card.ok?(:read)
    layout_card.content
  elsif (hardcoded_layout = LAYOUTS[name])
    hardcoded_layout
  else
    (:h1, I18n.t(:unknown_layout, scope: "mod.core.format.html_format",
                                             name: name)) +
      I18n.t(:built_in, scope: "mod.core.format.html_format",
                        built_in_layouts: LAYOUTS.keys.join(', '))
  end
end

#layout_from_ruleObject



44
45
46
47
48
49
50
# File 'mod/core/format/html_format.rb', line 44

def layout_from_rule
  if (rule = card.rule_card :layout) &&
     (rule.type_id == Card::PointerID) &&
     (layout_name = rule.item_name)
    layout_from_card_or_code layout_name
  end
end

#main?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'mod/core/format/html_format.rb', line 16

def main?
  !@main.nil?
end

#mime_typeObject



72
73
74
# File 'mod/core/format/html_format.rb', line 72

def mime_type
  "text/html"
end