lib/tabulatr/renderer/column.rb in tabulatr2-0.9.7 vs lib/tabulatr/renderer/column.rb in tabulatr2-0.9.10

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH +# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, @@ -49,11 +49,10 @@ header_style: {}, sort_sql: nil, filter_sql: nil, output: nil, &block) - b = block_given? ? block : nil self.new( name: name, table_name: table_name, header: header, classes: classes, @@ -66,11 +65,11 @@ filter: filter, sortable: sortable, format: format, map: map, klass: klass, - block: b, + block: block, cell_style: cell_style, header_style: header_style, sort_sql: sort_sql, filter_sql: filter_sql, output: output @@ -141,16 +140,11 @@ default_style_attributes || {} end def value_for(record, view) - if block - r = view.instance_exec(record, &block) - r = r.join(' ').html_safe if r.is_a?(Array) - return r - end - val = principal_value(record) or return '' + val = principal_value(record, view) if format.present? && val.respond_to?(:to_ary) val.map do |v| case format when Symbol then view.send(format, v) when String then format % v @@ -168,11 +162,19 @@ else val end end - def principal_value(record) - record.send name + def principal_value(record, view) + if output + view.instance_exec(record, &output) + elsif block + view.instance_exec(record, &block) + elsif name + record.send name + else + nil + end end def determine_appropriate_filter! case self.klass.columns_hash[self.name.to_s].try(:type) when :integer, :float, :decimal