Add responder for svg badges.

This commit is contained in:
Mathias Meyer 2014-03-19 14:31:38 +01:00
parent 725125c66c
commit e85d19d33d
4 changed files with 32 additions and 3 deletions

View File

@ -3,7 +3,7 @@ require 'travis/api/app'
class Travis::Api::App
class Middleware
class Rewrite < Middleware
FORMAT = %r(\.(json|xml|png|txt|atom)$)
FORMAT = %r(\.(json|xml|png|txt|atom|svg)$)
V1_REPO_URL = %r(^(/[^/]+/[^/]+(?:/builds(?:/[\d]+)?|/cc)?)$)
helpers :accept
@ -13,7 +13,7 @@ class Travis::Api::App
before do
extract_format
rewrite_v1_repo_segment if v1? || xml?
rewrite_v1_named_repo_image_path if png?
rewrite_v1_named_repo_image_path if png? || svg?
end
after do
@ -52,6 +52,10 @@ class Travis::Api::App
env['travis.format'] == 'png'
end
def svg?
env['travis.format'] == 'svg'
end
def xml?
env['travis.format'] == 'xml'
end

View File

@ -5,6 +5,7 @@ class Travis::Api::App
autoload :Atom, 'travis/api/app/responders/atom'
autoload :Base, 'travis/api/app/responders/base'
autoload :Image, 'travis/api/app/responders/image'
autoload :Badge, 'travis/api/app/responders/badge'
autoload :Json, 'travis/api/app/responders/json'
autoload :Plain, 'travis/api/app/responders/plain'
autoload :Service, 'travis/api/app/responders/service'

View File

@ -0,0 +1,20 @@
module Travis::Api::App::Responders
class Badge < Image
def format
'svg'
end
def apply
set_headers
send_file(filename, type: :svg, last_modified: last_modified)
end
def content_type
"image/svg"
end
def filename
"#{root}/public/images/result/#{result}.svg"
end
end
end

View File

@ -4,10 +4,14 @@ module Travis::Api::App::Responders
'png'
end
def apply
def set_headers
headers['Pragma'] = "no-cache"
headers['Expires'] = Time.now.utc.httpdate
headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}")
end
def apply
set_headers
send_file(filename, type: :png, last_modified: last_modified)
end