sinatra-controllers 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,9 @@
1
+
2
+ * 0.2.2
3
+ - fix bug with class with scope '/'.
4
+ - adding of Sinatra::Controllers.routes and Sinatra::Controllers.show_routes.
5
+ - adding example application.
6
+ * 0.2.1
7
+ - fix bug where omittance of leading slash and no defined scope leads to
8
+ TypeError
1
9
  * 0.2.0 add scoping
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-controllers (0.2.1)
4
+ sinatra-controllers (0.2.2)
5
5
  sinatra (>= 1.0.0)
6
6
 
7
7
  GEM
@@ -3,7 +3,8 @@
3
3
  Sinatra routing done differently. Allows for clean organization across
4
4
  multiple sinatra routes files.
5
5
 
6
- NOTE: this has only been tested with ruby 1.9.2
6
+ * this has only been tested with ruby 1.9.2
7
+ * redirect doesn't work.. yet
7
8
 
8
9
 
9
10
  == Examples
@@ -18,20 +18,26 @@ module Sinatra
18
18
  end
19
19
  module Controllers
20
20
  class Mapping
21
+ @@routes = []
21
22
  attr_accessor :klass, :opts
22
-
23
23
  def initialize(klass,opts={})
24
24
  @klass = klass
25
25
  @opts = opts
26
26
  end
27
27
 
28
+ def self.routes
29
+ @@routes
30
+ end
31
+
28
32
  def route(verb, path, action)
29
33
  aklass = klass # need this so it will stay in scope for closure
30
34
  block = proc { aklass.new(params, request).send action }
31
35
  if path[0] != '/'
32
36
  path = '/' + File.join(opts[:scope] || '', path)
33
37
  end
34
- Sinatra::Application.send verb, path, &block
38
+ @@routes.push [verb.to_sym, path, "#{aklass}\##{action}"]
39
+ path.gsub!(%r{^/+},'/')
40
+ Sinatra::Base.send verb, path, &block
35
41
  end
36
42
 
37
43
  def parse
@@ -62,6 +68,16 @@ module Sinatra
62
68
  map.instance_eval(&block) if block
63
69
  map.parse
64
70
  end
71
+ def routes
72
+ Sinatra::Controllers::Mapping.routes
73
+ end
74
+ def show_routes
75
+ routes.each do |verb, path, action|
76
+ puts
77
+ puts "#{verb.to_s.ljust(8)}#{path.ljust(35)}#{action.ljust(25)}"
78
+ puts
79
+ end
80
+ end
65
81
  end
66
82
  end
67
83
  end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Controllers
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -22,6 +22,13 @@ class Leader < Sinatra::Controller
22
22
  end
23
23
  end
24
24
 
25
+ class Sliders < Sinatra::Controller
26
+ def get_quinn
27
+ 'mallory'
28
+ end
29
+ end
30
+ Sinatra::Controllers.register(Sliders, :scope => '/')
31
+
25
32
  Sinatra::Controllers.register(Show70, :scope => '/70s_show')
26
33
  # make sure we don't need leading slash
27
34
  Sinatra::Controllers.register(Seinfeld, :scope => 'seinfeld') do
@@ -42,6 +49,12 @@ describe "with defined scope" do
42
49
  end
43
50
  end
44
51
 
52
+ it "should get a scope of slash correctly for a class" do
53
+ get '/quinn'
54
+ last_response.status.must_equal 200
55
+ last_response.body.must_equal 'mallory'
56
+ end
57
+
45
58
  it "should use correct scope" do
46
59
  get '/70s_show/kelso'
47
60
  last_response.status.must_equal 200
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Bretoi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-08 00:00:00 -07:00
17
+ date: 2011-04-09 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -138,7 +138,7 @@ files:
138
138
  - test/controller_test.rb
139
139
  - test/helper.rb
140
140
  - test/no_block_test.rb
141
- - test/path_defined_test.rb
141
+ - test/scope_defined_test.rb
142
142
  - test/views/foo.haml
143
143
  - test/views/fringe.haml
144
144
  - test/watchr.rb
@@ -180,7 +180,7 @@ test_files:
180
180
  - test/controller_test.rb
181
181
  - test/helper.rb
182
182
  - test/no_block_test.rb
183
- - test/path_defined_test.rb
183
+ - test/scope_defined_test.rb
184
184
  - test/views/foo.haml
185
185
  - test/views/fringe.haml
186
186
  - test/watchr.rb