Class: Hanami::Static

Inherits:
Rack::Static
  • Object
show all
Defined in:
lib/hanami/static.rb

Overview

Since:

  • 0.1.0

Constant Summary collapse

PATH_INFO =

Since:

  • 0.1.0

'PATH_INFO'.freeze
PUBLIC_DIRECTORY =

Since:

  • 0.1.0

Hanami.public_directory.join('**', '*').to_s.freeze
URL_SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • x.x.x

'/'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Static

Returns a new instance of Static.

Since:

  • 0.1.0



13
14
15
16
# File 'lib/hanami/static.rb', line 13

def initialize(app)
  super(app, root: Hanami.public_directory, header_rules: _header_rules)
  @sources = _sources_from_applications
end

Instance Method Details

#call(env) ⇒ Object

Since:

  • 0.1.0



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hanami/static.rb', line 18

def call(env)
  path           = env[PATH_INFO]

  prefix, config = @sources.find { |p, _| path.start_with?(p) }
  if prefix && config
    original = config.sources.find(path.sub(prefix, ''))
  end

  if can_serve(path, original)
    super
  else
    precompile(original, config) ?
      call(env) :
      @app.call(env)
  end
end