Skip to content

Instantly share code, notes, and snippets.

@jamiehodge
Created April 10, 2012 14:31
Show Gist options
  • Save jamiehodge/2351768 to your computer and use it in GitHub Desktop.
Save jamiehodge/2351768 to your computer and use it in GitHub Desktop.
sinatra/mount
module Sinatra
module Mount
def mount(app, route="/#{app.name.downcase}")
%w{get post put delete patch options}.each do |method|
self.send method.to_sym, "#{route}*" do
app.call(
env.merge!(
'SCRIPT_NAME' => route.split('/').last,
'PATH_INFO' => params.delete('splat').join('/')
)
)
end
end
end
end
register Mount
end
@jamiehodge
Copy link
Author

Usage:

require 'sinatra/mount'

class Foo < Sinatra::Base
  register Sinatra::Mount

  mount Bar, ':foo/bars'
end

Note: the splat pulls in whatever follows, trailing slash or no trailing slash

@merqlove
Copy link

Looks it working well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment