Module: Card::Format::Nesting

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

Overview

the core of the nesting api

Defined Under Namespace

Modules: Main, Mode, Subformat

Instance Method Summary collapse

Methods included from Mode

#configured_view_in_compact_mode, #hide_view_in_edit_mode?, #modal_nest_view, #nest_mode, #view_in_compact_mode, #view_in_edit_mode, #with_altered_nest_mode, #with_nest_mode

Methods included from Subformat

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

Methods included from Main

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

Instance Method Details

#default_nest_viewObject

view used if unspecified in nest. frequently overridden in other formats



42
43
44
# File 'lib/card/format/nesting.rb', line 42

def default_nest_view
  :name
end

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

Shortcut for nesting field cards

Examples:

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


27
28
29
30
31
# File 'lib/card/format/nesting.rb', line 27

def field_nest field, opts={}
  fullname = card.name.field(field) unless field.is_a? Card
  opts[:title] ||= Card.fetch_name(field).vary("capitalized")
  nest fullname, opts
end

#implicit_nest_viewObject



46
47
48
# File 'lib/card/format/nesting.rb', line 46

def implicit_nest_view
  voo_items_view || default_nest_view
end

#nest(cardish, view_opts = {}, format_opts = {}) ⇒ Object

Parameters:

  • cardish

    card mark

  • view_opts (Hash) (defaults to: {})

    view options, passed on to render.

  • format_opts (Hash) (defaults to: {})

    opts will be passed on to subformat



12
13
14
15
16
17
18
19
20
# File 'lib/card/format/nesting.rb', line 12

def nest cardish, view_opts={}, format_opts={}
  return "" if nest_invisible?

  nest = Card::Format::Nest.new self, cardish, view_opts, format_opts
  nest.prepare do |subformat, view|
    rendered = count_chars { subformat.render view, view_opts }
    block_given? ? yield(rendered, view) : rendered
  end
end

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

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



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

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