lib/active_admin/csv_builder.rb in activeadmin-1.0.0.pre2 vs lib/active_admin/csv_builder.rb in activeadmin-1.0.0.pre3

- old
+ new

@@ -37,28 +37,31 @@ def column(name, options={}, &block) @columns << Column.new(name, @resource, column_transitive_options.merge(options), block) end - def build(controller, receiver) - @collection = controller.send(:find_collection, except: :pagination) - options = ActiveAdmin.application.csv_options.merge self.options - columns = exec_columns controller.view_context + def build(controller, csv) + @collection = controller.send :find_collection, except: :pagination + columns = exec_columns controller.view_context + options = ActiveAdmin.application.csv_options.merge self.options + bom = options.delete :byte_order_mark + column_names = options.delete(:column_names) { true } + csv_options = options.except :encoding_options - if byte_order_mark = options.delete(:byte_order_mark) - receiver << byte_order_mark - end + csv << bom if bom - if options.delete(:column_names) { true } - receiver << CSV.generate_line(columns.map{ |c| encode c.name, options }, options) + if column_names + csv << CSV.generate_line(columns.map{ |c| encode c.name, options }, csv_options) end - (1..paginated_collection.total_pages).each do |page_no| - paginated_collection(page_no).each do |resource| - resource = controller.send :apply_decorator, resource - receiver << CSV.generate_line(build_row(resource, columns, options), options) + (1..paginated_collection.total_pages).each do |page| + paginated_collection(page).each do |resource| + resource = controller.send :apply_decorator, resource + csv << CSV.generate_line(build_row(resource, columns, options), csv_options) end end + + csv end def exec_columns(view_context = nil) @view_context = view_context @columns = [] # we want to re-render these every instance