phaedra 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f0e4c33ad4a5241f2a6b7455522db8389a1bc2323ef4542ad75546b2b874a08
4
- data.tar.gz: 42f380fa9cb7a620da9591862c7fd7abbd4022e8046c1ed8f089e902a052c1c2
3
+ metadata.gz: f8a4e661423271591485445de16dbbbd5921bfd3f677e4c9cccfd08a3634b79b
4
+ data.tar.gz: 513392234c9c02188d0fc20de6b83e0642133c0abdf246f4af9a7c06d72264dd
5
5
  SHA512:
6
- metadata.gz: 0003a862d70c030695b33c1318c69c14eb3f0eda149590e485083827d6c703c06d68dbf8daa6c39e911274b5a5527c2e043aa327e18759bdb8ff970179e764cd
7
- data.tar.gz: a5a22957adcb6c3e1fbce24e39e4c7b582381936b3d832d23ea32813888d5789ea779e89116fb3b16ac1a7122db97ac77d6de2fdd909ee791d351629f3c7dfcb
6
+ metadata.gz: 8e6421d7c5bab7f3acc94e5858c1b7695df4ce71d2613c5f4d87821d9fcd96f23286c01bf49ea715343f51a23f534d91923498b0bd99265f7fb31474de42ffac
7
+ data.tar.gz: d90e7402c1e8ea1d6c9afdd4fb530f4ad3fbbe289d59bff67d7dcf55b3783ec65778c5f41b625d1f4046acb3fc7d64f78160aec43f14d0738f8457bdc47b52eb
@@ -0,0 +1,2 @@
1
+ require "phaedra/middleware/not_found"
2
+ require "phaedra/middleware/static"
@@ -0,0 +1,21 @@
1
+ module Phaedra
2
+ module Middleware
3
+ class NotFound
4
+ def initialize(app, path, content_type = 'text/html; charset=utf-8')
5
+ @app = app
6
+ @content = File.read(path)
7
+ @length = @content.bytesize.to_s
8
+ @content_type = content_type
9
+ end
10
+
11
+ def call(env)
12
+ response = @app.call(env)
13
+ if response[0] == 404
14
+ [404, {'Content-Type' => @content_type, 'Content-Length' => @length}, [@content]]
15
+ else
16
+ response
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module Phaedra
2
+ module Middleware
3
+ # Based on Rack::TryStatic middleware
4
+ # https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
5
+
6
+ class Static
7
+ def initialize(app, options)
8
+ @app = app
9
+ @try = [".html", "index.html", "/index.html"] #, *options[:try]]
10
+ @static = Rack::Static.new(
11
+ lambda { |_| [404, {}, []] },
12
+ options)
13
+ end
14
+
15
+ def call(env)
16
+ orig_path = env['PATH_INFO']
17
+ found = nil
18
+ @try.each do |path|
19
+ resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
20
+ break if !(403..405).include?(resp[0]) && found = resp
21
+ end
22
+ found or @app.call(env.merge!('PATH_INFO' => orig_path))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Phaedra
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phaedra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -87,6 +87,9 @@ files:
87
87
  - lib/phaedra.rb
88
88
  - lib/phaedra/base.rb
89
89
  - lib/phaedra/concerns/callbacks_actionable.rb
90
+ - lib/phaedra/middleware.rb
91
+ - lib/phaedra/middleware/not_found.rb
92
+ - lib/phaedra/middleware/static.rb
90
93
  - lib/phaedra/rack_app.rb
91
94
  - lib/phaedra/version.rb
92
95
  - phaedra.gemspec