Class: Lotus::Static

Inherits:
Rack::Static
  • Object
show all
Defined in:
lib/lotus/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

Lotus.public_directory.join('**', '*').to_s.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Static

Returns a new instance of Static.

Since:

  • 0.1.0



9
10
11
12
# File 'lib/lotus/static.rb', line 9

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

Instance Method Details

#call(env) ⇒ Object

Since:

  • 0.1.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lotus/static.rb', line 14

def call(env)
  path           = env[PATH_INFO]

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

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