module Card::Format::Nesting
the core of the nesting api
Public Instance Methods
default_nest_view()
click to toggle source
view used if unspecified in nest. frequently overridden in other formats
# File lib/card/format/nesting.rb, line 42 def default_nest_view :name end
field_nest(field, opts={})
click to toggle source
Shortcut for nesting field cards @example
home = Card['home'].format home.nest :self # => nest for '*self' home.field_nest :self # => nest for 'Home+*self'
# 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] ||= field.cardname.vary("capitalized") nest fullname, opts end
implicit_nest_view()
click to toggle source
# File lib/card/format/nesting.rb, line 46 def implicit_nest_view voo_items_view || default_nest_view end
nest(cardish, view_opts={}) { |rendered, view| ... }
click to toggle source
@param cardish card mark @param view_opts [Hash] {Card::View::Options view options}, passed on to render. @param format_opts [Hash] opts will be passed on to subformat
# 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={})
click to toggle source
create a path for a nest with respect to the nest options
# 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
Private Instance Methods
count_chars() { || ... }
click to toggle source
# File lib/card/format/nesting.rb, line 56 def count_chars result = yield return result unless nest_mode == :compact && result @char_count ||= 0 @char_count += result.length result end
max_char_count()
click to toggle source
# File lib/card/format/nesting.rb, line 69 def max_char_count Card.config.max_char_count end
max_depth()
click to toggle source
# File lib/card/format/nesting.rb, line 65 def max_depth Card.config.max_depth end
nest_invisible?()
click to toggle source
# File lib/card/format/nesting.rb, line 52 def nest_invisible? nest_mode == :compact && @char_count && (@char_count > max_char_count) end