Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

regenerate contrib docs

  • Loading branch information...
commit 9e0dacebd9f3db87724023a5b236137ee3cdfa40 1 parent 64378f9
@rkh rkh authored
View
171 _includes/sinatra-config-file.html
@@ -1,106 +1,95 @@
+
<h1>Sinatra::ConfigFile</h1>
-<p>
-<tt>Sinatra::ConfigFile</tt> is an extension that allows you to load the
-application&#8217;s configuration from YAML files. It automatically
-detects if the files contains specific environment settings and it will use
-the corresponding to the current one.
-</p>
-<p>
-Within the application you can access those options through
-<tt>settings</tt>. If you try to get the value for a setting that
-hasn&#8217;t been defined in the config file for the current environment,
-you will get whatever it was set to in the application.
-</p>
+
+<p><tt>Sinatra::ConfigFile</tt> is an extension that allows you to load the
+application's configuration from YAML files. It automatically detects if
+the files contains specific environment settings and it will use the
+corresponding to the current one.</p>
+
+<p>Within the application you can access those options through
+<tt>settings</tt>. If you try to get the value for a setting that hasn't
+been defined in the config file for the current environment, you will get
+whatever it was set to in the application.</p>
+
<h2>Usage</h2>
-<p>
-Once you have written your configurations to a YAML file you can tell the
+
+<p>Once you have written your configurations to a YAML file you can tell the
extension to load them. See below for more information about how these
-files are interpreted.
-</p>
-<p>
-For the examples, lets assume the following config.yml file:
-</p>
-<pre>
- greeting: Welcome to my file configurable application
-</pre>
+files are interpreted.</p>
+
+<p>For the examples, lets assume the following config.yml file:</p>
+
+<pre>greeting: Welcome to my file configurable application</pre>
+
<h3>Classic Application</h3>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/config_file&quot;
- config_file 'path/to/config.yml'
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/config_file&quot;
+
+config_file 'path/to/config.yml'
- get '/' do
- @greeting = settings.greeting
- haml :index
- end
+get '/' do
+ @greeting = settings.greeting
+ haml :index
+end
+
+# The rest of your classic application code goes here...</pre>
- # The rest of your classic application code goes here...
-</pre>
<h3>Modular Application</h3>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/config_file&quot;
- class MyApp &lt; Sinatra::Base
- register Sinatra::ConfigFile
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/config_file&quot;
+
+class MyApp &lt; Sinatra::Base
+ register Sinatra::ConfigFile
- config_file 'path/to/config.yml'
+ config_file 'path/to/config.yml'
- get '/' do
- @greeting = settings.greeting
- haml :index
- end
+ get '/' do
+ @greeting = settings.greeting
+ haml :index
+ end
+
+ # The rest of your modular application code goes here...
+end</pre>
- # The rest of your modular application code goes here...
- end
-</pre>
<h3>Config File Format</h3>
-<p>
-In its most simple form this file is just a key-value list:
-</p>
-<pre>
- foo: bar
- something: 42
- nested:
- a: 1
- b: 2
-</pre>
-<p>
-But it also can provide specific environment configuration. There are two
+
+<p>In its most simple form this file is just a key-value list:</p>
+
+<pre>foo: bar
+something: 42
+nested:
+ a: 1
+ b: 2</pre>
+
+<p>But it also can provide specific environment configuration. There are two
ways to do that: at the file level and at the setting level. They are
-illustrated, repsectively, as follows:
-</p>
-<pre>
- development:
- foo: development
- bar: bar
- test:
- foo: test
- bar: bar
- production:
- foo: production
- bar: bar
-</pre>
-<p>
-and
-</p>
-<pre>
- foo:
- development: development
- test: test
- production: production
- bar: bar
-</pre>
-<p>
-In either case, <tt>settings.foo</tt> will return the environment name, and
-<tt>settings.bar</tt> will return <tt>&quot;bar&quot;</tt>.
-</p>
-<p>
-Be aware that if you have a different environment, besides development,
+illustrated, repsectively, as follows:</p>
+
+<pre>development:
+ foo: development
+ bar: bar
+test:
+ foo: test
+ bar: bar
+production:
+ foo: production
+ bar: bar</pre>
+
+<p>and</p>
+
+<pre>foo:
+ development: development
+ test: test
+ production: production
+bar: bar</pre>
+
+<p>In either case, <tt>settings.foo</tt> will return the environment name, and
+<tt>settings.bar</tt> will return <tt>&quot;bar&quot;</tt>.</p>
+
+<p>Be aware that if you have a different environment, besides development,
test and production, you will also need to adjust the <tt>environments</tt>
-setting. For instance, when you also have a staging environment:
-</p>
-<pre>
- set :environments, %w{development test production staging}
-</pre>
+setting. For instance, when you also have a staging environment:</p>
+
+<pre>set :environments, %w{development test production staging}</pre>
View
106 _includes/sinatra-content-for.html
@@ -1,63 +1,57 @@
+
<h1>Sinatra::ContentFor</h1>
-<p>
-<tt>Sinatra::ContentFor</tt> is a set of helpers that allows you to capture
+
+<p><tt>Sinatra::ContentFor</tt> is a set of helpers that allows you to capture
blocks inside views to be rendered later during the request. The most
-common use is to populate different parts of your layout from your view.
-</p>
-<p>
-The currently supported engines are: Erb, Erubis, Haml and Slim.
-</p>
+common use is to populate different parts of your layout from your view.</p>
+
+<p>The currently supported engines are: Erb, Erubis, Haml and Slim.</p>
+
<h2>Usage</h2>
-<p>
-You call <tt>content_for</tt>, generally from a view, to capture a block of
-markup giving it an identifier:
-</p>
-<pre>
- # index.erb
- &lt;% content_for :some_key do %&gt;
- &lt;chunk of=&quot;html&quot;&gt;...&lt;/chunk&gt;
- &lt;% end %&gt;
-</pre>
-<p>
-Then, you call <tt>yield_content</tt> with that identifier, generally from
-a layout, to render the captured block:
-</p>
-<pre>
- # layout.erb
- &lt;%= yield_content :some_key %&gt;
-</pre>
+
+<p>You call <tt>content_for</tt>, generally from a view, to capture a block of
+markup giving it an identifier:</p>
+
+<pre># index.erb
+&lt;% content_for :some_key do %&gt;
+ &lt;chunk of=&quot;html&quot;&gt;...&lt;/chunk&gt;
+&lt;% end %&gt;</pre>
+
+<p>Then, you call <tt>yield_content</tt> with that identifier, generally from
+a layout, to render the captured block:</p>
+
+<pre># layout.erb
+&lt;%= yield_content :some_key %&gt;</pre>
+
<h3>Classic Application</h3>
-<p>
-To use the helpers in a classic application all you need to do is require
-them:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/content_for&quot;
-
- # Your classic application code goes here...
-</pre>
+
+<p>To use the helpers in a classic application all you need to do is require
+them:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/content_for&quot;
+
+# Your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-To use the helpers in a modular application you need to require them, and
-then, tell the application you will use them:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/content_for&quot;
-
- class MyApp &lt; Sinatra::Base
- helpers Sinatra::ContentFor
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>To use the helpers in a modular application you need to require them, and
+then, tell the application you will use them:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/content_for&quot;
+
+class MyApp &lt; Sinatra::Base
+ helpers Sinatra::ContentFor
+
+ # The rest of your modular application code goes here...
+end</pre>
+
<h2>And How Is This Useful?</h2>
-<p>
-For example, some of your views might need a few javascript tags and
-stylesheets, but you don&#8217;t want to force this files in all your
-pages. Then you can put <tt>&lt;% yield_content :scripts_and_styles
-%&gt;</tt> on your layout, inside the <head> tag, and each view can call
+
+<p>For example, some of your views might need a few javascript tags and
+stylesheets, but you don't want to force this files in all your pages. Then
+you can put <tt>&lt;% yield_content :scripts_and_styles %&gt;</tt> on your
+layout, inside the &lt;head&gt; tag, and each view can call
<tt>content_for</tt> setting the appropriate set of tags that should be
-added to the layout.
-</p>
+added to the layout.</p>
View
101 _includes/sinatra-cookies.html
@@ -1,58 +1,51 @@
+
<h1>Sinatra::Cookies</h1>
-<p>
-Easy way to deal with cookies
-</p>
+
+<p>Easy way to deal with cookies</p>
+
<h2>Usage</h2>
-<p>
-Allows you to read cookies:
-</p>
-<pre>
- get '/' do
- &quot;value: #{cookie[:something]}&quot;
- end
-</pre>
-<p>
-And of course to write cookies:
-</p>
-<pre>
- get '/set' do
- cookies[:something] = 'foobar'
- redirect to('/')
- end
-</pre>
-<p>
-And generally behaves like a hash:
-</p>
-<pre>
- get '/demo' do
- cookies.merge! 'foo' =&gt; 'bar', 'bar' =&gt; 'baz'
- cookies.keep_if { |key, value| key.start_with? 'b' }
- foo, bar = cookies.values_at 'foo', 'bar'
- &quot;size: #{cookies.length}&quot;
- end
-</pre>
+
+<p>Allows you to read cookies:</p>
+
+<pre>get '/' do
+ &quot;value: #{cookie[:something]}&quot;
+end</pre>
+
+<p>And of course to write cookies:</p>
+
+<pre>get '/set' do
+ cookies[:something] = 'foobar'
+ redirect to('/')
+end</pre>
+
+<p>And generally behaves like a hash:</p>
+
+<pre>get '/demo' do
+ cookies.merge! 'foo' =&gt; 'bar', 'bar' =&gt; 'baz'
+ cookies.keep_if { |key, value| key.start_with? 'b' }
+ foo, bar = cookies.values_at 'foo', 'bar'
+ &quot;size: #{cookies.length}&quot;
+end</pre>
+
<h3>Classic Application</h3>
-<p>
-In a classic application simply require the helpers, and start using them:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/cookies&quot;
-
- # The rest of your classic application code goes here...
-</pre>
+
+<p>In a classic application simply require the helpers, and start using them:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/cookies&quot;
+
+# The rest of your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-In a modular application you need to require the helpers, and then tell the
-application you will use them:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/cookies&quot;
-
- class MyApp &lt; Sinatra::Base
- helpers Sinatra::Cookies
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>In a modular application you need to require the helpers, and then tell the
+application you will use them:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/cookies&quot;
+
+class MyApp &lt; Sinatra::Base
+ helpers Sinatra::Cookies
+
+ # The rest of your modular application code goes here...
+end</pre>
View
69 _includes/sinatra-decompile.html
@@ -1,43 +1,40 @@
+
<h1>Sinatra::Decompile</h1>
-<p>
-<tt>Sinatra::Decompile</tt> is an extension that provides a method,
+
+<p><tt>Sinatra::Decompile</tt> is an extension that provides a method,
conveniently called <tt>decompile</tt>, that will generate a String pattern
-for a given route.
-</p>
+for a given route.</p>
+
<h2>Usage</h2>
+
<h3>Classic Application</h3>
-<p>
-To use the extension in a classic application all you need to do is require
-it:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/decompile&quot;
-
- # Your classic application code goes here...
-</pre>
-<p>
-This will add the <tt>decompile</tt> method to the application/class scope,
-but you can also call it as <tt>Sinatra::Decompile.decompile</tt>.
-</p>
+
+<p>To use the extension in a classic application all you need to do is require
+it:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/decompile&quot;
+
+# Your classic application code goes here...</pre>
+
+<p>This will add the <tt>decompile</tt> method to the application/class scope,
+but you can also call it as <tt>Sinatra::Decompile.decompile</tt>.</p>
+
<h3>Modular Application</h3>
-<p>
-To use the extension in a modular application you need to require it, and
-then, tell the application you will use it:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/decompile&quot;
-
- class MyApp &lt; Sinatra::Base
- register Sinatra::Decompile
-
- # The rest of your modular application code goes here...
- end
-</pre>
-<p>
-This will add the <tt>decompile</tt> method to the application/class scope.
+
+<p>To use the extension in a modular application you need to require it, and
+then, tell the application you will use it:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/decompile&quot;
+
+class MyApp &lt; Sinatra::Base
+ register Sinatra::Decompile
+
+ # The rest of your modular application code goes here...
+end</pre>
+
+<p>This will add the <tt>decompile</tt> method to the application/class scope.
You can choose not to register the extension, but instead of calling
<tt>decompile</tt>, you will need to call
-<tt>Sinatra::Decompile.decompile</tt>.
-</p>
+<tt>Sinatra::Decompile.decompile</tt>.</p>
View
79 _includes/sinatra-extension.html
@@ -1,50 +1,45 @@
+
<h1>Sinatra::Extension</h1>
-<p>
-<tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar
+
+<p><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
<tt>get</tt> to define a route, <tt>before</tt> to define a before filter,
-<tt>set</tt> to define a setting, a so on.
-</p>
-<p>
-Is important to be aware that this mixin remembers the methods calls you
+<tt>set</tt> to define a setting, a so on.</p>
+
+<p>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 <tt>super</tt>.
-</p>
+too, remember to call <tt>super</tt>.</p>
+
<h2>Usage</h2>
-<p>
-Just require the mixin and extend your extension with it:
-</p>
-<pre>
- 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
-</pre>
-<p>
-You can also create an extension with the <tt>new</tt> method:
-</p>
-<pre>
- MyExtension = Sinatra::Extension.new do
- # Your extension code goes here...
- end
-</pre>
-<p>
-This is useful when you just want to pass a block to
-<tt>Sinatra::Base.register</tt>.
-</p>
+
+<p>Just require the mixin and extend your extension with it:</p>
+
+<pre>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</pre>
+
+<p>You can also create an extension with the <tt>new</tt> method:</p>
+
+<pre>MyExtension = Sinatra::Extension.new do
+ # Your extension code goes here...
+end</pre>
+
+<p>This is useful when you just want to pass a block to
+<tt>Sinatra::Base.register</tt>.</p>
View
166 _includes/sinatra-json.html
@@ -1,99 +1,87 @@
+
<h1>Sinatra::JSON</h1>
-<p>
-<tt>Sinatra::JSON</tt> adds a helper method, called <tt>json</tt>, for
-(obviously) json generation.
-</p>
+
+<p><tt>Sinatra::JSON</tt> adds a helper method, called <tt>json</tt>, for
+(obviously) json generation.</p>
+
<h2>Usage</h2>
+
<h3>Classic Application</h3>
-<p>
-In a classic application simply require the helper, and start using it:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/json&quot;
-
- # define a route that uses the helper
- get '/' do
- json :foo =&gt; 'bar'
- end
-
- # The rest of your classic application code goes here...
-</pre>
+
+<p>In a classic application simply require the helper, and start using it:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/json&quot;
+
+# define a route that uses the helper
+get '/' do
+ json :foo =&gt; 'bar'
+end
+
+# The rest of your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-In a modular application you need to require the helper, and then tell the
-application you will use it:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/json&quot;
-
- class MyApp &lt; Sinatra::Base
- helpers Sinatra::JSON
-
- # define a route that uses the helper
- get '/' do
- json :foo =&gt; 'bar'
- end
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>In a modular application you need to require the helper, and then tell the
+application you will use it:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/json&quot;
+
+class MyApp &lt; Sinatra::Base
+ helpers Sinatra::JSON
+
+ # define a route that uses the helper
+ get '/' do
+ json :foo =&gt; 'bar'
+ end
+
+ # The rest of your modular application code goes here...
+end</pre>
+
<h3>Encoders</h3>
-<p>
-Per default it will try to call <tt>to_json</tt> on the object, but if it
-doesn&#8217;t respond to that message, will use its own, rather simple
-encoder. You can easily change that anyways. To use <tt>JSON</tt>, simply
-require it:
-</p>
-<pre>
- require 'json'
-</pre>
-<p>
-The same goes for <tt>Yajl::Encoder</tt>:
-</p>
-<pre>
- require 'yajl'
-</pre>
-<p>
-For other encoders, besides requiring them, you need to define the
+
+<p>Per default it will try to call <tt>to_json</tt> on the object, but if it
+doesn't respond to that message, will use its own, rather simple encoder.
+You can easily change that anyways. To use <tt>JSON</tt>, simply require
+it:</p>
+
+<pre>require 'json'</pre>
+
+<p>The same goes for <tt>Yajl::Encoder</tt>:</p>
+
+<pre>require 'yajl'</pre>
+
+<p>For other encoders, besides requiring them, you need to define the
<tt>:json_encoder</tt> setting. For instance, for the <tt>Whatever</tt>
-encoder:
-</p>
-<pre>
- require 'whatever'
- set :json_encoder, Whatever
-</pre>
-<p>
-To force <tt>json</tt> to simply call <tt>to_json</tt> on the object:
-</p>
-<pre>
- set :json_encoder, :to_json
-</pre>
-<p>
-Actually, it can call any method:
-</p>
-<pre>
- set :json_encoder, :my_fancy_json_method
-</pre>
+encoder:</p>
+
+<pre>require 'whatever'
+set :json_encoder, Whatever</pre>
+
+<p>To force <tt>json</tt> to simply call <tt>to_json</tt> on the object:</p>
+
+<pre>set :json_encoder, :to_json</pre>
+
+<p>Actually, it can call any method:</p>
+
+<pre>set :json_encoder, :my_fancy_json_method</pre>
+
<h3>Content-Type</h3>
-<p>
-It will automatically set the content type to
-&#8220;application/json&#8221;. As usual, you can easily change that, with
-the <tt>:json_content_type</tt> setting:
-</p>
-<pre>
- set :json_content_type, :js
-</pre>
+
+<p>It will automatically set the content type to "application/json". As
+usual, you can easily change that, with the <tt>:json_content_type</tt>
+setting:</p>
+
+<pre>set :json_content_type, :js</pre>
+
<h3>Overriding the Encoder and the Content-Type</h3>
-<p>
-The <tt>json</tt> helper will also take two options <tt>:encoder</tt> and
+
+<p>The <tt>json</tt> helper will also take two options <tt>:encoder</tt> and
<tt>:content_type</tt>. The values of this options are the same as the
<tt>:json_encoder</tt> and <tt>:json_content_type</tt> settings,
-respectively. You can also pass those to the json method:
-</p>
-<pre>
- get '/' do
- json({:foo =&gt; 'bar'}, :encoder =&gt; :to_json, :content_type =&gt; :js)
- end
-</pre>
+respectively. You can also pass those to the json method:</p>
+
+<pre>get '/' do
+ json({:foo =&gt; 'bar'}, :encoder =&gt; :to_json, :content_type =&gt; :js)
+end</pre>
View
97 _includes/sinatra-link-header.html
@@ -1,57 +1,50 @@
+
<h1>Sinatra::LinkHeader</h1>
-<p>
-<tt>Sinatra::LinkHeader</tt> adds a set of helper methods to generate link
-HTML tags and their corresponding Link HTTP headers.
-</p>
+
+<p><tt>Sinatra::LinkHeader</tt> adds a set of helper methods to generate link
+HTML tags and their corresponding Link HTTP headers.</p>
+
<h2>Usage</h2>
-<p>
-Once you had set up the helpers in your application (see below), you will
+
+<p>Once you had set up the helpers in your application (see below), you will
be able to call the following methods from inside your route handlers,
-filters and templates:
-</p>
-<table>
-<tr><td valign="top"><tt>prefetch</tt></td><td><p>
-Sets the Link HTTP headers and returns HTML tags to prefetch the given
-resources.
-</p>
-</td></tr>
-<tr><td valign="top"><tt>stylesheet</tt></td><td><p>
-Sets the Link HTTP headers and returns HTML tags to use the given
-stylesheets.
-</p>
-</td></tr>
-<tr><td valign="top"><tt>link</tt></td><td><p>
-Sets the Link HTTP headers and returns the corresponding HTML tags for the
-given resources.
-</p>
-</td></tr>
-<tr><td valign="top"><tt>link_headers</tt></td><td><p>
-Returns the corresponding HTML tags for the current Link HTTP headers.
-</p>
-</td></tr>
-</table>
+filters and templates:</p>
+<table class="rdoc-list"><tr><td class="rdoc-term"><p><tt>prefetch</tt></p></td>
+<td>
+<p>Sets the Link HTTP headers and returns HTML tags to prefetch the given
+resources.</p>
+</td></tr><tr><td class="rdoc-term"><p><tt>stylesheet</tt></p></td>
+<td>
+<p>Sets the Link HTTP headers and returns HTML tags to use the given
+stylesheets.</p>
+</td></tr><tr><td class="rdoc-term"><p><tt>link</tt></p></td>
+<td>
+<p>Sets the Link HTTP headers and returns the corresponding HTML tags for the
+given resources.</p>
+</td></tr><tr><td class="rdoc-term"><p><tt>link_headers</tt></p></td>
+<td>
+<p>Returns the corresponding HTML tags for the current Link HTTP headers.</p>
+</td></tr></table>
+
<h3>Classic Application</h3>
-<p>
-In a classic application simply require the helpers, and start using them:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/link_header&quot;
-
- # The rest of your classic application code goes here...
-</pre>
+
+<p>In a classic application simply require the helpers, and start using them:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/link_header&quot;
+
+# The rest of your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-In a modular application you need to require the helpers, and then tell the
-application you will use them:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/link_header&quot;
-
- class MyApp &lt; Sinatra::Base
- helpers Sinatra::LinkHeader
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>In a modular application you need to require the helpers, and then tell the
+application you will use them:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/link_header&quot;
+
+class MyApp &lt; Sinatra::Base
+ helpers Sinatra::LinkHeader
+
+ # The rest of your modular application code goes here...
+end</pre>
View
95 _includes/sinatra-multi-route.html
@@ -1,55 +1,48 @@
+
<h1>Sinatra::MultiRoute</h1>
-<p>
-Create multiple routes with one statement.
-</p>
+
+<p>Create multiple routes with one statement.</p>
+
<h2>Usage</h2>
-<p>
-Use this extension to create a handler for multiple routes:
-</p>
-<pre>
- get '/foo', '/bar' do
- # ...
- end
-</pre>
-<p>
-Or for multiple verbs:
-</p>
-<pre>
- route :get, :post, '/' do
- # ...
- end
-</pre>
-<p>
-Or even for custom verbs:
-</p>
-<pre>
- route 'LIST', '/' do
- # ...
- end
-</pre>
+
+<p>Use this extension to create a handler for multiple routes:</p>
+
+<pre>get '/foo', '/bar' do
+ # ...
+end</pre>
+
+<p>Or for multiple verbs:</p>
+
+<pre>route :get, :post, '/' do
+ # ...
+end</pre>
+
+<p>Or even for custom verbs:</p>
+
+<pre>route 'LIST', '/' do
+ # ...
+end</pre>
+
<h3>Classic Application</h3>
-<p>
-To use the extension in a classic application all you need to do is require
-it:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/multi_route&quot;
-
- # Your classic application code goes here...
-</pre>
+
+<p>To use the extension in a classic application all you need to do is require
+it:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/multi_route&quot;
+
+# Your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-To use the extension in a modular application you need to require it, and
-then, tell the application you will use it:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/multi_route&quot;
-
- class MyApp &lt; Sinatra::Base
- register Sinatra::MultiRoute
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>To use the extension in a modular application you need to require it, and
+then, tell the application you will use it:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/multi_route&quot;
+
+class MyApp &lt; Sinatra::Base
+ register Sinatra::MultiRoute
+
+ # The rest of your modular application code goes here...
+end</pre>
View
208 _includes/sinatra-namespace.html
@@ -1,121 +1,109 @@
+
<h1>Sinatra::Namespace</h1>
-<p>
-<tt>Sinatra::Namespace</tt> is an extension that adds namespaces to an
+
+<p><tt>Sinatra::Namespace</tt> is an extension that adds namespaces to an
application. This namespaces will allow you to share a path prefix for the
routes within the namespace, and define filters, conditions and error
handlers exclusively for them. Besides that, you can also register helpers
-and extensions that will be used only within the namespace.
-</p>
+and extensions that will be used only within the namespace.</p>
+
<h2>Usage</h2>
-<p>
-Once you have loaded the extension (see below), you use the
-<tt>namespace</tt> method to define namespaces in your application.
-</p>
-<p>
-You can define a namespace by a path prefix:
-</p>
-<pre>
- namespace '/blog' do
- get { haml :blog }
- get '/:entry_permalink' do
- @entry = Entry.find_by_permalink!(params[:entry_permalink])
- haml :entry
- end
-
- # More blog routes...
- end
-</pre>
-<p>
-by a condition:
-</p>
-<pre>
- namespace :host_name =&gt; 'localhost' do
- get('/admin/dashboard') { haml :dashboard }
- get('/admin/login') { haml :login }
-
- # More admin routes...
- end
-</pre>
-<p>
-or both:
-</p>
-<pre>
- namespace '/admin', :host_name =&gt; 'localhost' do
- get('/dashboard') { haml :dashboard }
- get('/login') { haml :login }
- post('/login') { login_user }
-
- # More admin routes...
- end
-</pre>
-<p>
-When you define a filter or an error handler, or register an extension or a
+
+<p>Once you have loaded the extension (see below), you use the
+<tt>namespace</tt> method to define namespaces in your application.</p>
+
+<p>You can define a namespace by a path prefix:</p>
+
+<pre>namespace '/blog' do
+ get { haml :blog }
+ get '/:entry_permalink' do
+ @entry = Entry.find_by_permalink!(params[:entry_permalink])
+ haml :entry
+ end
+
+ # More blog routes...
+end</pre>
+
+<p>by a condition:</p>
+
+<pre>namespace :host_name =&gt; 'localhost' do
+ get('/admin/dashboard') { haml :dashboard }
+ get('/admin/login') { haml :login }
+
+ # More admin routes...
+end</pre>
+
+<p>or both:</p>
+
+<pre>namespace '/admin', :host_name =&gt; 'localhost' do
+ get('/dashboard') { haml :dashboard }
+ get('/login') { haml :login }
+ post('/login') { login_user }
+
+ # More admin routes...
+end</pre>
+
+<p>When you define a filter or an error handler, or register an extension or a
set of helpers within a namespace, they only affect the routes defined in
it. For instance, lets define a before filter to prevent the access of
-unauthorized users to the admin section of the application:
-</p>
-<pre>
- namespace '/admin' do
- helpers AdminHelpers
- before { authenticate unless request.path_info == '/admin/login' }
-
- get '/dashboard' do
- # Only authenticated users can access here...
- haml :dashboard
- end
-
- # More admin routes...
- end
+unauthorized users to the admin section of the application:</p>
- get '/' do
- # Any user can access here...
- haml :index
- end
-</pre>
-<p>
-Well, they actually also affect the nested namespaces:
-</p>
-<pre>
- namespace '/admin' do
- helpers AdminHelpers
- before { authenticate unless request.path_info == '/admin/login' }
-
- namespace '/users' do
- get do
- # Only authenticated users can access here...
- @users = User.all
- haml :users
- end
-
- # More user admin routes...
- end
-
- # More admin routes...
+<pre>namespace '/admin' do
+ helpers AdminHelpers
+ before { authenticate unless request.path_info == '/admin/login' }
+
+ get '/dashboard' do
+ # Only authenticated users can access here...
+ haml :dashboard
+ end
+
+ # More admin routes...
+end
+
+get '/' do
+ # Any user can access here...
+ haml :index
+end</pre>
+
+<p>Well, they actually also affect the nested namespaces:</p>
+
+<pre>namespace '/admin' do
+ helpers AdminHelpers
+ before { authenticate unless request.path_info == '/admin/login' }
+
+ namespace '/users' do
+ get do
+ # Only authenticated users can access here...
+ @users = User.all
+ haml :users
end
-</pre>
+
+ # More user admin routes...
+ end
+
+ # More admin routes...
+end</pre>
+
<h3>Classic Application Setup</h3>
-<p>
-To be able to use namespaces in a classic application all you need to do is
-require the extension:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/namespace&quot;
-
- # The rest of your classic application code goes here...
-</pre>
+
+<p>To be able to use namespaces in a classic application all you need to do is
+require the extension:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/namespace&quot;
+
+# The rest of your classic application code goes here...</pre>
+
<h3>Modular Application Setup</h3>
-<p>
-To be able to use namespaces in a modular application all you need to do is
-require the extension, and then, register it:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/namespace&quot;
-
- class MyApp &lt; Sinatra::Base
- register Sinatra::Namespace
-
- # The rest of your modular application code goes here...
- end
-</pre>
+
+<p>To be able to use namespaces in a modular application all you need to do is
+require the extension, and then, register it:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/namespace&quot;
+
+class MyApp &lt; Sinatra::Base
+ register Sinatra::Namespace
+
+ # The rest of your modular application code goes here...
+end</pre>
View
117 _includes/sinatra-reloader.html
@@ -1,73 +1,70 @@
+
<h1>Sinatra::Reloader</h1>
-<p>
-Extension to reload modified files. Useful during development, since it
+
+<p>Extension to reload modified files. Useful during development, since it
will automatically require files defining routes, filters, error handlers
and inline templates, with every incoming request, but only if they have
-been updated.
-</p>
+been updated.</p>
+
<h2>Usage</h2>
+
<h3>Classic Application</h3>
-<p>
-To enable the realoader in a classic application all you need to do is
-require it:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/reloader&quot; if development?
-
- # Your classic application code goes here...
-</pre>
+
+<p>To enable the realoader in a classic application all you need to do is
+require it:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/reloader&quot; if development?
+
+# Your classic application code goes here...</pre>
+
<h3>Modular Application</h3>
-<p>
-To enable the realoader in a modular application all you need to do is
-require it, and then, register it:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/reloader&quot;
-
- class MyApp &lt; Sinatra::Base
- configure :development do
- register Sinatra::Reloader
- end
-
- # Your modular application code goes here...
- end
-</pre>
+
+<p>To enable the realoader in a modular application all you need to do is
+require it, and then, register it:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/reloader&quot;
+
+class MyApp &lt; Sinatra::Base
+ configure :development do
+ register Sinatra::Reloader
+ end
+
+ # Your modular application code goes here...
+end</pre>
+
<h2>Changing the Reloading Policy</h2>
-<p>
-You can refine the reloading policy with <tt>also_reload</tt> and
+
+<p>You can refine the reloading policy with <tt>also_reload</tt> and
<tt>dont_reload</tt>, to customize which files should, and should not, be
-reloaded, respectively.
-</p>
+reloaded, respectively.</p>
+
<h3>Classic Application</h3>
-<p>
-Simply call the methods:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/reloader&quot; if development?
+<p>Simply call the methods:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/reloader&quot; if development?
+
+also_reload '/path/to/some/file'
+dont_reload '/path/to/other/file'
+
+# Your classic application code goes here...</pre>
+
+<h3>Modular Application</h3>
+
+<p>Call the methods inside the <tt>configure</tt> block:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/reloader&quot;
+
+class MyApp &lt; Sinatra::Base
+ configure :development do
+ register Sinatra::Reloader
also_reload '/path/to/some/file'
dont_reload '/path/to/other/file'
+ end
- # Your classic application code goes here...
-</pre>
-<h3>Modular Application</h3>
-<p>
-Call the methods inside the <tt>configure</tt> block:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/reloader&quot;
-
- class MyApp &lt; Sinatra::Base
- configure :development do
- register Sinatra::Reloader
- also_reload '/path/to/some/file'
- dont_reload '/path/to/other/file'
- end
-
- # Your modular application code goes here...
- end
-</pre>
+ # Your modular application code goes here...
+end</pre>
View
164 _includes/sinatra-respond-with.html
@@ -1,104 +1,88 @@
+
<h1>Sinatra::RespondWith</h1>
-<p>
-This extensions lets Sinatra automatically choose what template to render
-or action to perform depending on the request&#8217;s Accept header.
-</p>
-<p>
-Example:
-</p>
-<pre>
- # Without Sinatra::RespondWith
- get '/' do
- data = { :name =&gt; 'example' }
- request.accept.each do |type|
- case type
- when 'text/html'
- halt haml(:index, :locals =&gt; data)
- when 'application/json'
- halt data.to_json
- when 'application/atom+xml'
- halt nokogiri(:'index.atom', :locals =&gt; data)
- when 'application/xml', 'text/xml'
- halt nokogiri(:'index.xml', :locals =&gt; data)
- when 'text/plain'
- halt 'just an example'
- end
+
+<p>This extensions lets Sinatra automatically choose what template to render
+or action to perform depending on the request's Accept header.</p>
+
+<p>Example:</p>
+
+<pre># Without Sinatra::RespondWith
+get '/' do
+ data = { :name =&gt; 'example' }
+ request.accept.each do |type|
+ case type
+ when 'text/html'
+ halt haml(:index, :locals =&gt; data)
+ when 'text/json'
+ halt data.to_json
+ when 'application/atom+xml'
+ halt nokogiri(:'index.atom', :locals =&gt; data)
+ when 'application/xml', 'text/xml'
+ halt nokogiri(:'index.xml', :locals =&gt; data)
+ when 'text/plain'
+ halt 'just an example'
end
- error 406
end
+ error 406
+end
- # With Sinatra::RespondWith
- get '/' do
- respond_with :index, :name =&gt; 'example' do |f|
- f.txt { 'just an example' }
- end
+# With Sinatra::RespondWith
+get '/' do
+ respond_with :index, :name =&gt; 'example' do |f|
+ f.txt { 'just an example' }
end
-</pre>
-<p>
-Both helper methods <tt>respond_to</tt> and <tt>respond_with</tt> let you
+end</pre>
+
+<p>Both helper methods <tt>respond_to</tt> and <tt>respond_with</tt> let you
define custom handlers like the one above for <tt>text/plain</tt>.
<tt>respond_with</tt> additionally takes a template name and/or an object
-to offer the following default behavior:
-</p>
-<ul>
-<li><p>
-If a template name is given, search for a template called
+to offer the following default behavior:</p>
+<ul><li>
+<p>If a template name is given, search for a template called
<tt>name.format.engine</tt> (<tt>index.xml.nokogiri</tt> in the above
-example).
-</p>
-</li>
-<li><p>
-If a template name is given, search for a templated called
+example).</p>
+</li><li>
+<p>If a template name is given, search for a templated called
<tt>name.engine</tt> for engines known to result in the requested format
-(<tt>index.haml</tt>).
-</p>
-</li>
-<li><p>
-If a file extension associated with the mime type is known to Sinatra, and
+(<tt>index.haml</tt>).</p>
+</li><li>
+<p>If a file extension associated with the mime type is known to Sinatra, and
the object responds to <tt>to_extension</tt>, call that method and use the
-result (<tt>data.to_json</tt>).
-</p>
-</li>
-</ul>
+result (<tt>data.to_json</tt>).</p>
+</li></ul>
+
<h2>Security</h2>
-<p>
-Since methods are triggered based on client input, this can lead to
-security issues (but not as severe as those might appear in the first
+
+<p>Since methods are triggered based on client input, this can lead to
+security issues (but not as seviere as those might apear in the first
place: keep in mind that only known file extensions are used). You
-therefore should limit the possible formats you serve.
-</p>
-<p>
-This is possible with the <tt>provides</tt> condition:
-</p>
-<pre>
- get '/', :provides =&gt; [:html, :json, :xml, :atom] do
- respond_with :index, :name =&gt; 'example'
- end
-</pre>
-<p>
-However, since you have to set <tt>provides</tt> for every route, this
-extension adds a app global (class method) `respond_to`, that let&#8217;s
-you define content types for all routes:
-</p>
-<pre>
- respond_to :html, :json, :xml, :atom
- get('/a') { respond_with :index, :name =&gt; 'a' }
- get('/b') { respond_with :index, :name =&gt; 'b' }
-</pre>
+therefore should limit the possible formats you serve.</p>
+
+<p>This is possible with the <tt>provides</tt> condition:</p>
+
+<pre>get '/', :provides =&gt; [:html, :json, :xml, :atom] do
+ respond_with :index, :name =&gt; 'example'
+end</pre>
+
+<p>However, since you have to set <tt>provides</tt> for every route, this
+extension adds a app global (class method) `respond_to`, that let's you
+define content types for all routes:</p>
+
+<pre>respond_to :html, :json, :xml, :atom
+get('/a') { respond_with :index, :name =&gt; 'a' }
+get('/b') { respond_with :index, :name =&gt; 'b' }</pre>
+
<h2>Custom Types</h2>
-<p>
-Use the <tt>on</tt> method for defining actions for custom types:
-</p>
-<pre>
- get '/' do
- respond_to do |f|
- f.xml { nokogiri :index }
- f.on('application/custom') { custom_action }
- f.on('text/*') { data.to_s }
- f.on('*/*') { &quot;matches everything&quot; }
- end
+
+<p>Use the <tt>on</tt> method for defining actions for custom types:</p>
+
+<pre>get '/' do
+ respond_to do |f|
+ f.xml { nokogiri :index }
+ f.on('application/custom') { custom_action }
+ f.on('text/*') { data.to_s }
+ f.on('*/*') { &quot;matches everything&quot; }
end
-</pre>
-<p>
-Definition order does not matter.
-</p>
+end</pre>
+
+<p>Definition order does not matter.</p>
View
154 _includes/sinatra-streaming.html
@@ -1,98 +1,90 @@
+
<h1>Sinatra::Streaming</h1>
-<p>
-Sinatra 1.3 introduced the <tt>stream</tt> helper. This addon improves the
+
+<p>Sinatra 1.3 introduced the <tt>stream</tt> helper. This addon improves the
streaming API by making the stream object immitate an IO object, turing it
into a real Deferrable and making the body play nicer with middleware
-unaware of streaming.
-</p>
+unaware of streaming.</p>
+
<h2>IO-like behavior</h2>
-<p>
-This is useful when passing the stream object to a library expecting an IO
-or StringIO object.
-</p>
-<pre>
- get '/' do
- stream do |out|
- out.puts &quot;Hello World!&quot;, &quot;How are you?&quot;
- out.write &quot;Written #{out.pos} bytes so far!\n&quot;
- out.putc(65) unless out.closed?
- out.flush
- end
+
+<p>This is useful when passing the stream object to a library expecting an IO
+or StringIO object.</p>
+
+<pre>get '/' do
+ stream do |out|
+ out.puts &quot;Hello World!&quot;, &quot;How are you?&quot;
+ out.write &quot;Written #{out.pos} bytes so far!\n&quot;
+ out.putc(65) unless out.closed?
+ out.flush
end
-</pre>
+end</pre>
+
<h2>Proper Deferrable</h2>
-<p>
-Handy when using EventMachine.
-</p>
-<pre>
- list = []
-
- get '/' do
- stream(:keep_open) do |out|
- list &lt;&lt; out
- out.callback { list.delete out }
- out.errback do
- logger.warn &quot;lost connection&quot;
- list.delete out
- end
+
+<p>Handy when using EventMachine.</p>
+
+<pre>list = []
+
+get '/' do
+ stream(:keep_open) do |out|
+ list &lt;&lt; out
+ out.callback { list.delete out }
+ out.errback do
+ logger.warn &quot;lost connection&quot;
+ list.delete out
end
end
-</pre>
+end</pre>
+
<h2>Better Middleware Handling</h2>
-<p>
-Blocks passed to #map! or #map will actually be applied while streaming (as
+
+<p>Blocks passed to #map! or #map will actually be applied while streaming (as
you might suspect, #map! applies modifications to the current body, #map
-creates a new one):
-</p>
-<pre>
- class StupidMiddleware
- def initialize(app) @app = app end
-
- def call(env)
- status, headers, body = @app.call(env)
- body.map! { |e| e.upcase }
- [status, headers, body]
- end
- end
+creates a new one):</p>
- use StupidMiddleware
+<pre>class StupidMiddleware
+ def initialize(app) @app = app end
- get '/' do
- stream do |out|
- out.puts &quot;still&quot;
- sleep 1
- out.puts &quot;streaming&quot;
- end
- end
-</pre>
-<p>
-Even works if #each is used to generate an Enumerator:
-</p>
-<pre>
def call(env)
status, headers, body = @app.call(env)
- body = body.each.map { |s| s.upcase }
+ body.map! { |e| e.upcase }
[status, headers, body]
end
-</pre>
-<p>
-Note that both examples violate the Rack specification.
-</p>
+end
+
+use StupidMiddleware
+
+get '/' do
+ stream do |out|
+ out.puts &quot;still&quot;
+ sleep 1
+ out.puts &quot;streaming&quot;
+ end
+end</pre>
+
+<p>Even works if #each is used to generate an Enumerator:</p>
+
+<pre>def call(env)
+ status, headers, body = @app.call(env)
+ body = body.each.map { |s| s.upcase }
+ [status, headers, body]
+end</pre>
+
+<p>Note that both examples violate the Rack specification.</p>
+
<h2>Setup</h2>
-<p>
-In a classic application:
-</p>
-<pre>
- require &quot;sinatra&quot;
- require &quot;sinatra/streaming&quot;
-</pre>
-<p>
-In a modular application:
-</p>
-<pre>
- require &quot;sinatra/base&quot;
- require &quot;sinatra/streaming&quot;
-
- class MyApp &lt; Sinatra::Base
- helpers Sinatra::Streaming
- end</pre>
+
+<p>In a classic application:</p>
+
+<pre>require &quot;sinatra&quot;
+require &quot;sinatra/streaming&quot;</pre>
+
+<p>In a modular application:</p>
+
+<pre>require &quot;sinatra/base&quot;
+require &quot;sinatra/streaming&quot;
+
+class MyApp &lt; Sinatra::Base
+ helpers Sinatra::Streaming
+end</pre>
Please sign in to comment.
Something went wrong with that request. Please try again.