Sha256: a3ed83711e1ea689824291590a27e9bb4e2aa28039b029e564eddf686df15cf6
Contents?: true
Size: 929 Bytes
Versions: 2
Compression:
Stored size: 929 Bytes
Contents
require 'csv_shaper_template' # CsvShaperHandler # Template handler for Rails class CsvShaperHandler cattr_accessor :default_format self.default_format = Mime[:csv] # Expected `call` class method # Set response headers with filename # Primarily calls CsvShaperTemplate.encode, passing through the context (self) def self.call(template, source = nil) %{ if ( controller.present? ) && !( defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base) ) @filename ||= "\#{controller.action_name}.csv" controller.response.headers["Content-Type"] ||= 'text/csv' controller.response.headers['Content-Disposition'] = "attachment; filename=\\\"\#{@filename}\\\"" end CsvShaperTemplate.encode(self) do |csv| #{source || template.source} end } end end ActionView::Template.register_template_handler :shaper, CsvShaperHandler
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
csv_shaper-1.3.2 | lib/csv_shaper_handler.rb |
csv_shaper-1.3.1 | lib/csv_shaper_handler.rb |