Module: Card::Format::Nest::Mode

Included in:
Card::Format::Nest
Defined in:
lib/card/format/nest/mode.rb

Instance Method Summary collapse

Instance Method Details

#configured_view_in_closed_mode(view) ⇒ Symbol

the view configured in view definition for use when nested in closed mode

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



67
68
69
70
71
# File 'lib/card/format/nest/mode.rb', line 67

def configured_view_in_closed_mode view
  closed_config = Card::Format.closed[view]
  return view if closed_config == true || Card::Format.error_code[view]
  closed_config
end

#hide_view_in_edit_mode?(view) ⇒ True/False

Parameters:

  • view (Symbol)

Returns:

  • (True/False)


51
52
53
54
55
# File 'lib/card/format/nest/mode.rb', line 51

def hide_view_in_edit_mode? view
  Card::Format.perms[view] == :none || # view never edited
    card.structure                  || # not yet nesting structures
    card.key.blank?                    # eg {{_self|type}} on new cards
end

view to be rendered in current mode

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



32
33
34
35
36
37
38
39
40
# File 'lib/card/format/nest/mode.rb', line 32

def modal_nest_view view
  # Note: the subformat always has the same nest_mode as its parent format
  case nest_mode
  when :edit     then view_in_edit_mode(view)
  when :template then :template_rule
  when :closed   then view_in_closed_mode(view)
  else view
  end
end

#nest_modeSymbol

current nest mode

Returns:

  • (Symbol)

    :normal, :closed, :edit, or :template



14
15
16
# File 'lib/card/format/nest/mode.rb', line 14

def nest_mode
  @nest_mode ||= parent ? parent.nest_mode : :normal
end

#view_in_closed_mode(view) ⇒ Symbol

the view that should be used when nested in closed mode

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



60
61
62
# File 'lib/card/format/nest/mode.rb', line 60

def view_in_closed_mode view
  configured_view_in_closed_mode(view) || (card.known? ? :closed_content : :closed_missing)
end

#view_in_edit_mode(view) ⇒ Symbol

Returns the view that the card should use when nested in edit mode

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



45
46
47
# File 'lib/card/format/nest/mode.rb', line 45

def view_in_edit_mode view
  hide_view_in_edit_mode?(view) ? :blank : :edit_in_form
end

#with_nest_mode(new_mode) ⇒ Object

run block with new_mode as nest_mode, then return to prior mode

Parameters:

  • new_mode (Symbol)

    :normal, :closed, :edit, or :template

Returns:

  • block result



21
22
23
24
25
26
27
# File 'lib/card/format/nest/mode.rb', line 21

def with_nest_mode new_mode
  old_mode = nest_mode
  @nest_mode = new_mode
  result = yield
  @nest_mode = old_mode
  result
end