Sha256: 46d0074f8ce5d8d8a899f7a0bcf9fd59865eee3b37d4a16797c1b61b65364015

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

require 'deas/deas_runner'

module Deas

  class SinatraRunner < DeasRunner

    def initialize(handler_class, args = nil)
      @sinatra_call = (args || {})[:sinatra_call]
      super(handler_class, args)
    end

    # Helpers

    def halt(*args)
      @sinatra_call.halt(*args)
    end

    def redirect(*args)
      @sinatra_call.redirect(*args)
    end

    def content_type(*args)
      return @sinatra_call.content_type if args.empty?

      opts, value = [
        args.last.kind_of?(::Hash) ? args.pop : {},
        args.first
      ]
      @sinatra_call.content_type(value, {
        :charset => @sinatra_call.settings.deas_default_charset
      }.merge(opts || {}))
    end

    def status(*args)
      @sinatra_call.status(*args)
    end

    def headers(*args)
      @sinatra_call.headers(*args)
    end

    def source_render(source, template_name, locals = nil)
      self.content_type(get_content_type(template_name)) if self.content_type.nil?
      super
    end

    def send_file(*args, &block)
      @sinatra_call.send_file(*args, &block)
    end

    private

    def get_content_type(template_name)
      File.extname(template_name)[1..-1] || 'html'
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deas-0.33.0 lib/deas/sinatra_runner.rb
deas-0.32.0 lib/deas/sinatra_runner.rb
deas-0.31.0 lib/deas/sinatra_runner.rb
deas-0.30.0 lib/deas/sinatra_runner.rb