Module: Sinatra::FistFace

Defined in:
lib/fistface.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fistface.rb', line 7

def self.registered(app)
  app.before do
    expires 31536000, :public
    headers 'Access-Control-Allow-Origin' => '*'
  end

  app.get '/:font_face.css' do
    content_type 'text/css'
    open("#{ENV['S3_URL']}/#{params[:font_face]}.css").read
  end

  app.get '/:directory/:font_face' do
    content_type(
      case params[:font_face]
        when /\.ttf$/  then 'font/truetype'
        when /\.otf$/  then 'font/opentype'
        when /\.woff$/ then 'font/woff'
        when /\.eot$/  then 'application/vnd.ms-fontobject'
        when /\.svg$/  then 'image/svg+xml'
      end
    )
    open("#{ENV['S3_URL']}/#{params[:directory]}/#{params[:font_face]}").read
  end
end