0
@@ -866,7 +866,7 @@ module Sinatra
0
# (Sinatra::application).
0
get put post delete head template layout before error not_found
0
- configures configure set set_options set_option enable disable use
0
+ configures configure set set_options set_option enable disable use
resource0
# Create a new Application with a default configuration taken
0
@@ -994,21 +994,44 @@ module Sinatra
0
# NOTE: The #get, #post, #put, and #delete helper methods should
0
# be used to define events when possible.
0
def event(method, path, options = {}, &b)
0
- events[method].push(Event.new(path, options, &b)).last
0
+ events[method].push(Event.new(make_path(path), options, &b)).last
0
+ # Nest resources paths. Example:
0
+ # get { 'show all posts' }
0
+ # get ':id' { 'show post' }
0
+ # put ':id' { 'update post' }
0
+ def resource(path, &b)
0
+ orig_path = @path_parts
0
+ @path_parts = orig_path
0
+ def make_path(path) # :nodoc:
0
+ return path unless @path_parts
0
+ list << path if path and path != ''
0
+ ('/' + list.join('/')).squeeze('/')
0
# Define an event handler for GET requests.
0
- def get(path
, options={}, &b)
0
+ def get(path
='', options={}, &b)
0
event(:get, path, options, &b)
0
# Define an event handler for POST requests.
0
- def post(path
, options={}, &b)
0
+ def post(path
='', options={}, &b)
0
event(:post, path, options, &b)
0
# Define an event handler for HEAD requests.
0
- def head(path
, options={}, &b)
0
+ def head(path
='', options={}, &b)
0
event(:head, path, options, &b)
0
@@ -1017,7 +1040,7 @@ module Sinatra
0
# NOTE: PUT events are triggered when the HTTP request method is
0
# PUT and also when the request method is POST and the body includes a
0
# "_method" parameter set to "PUT".
0
- def put(path
, options={}, &b)
0
+ def put(path
='', options={}, &b)
0
event(:put, path, options, &b)
0
@@ -1026,7 +1049,7 @@ module Sinatra
0
# NOTE: DELETE events are triggered when the HTTP request method is
0
# DELETE and also when the request method is POST and the body includes a
0
# "_method" parameter set to "DELETE".
0
- def delete(path
, options={}, &b)
0
+ def delete(path
='', options={}, &b)
0
event(:delete, path, options, &b)