Module: Card::Format::Nest

Includes:
Fetch, Main, Mode, Subformat
Included in:
Card::Format
Defined in:
lib/card/format/nest.rb,
lib/card/format/nest/main.rb,
lib/card/format/nest/mode.rb,
lib/card/format/nest/fetch.rb,
lib/card/format/nest/subformat.rb

Defined Under Namespace

Modules: Fetch, Main, Mode, Subformat

Instance Method Summary collapse

Methods included from Mode

#configured_view_in_closed_mode, #hide_view_in_edit_mode?, #modal_nest_view, #nest_mode, #view_in_closed_mode, #view_in_edit_mode, #with_altered_nest_mode, #with_nest_mode

Methods included from Subformat

#depth, #field_subformat, #focal?, #main?, #root, #subformat

Methods included from Main

#already_mained?, #main!, #main_nest, #main_nest?, #main_nest_options, #wrap_main

Methods included from Fetch

#fetch_nested_card

Instance Method Details

#content_nest(opts = {}) ⇒ Object

nested by another card's content (as opposed to a direct API nest)



28
29
30
31
32
33
# File 'lib/card/format/nest.rb', line 28

def content_nest opts={}
  return opts[:comment] if opts.key? :comment # commented nest
  nest_name = opts[:nest_name]
  return main_nest(opts) if main_nest?(nest_name)
  nest nest_name, opts
end

#content_view?(view) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
# File 'lib/card/format/nest.rb', line 86

def content_view? view
  # TODO: this should be specified in view definition
  [
    :core, :content, :titled, :open, :closed, :open_content
  ].member? view.to_sym
end

#default_nest_viewObject



58
59
60
# File 'lib/card/format/nest.rb', line 58

def default_nest_view
  :name
end

#field_nest(field, opts = {}) ⇒ Object

Main difference compared to #nest is that you can use codename symbols to get nested fields

Examples:

home = Card['home'].format
home.nest :self         # => nest for '*self'
home.field_nest :self   # => nest for 'Home+*self'


99
100
101
102
# File 'lib/card/format/nest.rb', line 99

def field_nest field, opts={}
  field = card.name.field(field) unless field.is_a? Card
  nest field, opts
end

#implicit_nest_viewObject



53
54
55
56
# File 'lib/card/format/nest.rb', line 53

def implicit_nest_view
  view = voo_items_view || default_nest_view
  Card::View.canonicalize view
end

#interpret_nest_options(nested_card, options) ⇒ Object



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

def interpret_nest_options nested_card, options
  options[:nest_name] ||= nested_card.name
  view = options[:view] || implicit_nest_view
  view = Card::View.canonicalize view

  # FIXME: should handle in closed / edit view definitions
  options[:home_view] ||= [:closed, :edit].member?(view) ? :open : view

  [view, options]
end

#nest(cardish, options = {}, override = true, &block) ⇒ Object

Parameters:

  • cardish

    card mark

  • options (Hash) (defaults to: {})
  • override (defaults to: true)

    ??

Options Hash (options):

  • view (Symbol)
  • :hide (Symbol, Array<Symbol>)

    hide optional subviews

  • :show (Symbol, Array<Symbol>)

    show optional subviews

  • :title (String)


16
17
18
19
20
21
22
23
24
# File 'lib/card/format/nest.rb', line 16

def nest cardish, options={}, override=true, &block
  return "" if nest_invisible?
  nested_card = fetch_nested_card cardish, options
  view, options = interpret_nest_options nested_card, options

  with_nest_mode options.delete(:mode) do
    nest_render nested_card, view, options, override, &block
  end
end

#nest_path(name, nest_opts = {}) ⇒ Object

create a path for a nest with respect ot the nest options



36
37
38
39
40
# File 'lib/card/format/nest.rb', line 36

def nest_path name, nest_opts={}
  path_opts = { slot: nest_opts.clone }
  path_opts[:view] = path_opts[:slot].delete :view
  page_path name, path_opts
end

#nest_recursion_risk?(view) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/card/format/nest.rb', line 82

def nest_recursion_risk? view
  content_view?(view) && voo.structure
end

#nest_render(nested_card, view, options, override) ⇒ Object



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

def nest_render nested_card, view, options, override
  subformat = nest_subformat nested_card, options, view
  view = subformat.modal_nest_view view if override
  rendered = count_chars { subformat.render view, options }
  block_given? ? yield(rendered, view) : rendered
end

#nest_subformat(nested_card, opts, view) ⇒ Object



69
70
71
72
73
74
# File 'lib/card/format/nest.rb', line 69

def nest_subformat nested_card, opts, view
  return self if reuse_format? opts[:nest_name], view
  sub = subformat nested_card
  sub.main! if opts[:main]
  sub
end

#reuse_format?(nest_name, view) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'lib/card/format/nest.rb', line 76

def reuse_format? nest_name, view
  nest_name =~ /^_(self)?$/ &&
    card.context_card == card &&
    !nest_recursion_risk?(view)
end