howl-router 0.1 → 0.1.1

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
  SHA1:
3
- metadata.gz: 81ee1a9fd3fb9b42514e112a63ae5d0da2531553
4
- data.tar.gz: 18f0e9a58f174d209feb7857d77918067059b7ff
3
+ metadata.gz: a4ebbc66f3c3f654d674622767d7edf84254af76
4
+ data.tar.gz: a4f0e1a5b59fab741073bae7cf03fa985ada4ab9
5
5
  SHA512:
6
- metadata.gz: 23a2afffa48fabc92fa977bf01de758575dd5bd8bed88345cf6d9c92e12e43584143330262a5afeff6e9a6709718e17c1502c14c2ce6f2467e03e75699c10f23
7
- data.tar.gz: a08e7b11b6a41c65fd66e8635662aac4c62fcf7c78580ea45cf9d5305088f8c7eb7515d8a1203f3a06bd6fd0f36a32e765651e8692a01a5e7dc50f9baacb76cb
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
- `git clone git@github.com:namusyaka/howl-router.git`
11
+ add this line to your Gemfile.
12
12
 
13
- `cd howl-router; bundle install`
13
+ `gem 'howl-router'`
14
+
15
+ or
16
+
17
+ `$ gem install howl-router`
14
18
 
15
19
  ## Example
16
20
 
data/config.ru CHANGED
@@ -1,4 +1,4 @@
1
- load File.expand_path('../lib/howl.rb', __FILE__)
1
+ load File.expand_path('../lib/howl-router.rb', __FILE__)
2
2
 
3
3
  howl = Howl.new
4
4
 
@@ -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
@@ -30,9 +30,11 @@ class Howl
30
30
 
31
31
  def handler
32
32
  @handler ||= case @path
33
- when String then Mustermann.new(@path, :type => :rails, :capture => @capture)
34
- when Regexp then /^(?:#{@path})$/
35
- end
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 |route_pair, index|
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
- original_params, parent_layout, successful = @params.dup, @layout, false
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
@@ -3,5 +3,9 @@ require 'rack'
3
3
  class Howl
4
4
  class Request < Rack::Request
5
5
  attr_accessor :acceptable_methods
6
+
7
+ def path_info
8
+ Rack::Utils.unescape super
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  class Howl
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
data/test/howl_test.rb CHANGED
@@ -33,6 +33,8 @@ describe Howl do
33
33
 
34
34
  get("/1")
35
35
  assert_equal "show 1", body
36
+ get(URI.escape("/あいうえお"))
37
+ assert_equal "show あいうえお", body
36
38
  get("/foo")
37
39
  assert_equal "show foo", body
38
40
  get("/1.json")
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: '0.1'
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-24 00:00:00.000000000 Z
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