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
-
#configured_view_in_compact_mode(view) ⇒ Symbol
the view configured in view definition for use when nested in compact mode.
- #hide_view_in_edit_mode?(view) ⇒ True/False
-
#modal_nest_view(view) ⇒ Symbol
view to be rendered in current mode.
-
#nest_mode ⇒ Symbol
current nest mode.
-
#view_in_compact_mode(view) ⇒ Symbol
the view that should be used when nested in compact mode.
-
#view_in_edit_mode(view) ⇒ Symbol
Returns the view that the card should use when nested in edit mode.
- #with_altered_nest_mode(new_mode) ⇒ Object
-
#with_nest_mode(new_mode, &block) ⇒ Object
run block with new_mode as nest_mode, then return to prior mode.
Instance Method Details
#configured_view_in_compact_mode(view) ⇒ Symbol
the view configured in view definition for use when nested in compact mode
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
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 |
#modal_nest_view(view) ⇒ Symbol
view to be rendered in current mode
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_mode ⇒ Symbol
current nest mode
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
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
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
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 |