Class: Toolsmith::Views::DefinitionList

Inherits:
Base
  • Object
show all
Defined in:
lib/toolsmith/views/definition_list.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ horizontal: true }

Instance Attribute Summary collapse

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

#content_tag

Constructor Details

#initialize(context, options = {}, &block) ⇒ DefinitionList

Returns a new instance of DefinitionList.



8
9
10
11
12
# File 'lib/toolsmith/views/definition_list.rb', line 8

def initialize(context, options={}, &block)
  @content_block = block if block_given?
  @options = DEFAULT_OPTIONS.merge(options)
  super(context, &nil)
end

Instance Attribute Details

#content_blockObject (readonly)

Returns the value of attribute content_block.



6
7
8
# File 'lib/toolsmith/views/definition_list.rb', line 6

def content_block
  @content_block
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/toolsmith/views/definition_list.rb', line 6

def options
  @options
end

Instance Method Details

#define(term, description) ⇒ Object



14
15
16
17
# File 'lib/toolsmith/views/definition_list.rb', line 14

def define(term, description)
  description = description.blank? ? " ".html_safe : description
  (:dt, term) + (:dd, description)
end

#to_sObject



19
20
21
22
# File 'lib/toolsmith/views/definition_list.rb', line 19

def to_s
  content = context.capture(self, &content_block)
   :dl, content, dl_options
end