Class: TableHelper::Cell

Inherits:
HtmlElement show all
Defined in:
lib/table_helper/cell.rb

Overview

Represents a single cell within a table. This can either be a regular data cell (td) or a header cell (th). By default, all cells will have their name appended to the cell’s class attribute.

Examples

# Data cell
c = Cell.new(:author, 'John Doe')
c.html    # => <td class="author">John Doe</td>

# Header cell
c = Cell.new(:author, 'Author Name')
c.content_type = :header
c.html

# With namespace
c = Cell.new(:author, :namespace => 'post')
c.content_type = :header
c.html    # => <td class="post-author">Author</td>

Constant Summary collapse

@@empty_class =
'ui-state-empty'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HtmlElement

#html

Constructor Details

#initialize(name, content = name.to_s.titleize, html_options = {}) ⇒ Cell

:nodoc



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/table_helper/cell.rb', line 32

def initialize(name, content = name.to_s.titleize, html_options = {}) #:nodoc
  html_options, content = content, name.to_s.titleize if content.is_a?(Hash)
  namespace = html_options.delete(:namespace)
  super(html_options)
  
  @content = content.to_s
  
  if name
    name = "#{namespace}-#{name}" unless namespace.blank?
    self[:class] = "#{self[:class]} #{name}".strip
  end
  self[:class] = "#{self[:class]} #{empty_class}".strip if content.blank?
  
  self.content_type = :data
end

Instance Attribute Details

#contentObject (readonly)

The content to display within the cell



27
28
29
# File 'lib/table_helper/cell.rb', line 27

def content
  @content
end

#content_typeObject

The type of content this cell represents (:data or :header)



30
31
32
# File 'lib/table_helper/cell.rb', line 30

def content_type
  @content_type
end