Module: Card::Format::Nesting::Mode

Included in:
Card::Format::Nesting
Defined in:
lib/card/format/nesting/mode.rb

Overview

Nest modes are states that can alter a nest's view

Instance Method Summary collapse

Instance Method Details

#configured_view_in_compact_mode(view) ⇒ Symbol

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

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



79
80
81
82
83
84
# File 'lib/card/format/nesting/mode.rb', line 79

def configured_view_in_compact_mode view
  compact_config = view_setting(:compact, view)
  return view if compact_config == true

  compact_config
end

#hide_view_in_edit_mode?(view) ⇒ True/False

Parameters:

  • view (Symbol)

Returns:

  • (True/False)


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

def hide_view_in_edit_mode? view
  view_setting(: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



43
44
45
46
47
48
49
50
51
# File 'lib/card/format/nesting/mode.rb', line 43

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_nest
  when :compact   then view_in_compact_mode(view)
  else view
  end
end

#nest_modeSymbol

current nest mode

Returns:

  • (Symbol)

    :normal, :compact, :edit, or :template



17
18
19
# File 'lib/card/format/nesting/mode.rb', line 17

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

#view_in_compact_mode(view) ⇒ Symbol

the view that should be used when nested in compact mode

Parameters:

  • view (Symbol)

Returns:

  • (Symbol)

    viewname



71
72
73
74
# File 'lib/card/format/nesting/mode.rb', line 71

def view_in_compact_mode view
  configured_view_in_compact_mode(view) ||
    (card.known? ? :one_line_content : :compact_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



56
57
58
# File 'lib/card/format/nesting/mode.rb', line 56

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

#with_altered_nest_mode(new_mode) ⇒ Object



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

def with_altered_nest_mode new_mode
  old_mode = nest_mode
  @nest_mode = new_mode
  yield
ensure
  @nest_mode = old_mode
end

#with_nest_mode(new_mode, &block) ⇒ Object

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

Parameters:

  • new_mode (Symbol)

    :normal, :compact, :edit, or :template

Returns:

  • block result



24
25
26
27
28
29
30
# File 'lib/card/format/nesting/mode.rb', line 24

def with_nest_mode new_mode, &block
  if new_mode == @nest_mode
    yield
  else
    with_altered_nest_mode new_mode, &block
  end
end