Sha256: 2493417c0d1032b98f7fe325cd491afebef2e90383a9e51f7fe1de1f5025e5c4
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
module EasyTable module Components class Column include Base delegate :tag, :capture, :content_tag, :to => :@template def initialize(node, title, label, opts, template, block) @node, @title, @label, @template, @block, @opts = node, title, label, template, block, opts header_opts = @opts.select { |k, _v| k =~ /^header_.*/ } header_opts.each { |k, _v| @opts.delete(k) } @header_opts = header_opts.inject({}) do |h, e| k, v = *e h[k[7..-1]] = v h end end def head concat content_tag(:th, label, @header_opts) end def td(record) if @block.present? html = capture { @block.call(record, self) } else html = record.send(@title).to_s end concat(content_tag(:td, html, html_opts(record))) end private def label @label || translate(@title) end def concat(tag) @template.safe_concat(tag) unless tag.nil? "" end def html_opts(record) @opts.inject({}) do |h, e| k, v = *e h[k] = case v when Proc v.call(record) else v end h end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
easy_table-0.0.8 | lib/easy_table/components/column.rb |
easy_table-0.0.7 | lib/easy_table/components/column.rb |