Class: Pith::Server::OutputFinder
- Inherits:
-
Object
- Object
- Pith::Server::OutputFinder
- Defined in:
- lib/pith/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, project) ⇒ OutputFinder
constructor
A new instance of OutputFinder.
Constructor Details
#initialize(app, project) ⇒ OutputFinder
Returns a new instance of OutputFinder.
23 24 25 26 |
# File 'lib/pith/server.rb', line 23 def initialize(app, project) @app = app @project = project end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pith/server.rb', line 28 def call(env) @project.sync_every(1) path_info = ::Rack::Utils.unescape(env["PATH_INFO"]) ends_with_slash = (path_info[-1] == '/') outputs = @project.outputs.sort_by { |output| output.path } outputs.each do |output| output_path = "/" + output.path.to_s if !ends_with_slash && output_path =~ %r{^#{path_info}/} return [ 302, { "Location" => path_info + "/" }, [] ] end ["", ".html", "index.html"].map do |ext| if output_path == (path_info + ext) output.build env["PATH_INFO"] += ext return @app.call(env) end end end @app.call(env) end |