Add responder for svg badges.
This commit is contained in:
parent
725125c66c
commit
e85d19d33d
|
@ -3,7 +3,7 @@ require 'travis/api/app'
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Middleware
|
class Middleware
|
||||||
class Rewrite < 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)?)$)
|
V1_REPO_URL = %r(^(/[^/]+/[^/]+(?:/builds(?:/[\d]+)?|/cc)?)$)
|
||||||
|
|
||||||
helpers :accept
|
helpers :accept
|
||||||
|
@ -13,7 +13,7 @@ class Travis::Api::App
|
||||||
before do
|
before do
|
||||||
extract_format
|
extract_format
|
||||||
rewrite_v1_repo_segment if v1? || xml?
|
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
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
@ -52,6 +52,10 @@ class Travis::Api::App
|
||||||
env['travis.format'] == 'png'
|
env['travis.format'] == 'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def svg?
|
||||||
|
env['travis.format'] == 'svg'
|
||||||
|
end
|
||||||
|
|
||||||
def xml?
|
def xml?
|
||||||
env['travis.format'] == 'xml'
|
env['travis.format'] == 'xml'
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Travis::Api::App
|
||||||
autoload :Atom, 'travis/api/app/responders/atom'
|
autoload :Atom, 'travis/api/app/responders/atom'
|
||||||
autoload :Base, 'travis/api/app/responders/base'
|
autoload :Base, 'travis/api/app/responders/base'
|
||||||
autoload :Image, 'travis/api/app/responders/image'
|
autoload :Image, 'travis/api/app/responders/image'
|
||||||
|
autoload :Badge, 'travis/api/app/responders/badge'
|
||||||
autoload :Json, 'travis/api/app/responders/json'
|
autoload :Json, 'travis/api/app/responders/json'
|
||||||
autoload :Plain, 'travis/api/app/responders/plain'
|
autoload :Plain, 'travis/api/app/responders/plain'
|
||||||
autoload :Service, 'travis/api/app/responders/service'
|
autoload :Service, 'travis/api/app/responders/service'
|
||||||
|
|
20
lib/travis/api/app/responders/badge.rb
Normal file
20
lib/travis/api/app/responders/badge.rb
Normal 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
|
|
@ -4,10 +4,14 @@ module Travis::Api::App::Responders
|
||||||
'png'
|
'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def set_headers
|
||||||
headers['Pragma'] = "no-cache"
|
headers['Pragma'] = "no-cache"
|
||||||
headers['Expires'] = Time.now.utc.httpdate
|
headers['Expires'] = Time.now.utc.httpdate
|
||||||
headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}")
|
headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply
|
||||||
|
set_headers
|
||||||
send_file(filename, type: :png, last_modified: last_modified)
|
send_file(filename, type: :png, last_modified: last_modified)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user