howl-router 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/config.ru +1 -1
- data/howl-router.gemspec +20 -0
- data/lib/howl-router/matcher.rb +5 -3
- data/lib/howl-router/padrino/ext/instance_methods.rb +33 -28
- data/lib/howl-router/request.rb +4 -0
- data/lib/howl-router/version.rb +1 -1
- data/test/howl_test.rb +2 -0
- data/test/padrino_test.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4ebbc66f3c3f654d674622767d7edf84254af76
|
4
|
+
data.tar.gz: a4f0e1a5b59fab741073bae7cf03fa985ada4ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c9892dd1461ab74ac61faceb3d5a92555793a5f4810d3c724008765aec3758dda65e478a6d22e534076bfce3b743a3d463920a2d1ed768870b3e301b1f8459
|
7
|
+
data.tar.gz: 08f15a1b94df198e78e195ea4a1e547b2552a3b2ef1d041f405fabfa3e56f2f771192471f09ad9b23ee456defad79e77e60be5ccaf9a8a384830049de3d1b90d
|
data/README.md
CHANGED
@@ -8,9 +8,13 @@ Howl works only in Ruby2.0.
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
add this line to your Gemfile.
|
12
12
|
|
13
|
-
`
|
13
|
+
`gem 'howl-router'`
|
14
|
+
|
15
|
+
or
|
16
|
+
|
17
|
+
`$ gem install howl-router`
|
14
18
|
|
15
19
|
## Example
|
16
20
|
|
data/config.ru
CHANGED
data/howl-router.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path("../lib/howl-router/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new "howl-router", Howl::VERSION do |s|
|
4
|
+
s.description = "A http router for Rack and Padrino."
|
5
|
+
s.summary = "http router library."
|
6
|
+
s.authors = ["namusyaka"]
|
7
|
+
s.email = "namusyaka@gmail.com"
|
8
|
+
s.homepage = "https://github.com/namusyaka/howl-router"
|
9
|
+
s.files = `git ls-files`.split("\n") - %w(.gitignore)
|
10
|
+
s.test_files = s.files.select { |path| path =~ /^test\/.*_test\.rb/ }
|
11
|
+
s.license = "MIT"
|
12
|
+
|
13
|
+
s.add_dependency "rack", ">= 1.3.0"
|
14
|
+
s.add_dependency "mustermann", "= 0.2.0"
|
15
|
+
s.add_development_dependency "rake", ">= 0.8.7"
|
16
|
+
s.add_development_dependency "rack-test", ">= 0.5.0"
|
17
|
+
s.add_development_dependency "mocha", ">= 0.10.0"
|
18
|
+
s.add_development_dependency "haml"
|
19
|
+
s.add_development_dependency "padrino-core"
|
20
|
+
end
|
data/lib/howl-router/matcher.rb
CHANGED
@@ -30,9 +30,11 @@ class Howl
|
|
30
30
|
|
31
31
|
def handler
|
32
32
|
@handler ||= case @path
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
when String
|
34
|
+
Mustermann.new(@path, :type => :rails, :capture => @capture, :uri_decode => nil)
|
35
|
+
when Regexp
|
36
|
+
/^(?:#{@path})$/
|
37
|
+
end
|
36
38
|
end
|
37
39
|
|
38
40
|
def to_s
|
@@ -3,41 +3,46 @@ class Howl
|
|
3
3
|
module Padrino
|
4
4
|
module InstanceMethods
|
5
5
|
private
|
6
|
+
def invoke_route(route, params, options = {})
|
7
|
+
original_params, parent_layout, successful = @params.dup, @layout, false
|
8
|
+
captured_params = params[:captures].is_a?(Array) ? params.delete(:captures) :
|
9
|
+
params.values_at(*route.matcher.names.dup)
|
10
|
+
|
11
|
+
@_response_buffer = nil
|
12
|
+
@route = request.route_obj = route
|
13
|
+
@params.merge!(params) if params.is_a?(Hash)
|
14
|
+
@params.merge!(:captures => captured_params) unless captured_params.empty?
|
15
|
+
@block_params = params
|
16
|
+
|
17
|
+
filter! :before if options[:first]
|
18
|
+
|
19
|
+
catch(:pass) do
|
20
|
+
begin
|
21
|
+
(route.before_filters - settings.filters[:before]).each{|block| instance_eval(&block) }
|
22
|
+
@layout = route.use_layout if route.use_layout
|
23
|
+
route.custom_conditions.each {|block|
|
24
|
+
pass if block.bind(self).call == false
|
25
|
+
} unless route.custom_conditions.empty?
|
26
|
+
halt_response = catch(:halt){ route_eval{ route.block[self, captured_params] }}
|
27
|
+
@_response_buffer = halt_response.is_a?(Array) ? halt_response.last : halt_response
|
28
|
+
successful = true
|
29
|
+
halt(halt_response)
|
30
|
+
ensure
|
31
|
+
(route.after_filters - settings.filters[:after]).each {|block| instance_eval(&block) } if successful
|
32
|
+
@layout, @params = parent_layout, original_params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
6
37
|
def route!(base = settings, pass_block = nil)
|
7
38
|
Thread.current['padrino.instance'] = self
|
8
39
|
code, headers, routes = base.compiled_router.call(@request.env)
|
9
40
|
|
10
41
|
status(code)
|
11
42
|
if code == 200
|
12
|
-
routes.each_with_index do |
|
13
|
-
route = route_pair[0]
|
43
|
+
routes.each_with_index do |(route, howl_params), index|
|
14
44
|
next if route.user_agent && !(route.user_agent =~ @request.user_agent)
|
15
|
-
|
16
|
-
|
17
|
-
howl_params = route_pair[1]
|
18
|
-
param_names = route.matcher.names.dup
|
19
|
-
captured_params = howl_params[:captures].is_a?(Array) ? howl_params.delete(:captures) : howl_params.values_at(*param_names)
|
20
|
-
|
21
|
-
@route = request.route_obj = route
|
22
|
-
@params.merge!(howl_params) if howl_params.is_a?(Hash)
|
23
|
-
@params.merge!(:captures => captured_params) unless captured_params.empty?
|
24
|
-
@block_params = howl_params
|
25
|
-
|
26
|
-
filter! :before if index == 0
|
27
|
-
|
28
|
-
catch(:pass) do
|
29
|
-
begin
|
30
|
-
(route.before_filters - settings.filters[:before]).each{|block| instance_eval(&block) }
|
31
|
-
@layout = route.use_layout if route.use_layout
|
32
|
-
route.custom_conditions.each {|block| pass if block.bind(self).call == false } unless route.custom_conditions.empty?
|
33
|
-
halt_response = catch(:halt){ route_eval{ route.block[self, captured_params] }}
|
34
|
-
successful = true
|
35
|
-
halt(halt_response)
|
36
|
-
ensure
|
37
|
-
(route.after_filters - settings.filters[:after]).each {|block| instance_eval(&block) } if successful
|
38
|
-
@layout, @params = parent_layout, original_params
|
39
|
-
end
|
40
|
-
end
|
45
|
+
invoke_route(route, howl_params, :first => index.zero?)
|
41
46
|
end
|
42
47
|
else
|
43
48
|
route_eval do
|
data/lib/howl-router/request.rb
CHANGED
data/lib/howl-router/version.rb
CHANGED
data/test/howl_test.rb
CHANGED
data/test/padrino_test.rb
CHANGED
@@ -110,6 +110,14 @@ describe "Howl::Padrino" do
|
|
110
110
|
assert_equal 'success!', body
|
111
111
|
end
|
112
112
|
|
113
|
+
should 'parse route that contains encoded param.' do
|
114
|
+
mock_app do
|
115
|
+
get('/foo/:name'){ params[:name] }
|
116
|
+
end
|
117
|
+
get(URI.escape('/foo/あいうえお'))
|
118
|
+
assert_equal 'あいうえお', body
|
119
|
+
end
|
120
|
+
|
113
121
|
should 'encode params using UTF-8' do
|
114
122
|
#skip unless ''.respond_to?(:encoding) # for 1.8.7
|
115
123
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: howl-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- namusyaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
121
|
- config.ru
|
122
|
+
- howl-router.gemspec
|
122
123
|
- lib/howl-router.rb
|
123
124
|
- lib/howl-router/matcher.rb
|
124
125
|
- lib/howl-router/padrino.rb
|