Class: View::DefinitionList

Inherits:
Formatter show all
Defined in:
lib/view/formatters/definition_list.rb

Overview

Creates a simple definition list for an object. This works well with ActiveRecord objects. Without a block it will render all fields. You can specify the fields using the `fields` option.

You can use a block, to further format the way the definition items are formatted.

Examples:

Without a block


= view @post, :as => :definition_list, :fields => [ :title, :author ]

With a block


= view @post, :as => :definition_list do |dl|
  = dl.view :title
  = dl.view :author
  = dl.view :published_at, :as => :date

Defined Under Namespace

Classes: Attribute

Instance Attribute Summary

Attributes inherited from Formatter

#block, #template, #value

Instance Method Summary collapse

Methods inherited from Formatter

#all_options, as, inherited, #options, skip_blank_formatter, #to_s, type

Instance Method Details

#view(attribute, options = {}) {|formatter| ... } ⇒ Object

This will add the dt and dd tags.

Yields:

  • (formatter)

    The block will be used for formatting the attribute's value



33
34
35
36
# File 'lib/view/formatters/definition_list.rb', line 33

def view(attribute, options = {}, &block)
  tag = Attribute.new(value, attribute, block, template, options)
  tag.dt + tag.dd
end