Class: Locomotive::Middlewares::Fonts

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/middlewares/fonts.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Fonts

Returns a new instance of Fonts.



5
6
7
8
9
# File 'lib/locomotive/middlewares/fonts.rb', line 5

def initialize(app, opts = {})
  @app          = app
  @path_regexp  = opts[:path] || %r{^/fonts/}
  @expires_in   = opts[:expires_in] || 24.hour # varnish
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/locomotive/middlewares/fonts.rb', line 11

def call(env)
  if env["PATH_INFO"] =~ @path_regexp
    if Locomotive.config.multi_sites?
      site = fetch_site(env['SERVER_NAME'])
    else
      site = Site.first
    end

    if site.nil?
      @app.call(env)
    else
      body = ThemeAssetUploader.build(site, env['PATH_INFO']).read.to_s

      [200, { 'Cache-Control' => "public; max-age=#{@expires_in}" }, [body]]
    end
  else
    @app.call(env)
  end
end