Class: Tablette::Column

Inherits:
Element show all
Defined in:
lib/tablette/columns.rb

Direct Known Subclasses

BodyColumn, FooterColumn, HeaderColumn

Instance Attribute Summary collapse

Attributes inherited from Element

#helper, #renderer

Instance Method Summary collapse

Methods inherited from Element

#element_to_html, #method_missing, #respond_to_missing?, #to_html

Constructor Details

#initialize(*args, &block) ⇒ Column

Returns a new instance of Column.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tablette/columns.rb', line 5

def initialize(*args, &block)
  self.value = block
  self.key   = args.first if args.first.is_a?(String) or args.first.is_a?(Symbol)

  config.builtin_html_options = ->(member, index = nil) do
    classes = []

    if self.key.present?
      classes << self.key.to_s
    end

    if index.kind_of? Numeric
      if index.odd?
        classes << "odd"
      else
        classes << "even"
      end
    end

    if classes.any?
      { :class => classes.join(" ") }
    else
      {}
    end
  end

  # Bypass block evaling: in this case it's not a config but a value formatter
  super(*args, &nil)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tablette::Element

Instance Attribute Details

#keyObject

Returns the value of attribute key.



43
44
45
# File 'lib/tablette/columns.rb', line 43

def key
  @key
end

#valueObject

Returns the value of attribute value.



43
44
45
# File 'lib/tablette/columns.rb', line 43

def value
  @value
end

Instance Method Details

#colspan(args) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/tablette/columns.rb', line 35

def colspan(args)
  override_html_options, html_options =
    get_options([:override_html_options, :html_options], *args)

  options = override_html_options.merge html_options
  options[:colspan]
end