Class: Tipsy::Handler::StaticHandler
- Inherits:
-
Object
- Object
- Tipsy::Handler::StaticHandler
- Defined in:
- lib/tipsy/handler/static.rb
Overview
Handles serving/delivering static files from the /public directory.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#static ⇒ Object
readonly
Returns the value of attribute static.
-
#try_files ⇒ Object
readonly
Returns the value of attribute try_files.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ StaticHandler
constructor
A new instance of StaticHandler.
Constructor Details
#initialize(app, options) ⇒ StaticHandler
Returns a new instance of StaticHandler.
12 13 14 15 16 |
# File 'lib/tipsy/handler/static.rb', line 12 def initialize(app, ) @app = app @try_files = ['', *.delete(:try)] @static = ::Rack::Static.new(lambda { [404, {}, []] }, ) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/tipsy/handler/static.rb', line 10 def app @app end |
#static ⇒ Object (readonly)
Returns the value of attribute static.
10 11 12 |
# File 'lib/tipsy/handler/static.rb', line 10 def static @static end |
#try_files ⇒ Object (readonly)
Returns the value of attribute try_files.
10 11 12 |
# File 'lib/tipsy/handler/static.rb', line 10 def try_files @try_files end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tipsy/handler/static.rb', line 18 def call(env) pathinfo = env['PATH_INFO'] if(File.basename(pathinfo) == "favicon.ico") resp = static.call(env.merge!({ 'PATH_INFO' => pathinfo })) unless 404 == resp[0] resp[1].merge!({ "Pragma" => "nocache", "Cache-Control" => "max-age=0" }) return resp end end found = nil try_files.each do |path| response = static.call(env.merge!({ 'PATH_INFO' => pathinfo + path })) break if 404 != response[0] && found = response end found or app.call(env.merge!('PATH_INFO' => pathinfo)) end |