Permalink
Browse files

add docs for Sinatra::Extension

  • Loading branch information...
1 parent 8910455 commit e0285d84254752062ed3bbb148d79aee7eeb9d09 @gnandretta gnandretta committed Jul 17, 2011
Showing with 45 additions and 0 deletions.
  1. +45 −0 lib/sinatra/extension.rb
View
@@ -2,6 +2,51 @@
require 'backports/basic_object' unless defined? BasicObject
module Sinatra
+
+ # = Sinatra::Extension
+ #
+ # <tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar
+ # for your extensions. It allows you to call directly inside your extension
+ # module almost any <tt>Sinatra::Base</tt> method. This means you can use
+ # +get+ to define a route, +before+ to define a before filter, +set+ to
+ # define a setting, a so on.
+ #
+ # Is important to be aware that this mixin remembers the methods calls you
+ # make, and then, when your extension is registered, replays them on the
+ # Sinatra application that has been extended. In order to do that, it
+ # defines a <tt>registered</tt> method, so, if your extension defines one
+ # too, remember to call +super+.
+ #
+ # == Usage
+ #
+ # Just require the mixin and extend your extension with it:
+ #
+ # require 'sinatra/extension'
+ #
+ # module MyExtension
+ # extend Sinatra::Extension
+ #
+ # # set some settings for development
+ # configure :development do
+ # set :reload_stuff, true
+ # end
+ #
+ # # define a route
+ # get '/' do
+ # 'Hello World'
+ # end
+ #
+ # # The rest of your extension code goes here...
+ # end
+ #
+ # You can also create an extension with the +new+ method:
+ #
+ # MyExtension = Sinatra::Extension.new do
+ # # Your extension code goes here...
+ # end
+ #
+ # This is useful when you just want to pass a block to
+ # <tt>Sinatra::Base.register</tt>.
module Extension
def self.new(&block)
ext = Module.new.extend(self)

0 comments on commit e0285d8

Please sign in to comment.