module Card::Format::Nesting::Mode
Nest
modes are states that can alter a nest’s view
Public Instance Methods
configured_view_in_compact_mode(view)
click to toggle source
the view configured in view definition for use when nested in compact mode @param view [Symbol] @return [Symbol] viewname
# 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)
click to toggle source
@param view [Symbol] @return [True/False]
# 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)
click to toggle source
view to be rendered in current mode @param view [Symbol] @return [Symbol ] viewname
# 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()
click to toggle source
current nest mode @return [Symbol] :normal, :compact, :edit, or :template
# 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)
click to toggle source
the view that should be used when nested in compact mode @param view [Symbol] @return [Symbol] viewname
# 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)
click to toggle source
Returns the view that the card should use when nested in edit mode @param view [Symbol] @return [Symbol] viewname
# 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) { || ... }
click to toggle source
# 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) { || ... }
click to toggle source
run block with new_mode as nest_mode
, then return to prior mode @param new_mode [Symbol] :normal, :compact, :edit, or :template @return block result
# 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