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
-
#content_nest(opts = {}) ⇒ Object
nested by another card's content (as opposed to a direct API nest).
-
#content_view?(view) ⇒ Boolean
-
#default_nest_view ⇒ Object
-
#field_nest(field, opts = {}) ⇒ Object
Main difference compared to #nest is that you can use codename symbols to get nested fields.
-
#implicit_nest_view ⇒ Object
-
#interpret_nest_options(nested_card, options) ⇒ Object
-
#nest(cardish, options = {}, override = true, &block) ⇒ Object
-
#nest_path(name, nest_opts = {}) ⇒ Object
create a path for a nest with respect ot the nest options.
-
#nest_recursion_risk?(view) ⇒ Boolean
-
#nest_render(nested_card, view, options, override) ⇒ Object
-
#nest_subformat(nested_card, opts, view) ⇒ Object
-
#reuse_format?(nest_name, view) ⇒ Boolean
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_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)
18
19
20
21
22
23
|
# File 'lib/card/format/nest.rb', line 18
def content_nest opts={}
return opts[:comment] if opts.key? :comment nest_name = opts[:nest_name]
return main_nest(opts) if main_nest?(nest_name)
nest nest_name, opts
end
|
#content_view?(view) ⇒ Boolean
76
77
78
79
80
81
|
# File 'lib/card/format/nest.rb', line 76
def content_view? view
[
:core, :content, :titled, :open, :closed, :open_content
].member? view.to_sym
end
|
#default_nest_view ⇒ Object
48
49
50
|
# File 'lib/card/format/nest.rb', line 48
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
89
90
91
92
|
# File 'lib/card/format/nest.rb', line 89
def field_nest field, opts={}
field = card.name.field(field) unless field.is_a? Card
nest field, opts
end
|
#implicit_nest_view ⇒ Object
43
44
45
46
|
# File 'lib/card/format/nest.rb', line 43
def implicit_nest_view
view = voo_items_view || default_nest_view
Card::View.canonicalize view
end
|
#interpret_nest_options(nested_card, options) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/card/format/nest.rb', line 32
def interpret_nest_options nested_card, options
options[:nest_name] ||= nested_card.name
view = options[:view] || implicit_nest_view
view = Card::View.canonicalize view
options[:home_view] ||= [:closed, :edit].member?(view) ? :open : view
[view, options]
end
|
#nest(cardish, options = {}, override = true, &block) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/card/format/nest.rb', line 9
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
nest_render nested_card, view, options, override, &block
end
|
#nest_path(name, nest_opts = {}) ⇒ Object
create a path for a nest with respect ot the nest options
26
27
28
29
30
|
# File 'lib/card/format/nest.rb', line 26
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
72
73
74
|
# File 'lib/card/format/nest.rb', line 72
def nest_recursion_risk? view
content_view?(view) && voo.structure
end
|
#nest_render(nested_card, view, options, override) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/card/format/nest.rb', line 52
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
|
59
60
61
62
63
64
|
# File 'lib/card/format/nest.rb', line 59
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
|
66
67
68
69
70
|
# File 'lib/card/format/nest.rb', line 66
def reuse_format? nest_name, view
nest_name =~ /^_(self)?$/ &&
card.context_card == card &&
!nest_recursion_risk?(view)
end
|