Sha256: f19b3b763a36b5c3bce062147cf7be3264b6271bc2ca9a59ab3f3bc1c994889a

Contents?: true

Size: 605 Bytes

Versions: 1

Compression:

Stored size: 605 Bytes

Contents

module Sinatra
  module Images
    def self.registered(app)
      # stream images
      app.get %r{[gif|jpg|png|jpeg]$} do
        content_type get_image_type(request.path_info)
        File.open(options.views + request.path_info, 'rb') do |file| 
          file.read
        end 
      end
    end
    
    def get_image_type(image_name)
      if image_name =~ /.gif/
        "image/gif"
      elsif image_name =~ /.jpg/
        "image/jpg"
      elsif image_name =~ /.png/
        "image/png"
      elsif image_name =~ /.jpeg/
        "image/jpeg"
      end
    end
        
  end
  register Images
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mercury-0.9.4 lib/mercury/images.rb