tansu 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd67f1e2c6100222b3b22315e166451be9ae789e
4
- data.tar.gz: 5805a8800e971efc0b277e71e15d10bd766fc1bf
3
+ metadata.gz: 3255da4f480f3428f7a2c65590f171229879256d
4
+ data.tar.gz: 53d76f95e8831b43946cafb6ad64a32224757e07
5
5
  SHA512:
6
- metadata.gz: a0f706c3bfabf11d502018c54e7ff795aa527b2239d825aa4b485ea2d6907cf9f8013bf05728b7f7c36cda099aa15b586b77f414a5065eb2e5bd8cb7e55711bc
7
- data.tar.gz: 5db1cdb46be41625f410c1ad851e046fe2ef915c75cbd8f9bedc05afe55edd4d54d25ef3b16aa42bdac516ddb901131e0f689271c4315dac8a053f94c5018cce
6
+ metadata.gz: 09c18f040d39a93ba9e7ae35c5bbc14c6a5ea41464616e19b199528598e800a4da35fa2762e691a4211335f4884153800e2b352916de3c19b40325dbedfbd643
7
+ data.tar.gz: 14b626ceb849b3f8600e5f58fee281d08f52668bd86e84e6c9f21cc01794922c663f97adb22ef3b666e4162d64d4ff78fff2949fb6e0bf281a41f6e69592330c
data/README.md CHANGED
@@ -6,7 +6,7 @@ Tansu is a web-application framework.
6
6
 
7
7
  ## Installation
8
8
 
9
- `Gemfile`:
9
+ Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
12
  gem 'tansu'
@@ -0,0 +1,50 @@
1
+ module Tansu
2
+ class Static
3
+ ACCEPT_METHODS = %w(GET HEAD)
4
+
5
+ def initialize(app, root)
6
+ @app = app
7
+ @root = root
8
+ @file_server = Rack::File.new(root)
9
+ @parser = URI::Parser.new
10
+ end
11
+
12
+ def match(path)
13
+ return false unless path = verify(path)
14
+
15
+ path = Rack::Utils.clean_path_info(path)
16
+
17
+ match?(path) && path
18
+ end
19
+
20
+ def call(env)
21
+ method = env['REQUEST_METHOD']
22
+ path = env['PATH_INFO']
23
+
24
+ if ACCEPT_METHODS.include?(method) && path = match(path)
25
+ env['PATH_INFO'] = path
26
+
27
+ @file_server.(env)
28
+ else
29
+ @app.(env)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def verify(path)
36
+ encode = Encoding::UTF_8 if (encode = path.encoding) == Encoding::US_ASCII
37
+ path = @parser.unescape(path).force_encoding(encode)
38
+
39
+ path.valid_encoding? ? path : false
40
+ end
41
+
42
+ def match?(path)
43
+ path = File.join(@root, path)
44
+
45
+ File.file?(path) && File.readable?(path)
46
+ rescue SystemCallError
47
+ false
48
+ end
49
+ end
50
+ end
data/lib/tansu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tansu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/tansu.rb CHANGED
@@ -1,15 +1,17 @@
1
- require "rack"
2
- require "minicontext"
3
- require "tilt"
4
- require "rack/protection"
1
+ require 'uri'
2
+ require 'rack'
3
+ require 'minicontext'
4
+ require 'tilt'
5
+ require 'rack/protection'
5
6
 
6
- require "tansu/version"
7
- require "tansu/context"
8
- require "tansu/response"
9
- require "tansu/render"
10
- require "tansu/environment"
11
- require "tansu/configuration"
12
- require "tansu/application"
7
+ require 'tansu/version'
8
+ require 'tansu/context'
9
+ require 'tansu/response'
10
+ require 'tansu/render'
11
+ require 'tansu/environment'
12
+ require 'tansu/configuration'
13
+ require 'tansu/application'
14
+ require 'tansu/static'
13
15
 
14
16
  module Tansu
15
17
  class << self
data/tansu.gemspec CHANGED
@@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ["lib"]
21
22
 
22
23
  spec.add_dependency "rack"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tansu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - daisuko
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-08 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -125,9 +125,7 @@ dependencies:
125
125
  description:
126
126
  email:
127
127
  - striker.daisuko@gmail.com
128
- executables:
129
- - console
130
- - setup
128
+ executables: []
131
129
  extensions: []
132
130
  extra_rdoc_files: []
133
131
  files:
@@ -147,6 +145,7 @@ files:
147
145
  - lib/tansu/environment.rb
148
146
  - lib/tansu/render.rb
149
147
  - lib/tansu/response.rb
148
+ - lib/tansu/static.rb
150
149
  - lib/tansu/version.rb
151
150
  - tansu.gemspec
152
151
  homepage: https://github.com/daisuko/tansu