Sha256: 09a116b6305d8a89a7a9361119d0ecfe15d6847119dc71a43bc4f9fe1c3d244f

Contents?: true

Size: 975 Bytes

Versions: 3

Compression:

Stored size: 975 Bytes

Contents

require "useful_renderers/version"
require 'useful_renderers/csv_renderable'
require 'useful_renderers/zip_renderable'
require 'action_controller/metal/renderers'

module UsefulRenderers
  class RenderUsefulRailtie < ::Rails::Railtie
    config.after_initialize do

      ActionController.add_renderer :csv do |csv, options|
        filename = options[:filename] || options[:template]
        csv.extend UsefulRenderers::CsvRenderable
        data = csv.respond_to?(:to_csv) ? csv.to_csv(options) : csv
        send_data data, type: Mime[:csv], disposition: "attachment; filename=#{filename}.csv"
      end

      ActionController.add_renderer :zip do |zip, options|
        filename = options[:filename] || options[:template]
        zip.extend UsefulRenderers::ZipRenderable
        data = zip.respond_to?(:to_zip) ? zip.to_zip(options) : zip
        send_data data, type: 'application/zip', disposition: "attachment; filename=#{filename}.zip"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
useful_renderers-0.3.0 lib/useful_renderers.rb
useful_renderers-0.2.0 lib/useful_renderers.rb
useful_renderers-0.1.0 lib/useful_renderers.rb