Class: Toolsmith::Views::DefinitionListFor
- Defined in:
- lib/toolsmith/views/definition_list_for.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ horizontal: true }
Instance Attribute Summary collapse
-
#content_block ⇒ Object
readonly
Returns the value of attribute content_block.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #define(attribute) ⇒ Object
- #dl_options ⇒ Object
-
#initialize(context, &block) ⇒ DefinitionListFor
constructor
A new instance of DefinitionListFor.
- #to_s ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(context, &block) ⇒ DefinitionListFor
Returns a new instance of DefinitionListFor.
9 10 11 12 13 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 9 def initialize(context, &block) @content_block = block if block_given? @options = DEFAULT_OPTIONS.dup super(context, &nil) end |
Instance Attribute Details
#content_block ⇒ Object (readonly)
Returns the value of attribute content_block.
5 6 7 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 5 def content_block @content_block end |
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 4 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 4 def @options end |
Class Method Details
.new_with_object(context, object, &block) ⇒ Object
15 16 17 18 19 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 15 def self.new_with_object(context, object, &block) definition_list = new(context, &block) definition_list.object = object definition_list end |
Instance Method Details
#define(attribute) ⇒ Object
21 22 23 24 25 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 21 def define(attribute) human_attribute = attribute.to_s.humanize content_tag(:dt, human_attribute) + content_tag(:dd, object.send(attribute)) end |
#dl_options ⇒ Object
32 33 34 35 36 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 32 def { class: [:horizontal] ? "dl-horizontal" : nil } end |
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/toolsmith/views/definition_list_for.rb', line 27 def to_s content = context.capture(self, &content_block) content_tag :dl, content, end |