lib/trestle/table/column.rb in trestle-0.8.6 vs lib/trestle/table/column.rb in trestle-0.8.7
- old
+ new
@@ -43,10 +43,14 @@
def initialize(column, template)
@column, @template = column, template
end
+ def render(instance)
+ @template.content_tag(:td, content(instance), class: classes, data: data)
+ end
+
def header
return if options.has_key?(:header) && options[:header].in?([nil, false])
header = I18n.t("admin.table.headers.#{@column.field}", default: @column.header)
header = @template.sort_link(header, @column.sort_field, @column.sort_options) if @column.sortable?
@@ -85,13 +89,20 @@
# the _hamlout local variable needs to be defined in the scope of the block,
# so that the Haml version of the capture method is used. Because we
# evaluate the block using instance_exec, we need to set this up manually.
-> {
_hamlout = eval('_hamlout', @column.block.binding)
- @template.capture { @template.instance_exec(instance, &@column.block).to_s }
+ value = nil
+ buffer = @template.capture { value = @template.instance_exec(instance, &@column.block) }
+ value.is_a?(String) ? buffer : value
}.call
else
- @template.capture { @template.instance_exec(instance, &@column.block).to_s }
+ # Capture both the immediate value and captured output of the block.
+ # If the result of the block is a string, then use the contents of the buffer.
+ # Otherwise return the result of the block as a raw value (for auto-formatting).
+ value = nil
+ buffer = @template.capture { value = @template.instance_exec(instance, &@column.block) }
+ value.is_a?(String) ? buffer : value
end
else
instance.send(@column.field)
end
end