lib/tabulatr/renderer/column.rb in tabulatr2-0.8.2 vs lib/tabulatr/renderer/column.rb in tabulatr2-0.8.3

- old
+ new

@@ -24,52 +24,56 @@ class Tabulatr::Renderer::Column include ActiveModel::Model attr_accessor *%i{name header width align valign wrap type th_html filter_html filter checkbox_value checkbox_label filter_width range_filter_symbol - sortable table_name block klass format map} + sortable table_name block klass format map classes cell_style header_style} def self.from( name: nil, table_name: nil, - header: false, + header: nil, + classes: nil, width: false, align: false, valign: false, - wrap: true, - type: :string, + wrap: nil, th_html: false, filter_html: false, filter: true, checkbox_value: '1', checkbox_label: '', sortable: true, format: nil, map: true, klass: nil, + cell_style: {}, + header_style: {}, &block) b = block_given? ? block : nil self.new( name: name, table_name: table_name, header: header, + classes: classes, width: width, align: align, valign: valign, wrap: wrap, - type: type, th_html: th_html, filter_html: filter_html, filter: filter, checkbox_value: checkbox_value, checkbox_label: checkbox_label, sortable: sortable, format: format, map: map, klass: klass, - block: b - ) + block: b, + cell_style: cell_style, + header_style: header_style + ).apply_styles! end def klassname() @_klassname ||= @klass.name.underscore end def human_name() header || klass.human_attribute_name(name) end def sort_param() "#{klassname}_sort" end @@ -78,9 +82,27 @@ def column?() true end def association?() false end def checkbox?() false end def action?() false end + + def apply_styles! + # raise cell_style.inspect + self.cell_style = style_options.merge(self.cell_style).map{|e| e.join(':')}.join(';') + self.header_style = style_options.merge(self.header_style).map{|e| e.join(':')}.join(';') + self + end + + def style_options + default_style_attributes = { + :'text-align' => align, + width: width, + :'vertical-align' => valign, + :'white-space' => wrap + }.select{|k,v| v} + + default_style_attributes || {} + end def value_for(record, view) if block return view.instance_exec(record, &block) end