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 =

builtin layouts allow for rescue / testing

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

Constants included from Render

Render::DEPRECATED_VIEWS

Constants included from Nest::View

Nest::View::NEST_MODES

Instance Attribute Summary collapse

Attributes inherited from Card::Format

#card, #error_status, #form, #main_opts, #nest_opts, #parent, #root

Instance Method Summary collapse

Methods inherited from Card::Format

#controller, #include_set_format_modules, #initialize, #method_missing, #page, #params, #pass_method_to_template_object, #respond_to_missing?, #session, #tagged, #template

Methods included from Nest::ClassMethods

#max_depth

Methods included from Registration

#class_from_name, #extract_class_vars, #extract_view_tags, #format_ancestry, #format_class_name, #format_sym, #new, #register, #tagged

Methods included from Error

#debug_error, #error_cardname, #rendering_error, #rescue_view

Methods included from Content

#add_class, #format_date, #get_content_object, #id_counter, #output, #process_content, #unique_id

Methods included from Names

#add_name_context, #context_names_from_params, #context_names_minus_irrelevants, #initialize_context_names, #showname, #with_name_context

Methods included from Render

#canonicalize_view, #configured_visibility, #current_view, #default_render_args, #hidden_view?, #nest_arg_visibility, #optional_render_args, #parse_view_visibility, #render, #render_api, #show_view?, #view_method

Methods included from Permission

#approved_view, #ok?, #ok_view, #permitted_view, #view_for_unknown

Methods included from Nest

#field_nest, #nest, #nest_card, #nest_defaults, #process_nest

Methods included from Nest::View

#nest_render, #with_nest_mode

Methods included from Nest::Subformat

#field_subformat, #subformat

Methods included from Nest::Main

#wrap_main

Methods included from Nest::Fetch

#fetch_nested_card

Methods included from Env::Location

#card_path, #card_url, #page_path

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

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



51
52
53
# File 'mod/core/format/html_format.rb', line 51

def default_item_view
  :closed
end

#focal?Boolean

meaning the current card is the requested card

Returns:

  • (Boolean)


69
70
71
72
73
74
75
# File 'mod/core/format/html_format.rb', line 69

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

#get_layout_contentObject

helper methods for layout view



16
17
18
19
20
21
22
23
24
# File 'mod/core/format/html_format.rb', line 16

def get_layout_content
  Auth.as_bot do
    if (requested_layout = params[:layout])
      layout_from_card_or_code requested_layout
    else
      layout_from_rule
    end
  end
end

#get_nest_defaults(nested_card) ⇒ Object



47
48
49
# File 'mod/core/format/html_format.rb', line 47

def get_nest_defaults nested_card
  { view: (nested_card.rule(:default_html_view) || :titled) }
end

#html_escape_except_quotes(s) ⇒ Object



55
56
57
58
59
# File 'mod/core/format/html_format.rb', line 55

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



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

def layout_from_card_or_code name
  layout_card = Card.fetch name.to_s, skip_virtual: true,
                                      skip_modules: true
  if layout_card && layout_card.ok?(:read)
    layout_card.content
  elsif (hardcoded_layout = LAYOUTS[name])
    hardcoded_layout
  else
    "<h1>Unknown layout: #{name}</h1>"\
    "Built-in Layouts: #{LAYOUTS.keys.join(', ')}"
  end
end

#layout_from_ruleObject



26
27
28
29
30
31
32
# File 'mod/core/format/html_format.rb', line 26

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

#main?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'mod/core/format/html_format.rb', line 61

def main?
  if show_layout?
    @depth == 1 && @mainline # assumes layout includes {{_main}}
  else
    @depth.zero? && params[:is_main]
  end
end