Sha256: 251879d6ee60809828258fc10cfe36f1532dea518c7c7c7e5d22756c2ee75fd1

Contents?: true

Size: 725 Bytes

Versions: 69

Compression:

Stored size: 725 Bytes

Contents

# encoding: utf-8
module Sinatra
  module ReportHandler
    extend Hexacta

    def enable_reports
      p "Enabling reports..."
      before '/reports/*' do
        error(403) if authenticated(User).permissions.empty?
      end

      get '/reports' do
        slim :reports
      end

      get '/reports/:report_name' do |report_name|
        date = Date.parse(params[:date]) unless params[:date].nil?
        date ||= Date.today
        headers "Content-Disposition" => "attachment;filename=#{report_name}.#{date}.xls",
          "Content-Type" => "application/octet-stream"
          slim "reports/#{report_name}".to_sym, locals: { :date => date }, :layout => false
      end
    end

  end

  register ReportHandler
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
sinatra-hexacta-1.2.10 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.9 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.8 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.7 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.6 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.5 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.4 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.3 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.2 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.1 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.2.0 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.5 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.4 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.3 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.2 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.1 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.1.0 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.0.3 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.0.2 lib/sinatra/handlers/reports.rb
sinatra-hexacta-1.0.1 lib/sinatra/handlers/reports.rb