Skip to content

Clean up docs inline with book and contrib project #198

Closed
wants to merge 8 commits into from
View
425 README.rdoc
@@ -216,394 +216,6 @@ case, use <tt>:'subdir/template'</tt>). You must use a symbol because
otherwise rendering methods will render any strings passed to them
directly.
-=== Haml Templates
-
-The <tt>haml</tt> gem/library is required to render HAML templates:
-
- # You'll need to require haml in your app
- require 'haml'
-
- get '/' do
- haml :index
- end
-
-Renders <tt>./views/index.haml</tt>.
-
-{Haml's options}[http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options]
-can be set globally through Sinatra's configurations,
-see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
-and overridden on an individual basis.
-
- set :haml, :format => :html5 # default Haml format is :xhtml
-
- get '/' do
- haml :index, :format => :html4 # overridden
- end
-
-
-=== Erb Templates
-
- # You'll need to require erb in your app
- require 'erb'
-
- get '/' do
- erb :index
- end
-
-Renders <tt>./views/index.erb</tt>.
-
-=== Erubis Templates
-
-The <tt>erubis</tt> gem/library is required to render Erubis templates:
-
- # You'll need to require erubis in your app
- require 'erubis'
-
- get '/' do
- erubis :index
- end
-
-Renders <tt>./views/index.erubis</tt>.
-
-It is also possible to replace Erb with Erubis:
-
- require 'erubis'
- Tilt.register :erb, Tilt[:erubis]
-
- get '/' do
- erb :index
- end
-
-Renders <tt>./views/index.erb</tt> with Erubis.
-
-=== Builder Templates
-
-The <tt>builder</tt> gem/library is required to render builder templates:
-
- # You'll need to require builder in your app
- require 'builder'
-
- get '/' do
- builder :index
- end
-
-Renders <tt>./views/index.builder</tt>.
-
-=== Nokogiri Templates
-
-The <tt>nokogiri</tt> gem/library is required to render nokogiri templates:
-
- # You'll need to require nokogiri in your app
- require 'nokogiri'
-
- get '/' do
- nokogiri :index
- end
-
-Renders <tt>./views/index.nokogiri</tt>.
-
-=== Sass Templates
-
-The <tt>haml</tt> or <tt>sass</tt> gem/library is required to render Sass templates:
-
- # You'll need to require haml or sass in your app
- require 'sass'
-
- get '/stylesheet.css' do
- sass :stylesheet
- end
-
-Renders <tt>./views/stylesheet.sass</tt>.
-
-{Sass's options}[http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options]
-can be set globally through Sinatra's configurations,
-see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
-and overridden on an individual basis.
-
- set :sass, :style => :compact # default Sass style is :nested
-
- get '/stylesheet.css' do
- sass :stylesheet, :style => :expanded # overridden
- end
-
-=== Scss Templates
-
-The <tt>haml</tt> or <tt>sass</tt> gem/library is required to render Scss templates:
-
- # You'll need to require haml or sass in your app
- require 'sass'
-
- get '/stylesheet.css' do
- scss :stylesheet
- end
-
-Renders <tt>./views/stylesheet.scss</tt>.
-
-{Scss's options}[http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options]
-can be set globally through Sinatra's configurations,
-see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
-and overridden on an individual basis.
-
- set :scss, :style => :compact # default Scss style is :nested
-
- get '/stylesheet.css' do
- scss :stylesheet, :style => :expanded # overridden
- end
-
-=== Less Templates
-
-The <tt>less</tt> gem/library is required to render Less templates:
-
- # You'll need to require less in your app
- require 'less'
-
- get '/stylesheet.css' do
- less :stylesheet
- end
-
-Renders <tt>./views/stylesheet.less</tt>.
-
-=== Liquid Templates
-
-The <tt>liquid</tt> gem/library is required to render Liquid templates:
-
- # You'll need to require liquid in your app
- require 'liquid'
-
- get '/' do
- liquid :index
- end
-
-Renders <tt>./views/index.liquid</tt>.
-
-Since you cannot call Ruby methods (except for +yield+) from a Liquid
-template, you almost always want to pass locals to it:
-
- liquid :index, :locals => { :key => 'value' }
-
-=== Markdown Templates
-
-The <tt>rdiscount</tt> gem/library is required to render Markdown templates:
-
- # You'll need to require rdiscount in your app
- require "rdiscount"
-
- get '/' do
- markdown :index
- end
-
-Renders <tt>./views/index.markdown</tt> (+md+ and +mkd+ are also valid file
-extensions).
-
-It is not possible to call methods from markdown, nor to pass locals to it.
-You therefore will usually use it in combination with another rendering
-engine:
-
- erb :overview, :locals => { :text => markdown(:introduction) }
-
-Note that you may also call the +markdown+ method from within other templates:
-
- %h1 Hello From Haml!
- %p= markdown(:greetings)
-
-Since you cannot call Ruby from Markdown, you cannot use layouts written in
-Markdown. However, it is possible to use another rendering engine for the
-template than for the layout by passing the <tt>:layout_engine</tt> option:
-
- get '/' do
- markdown :index, :layout_engine => :erb
- end
-
-This will render <tt>./views/index.md</tt> with <tt>./views/layout.erb</tt> as
-layout.
-
-Remember that you can set such rendering options globally:
-
- set :markdown, :layout_engine => :haml, :layout => :post
-
- get '/' do
- markdown :index
- end
-
-This will render <tt>./views/index.md</tt> (and any other Markdown template)
-with <tt>./views/post.haml</tt> as layout.
-
-It is also possible to parse Markdown with BlueCloth rather than RDiscount:
-
- require 'bluecloth'
-
- Tilt.register 'markdown', BlueClothTemplate
- Tilt.register 'mkd', BlueClothTemplate
- Tilt.register 'md', BlueClothTemplate
-
- get '/' do
- markdown :index
- end
-
-Renders <tt>./views/index.md</tt> with BlueCloth.
-
-=== Textile Templates
-
-The <tt>RedCloth</tt> gem/library is required to render Textile templates:
-
- # You'll need to require redcloth in your app
- require "redcloth"
-
- get '/' do
- textile :index
- end
-
-Renders <tt>./views/index.textile</tt>.
-
-It is not possible to call methods from textile, nor to pass locals to it. You
-therefore will usually use it in combination with another rendering engine:
-
- erb :overview, :locals => { :text => textile(:introduction) }
-
-Note that you may also call the +textile+ method from within other templates:
-
- %h1 Hello From Haml!
- %p= textile(:greetings)
-
-Since you cannot call Ruby from Textile, you cannot use layouts written in
-Textile. However, it is possible to use another rendering engine for the
-template than for the layout by passing the <tt>:layout_engine</tt> option:
-
- get '/' do
- textile :index, :layout_engine => :erb
- end
-
-This will render <tt>./views/index.textile</tt> with
-<tt>./views/layout.erb</tt> as layout.
-
-Remember that you can set such rendering options globally:
-
- set :textile, :layout_engine => :haml, :layout => :post
-
- get '/' do
- textile :index
- end
-
-This will render <tt>./views/index.textile</tt> (and any other Textile
-template) with <tt>./views/post.haml</tt> as layout.
-
-=== RDoc Templates
-
-The <tt>rdoc</tt> gem/library is required to render RDoc templates:
-
- # You'll need to require rdoc/markup/to_html in your app
- require "rdoc/markup/to_html"
-
- get '/' do
- rdoc :index
- end
-
-Renders <tt>./views/index.rdoc</tt>.
-
-It is not possible to call methods from rdoc, nor to pass locals to it. You
-therefore will usually use it in combination with another rendering engine:
-
- erb :overview, :locals => { :text => rdoc(:introduction) }
-
-Note that you may also call the +rdoc+ method from within other templates:
-
- %h1 Hello From Haml!
- %p= rdoc(:greetings)
-
-Since you cannot call Ruby from RDoc, you cannot use layouts written in
-RDoc. However, it is possible to use another rendering engine for the
-template than for the layout by passing the <tt>:layout_engine</tt> option:
-
- get '/' do
- rdoc :index, :layout_engine => :erb
- end
-
-This will render <tt>./views/index.rdoc</tt> with <tt>./views/layout.erb</tt> as
-layout.
-
-Remember that you can set such rendering options globally:
-
- set :rdoc, :layout_engine => :haml, :layout => :post
-
- get '/' do
- rdoc :index
- end
-
-This will render <tt>./views/index.rdoc</tt> (and any other RDoc template)
-with <tt>./views/post.haml</tt> as layout.
-
-=== Radius Templates
-
-The <tt>radius</tt> gem/library is required to render Radius templates:
-
- # You'll need to require radius in your app
- require 'radius'
-
- get '/' do
- radius :index
- end
-
-Renders <tt>./views/index.radius</tt>.
-
-Since you cannot call Ruby methods (except for +yield+) from a Radius
-template, you almost always want to pass locals to it:
-
- radius :index, :locals => { :key => 'value' }
-
-=== Markaby Templates
-
-The <tt>markaby</tt> gem/library is required to render Markaby templates:
-
- # You'll need to require markaby in your app
- require 'markaby'
-
- get '/' do
- markaby :index
- end
-
-Renders <tt>./views/index.mab</tt>.
-
-You may also use inline Markaby:
-
- get '/' do
- markaby { h1 "Welcome!" }
- end
-
-=== Slim Templates
-
-The <tt>slim</tt> gem/library is required to render Slim templates:
-
- # You'll need to require slim in your app
- require 'slim'
-
- get '/' do
- slim :index
- end
-
-Renders <tt>./views/index.slim</tt>.
-
-=== CoffeeScript Templates
-
-The <tt>coffee-script</tt> gem/library and at least <b>one</b> of the
-following options to execute JavaScript:
-
-* +node+ (from Node.js) in your path
-* you must be running on OSX
-* +therubyracer+ gem/library
-
-See http://github.com/josh/ruby-coffee-script for an updated list of options.
-
-Now you can render CoffeeScript templates:
-
- # You'll need to require coffee-script in your app
- require 'coffee-script'
-
- get '/application.js' do
- coffee :application
- end
-
-Renders <tt>./views/application.coffee</tt>.
-
=== Embedded Templates
get '/' do
@@ -704,6 +316,13 @@ First, register your engine with Tilt, then create a rendering method:
Renders <tt>./views/index.myat</tt>. See https://github.com/rtomayko/tilt to
learn more about Tilt.
+=== Template Cookbook Recipes
+
+There are a number of recipes included in the {Sinatra
+Book}[http://sinatra-book.gittr.com/#views] for templating, as well as
+{community contributed
+recipes}[https://github.com/sinatra/sinatra-book-contrib/tree/master/views].
+
== Filters
Before filters are evaluated before each request within the same
@@ -768,6 +387,12 @@ route handlers and templates:
bar(params[:name])
end
+=== Helper Cookbook Recipes
+
+There's a number of helper recipes in the {Sinatra
+Book}[http://sinatra-book.gittr.com/] as well as {community contributed
+recipes}[https://github.com/sinatra/sinatra-book-contrib/tree/master/helpers].
+
=== Using Sessions
A session is used to keep state during requests. If activated, you have one
@@ -1373,18 +998,21 @@ Sinatra makes building Rack middleware pipelines a cinch via a top-level
The semantics of +use+ are identical to those defined for the
Rack::Builder[http://rack.rubyforge.org/doc/classes/Rack/Builder.html] DSL
-(most frequently used from rackup files). For example, the +use+ method
-accepts multiple/variable args as well as blocks:
-
- use Rack::Auth::Basic do |username, password|
- username == 'admin' && password == 'secret'
- end
+(most frequently used from rackup files).
Rack is distributed with a variety of standard middleware for logging,
debugging, URL routing, authentication, and session handling. Sinatra uses
many of these components automatically based on configuration so you
typically don't have to +use+ them explicitly.
+=== Middleware Cookbook Recipes
+
+There are some excellent recipes in the {Sinatra
+Book}[http://sinatra-book.gittr.com/#middleware], as well as {community
+contributed
+recipes}[https://github.com/sinatra/sinatra-book-contrib/tree/master/middleware],
+for using middleware with Sinatra.
+
== Testing
Sinatra tests can be written using any Rack-based testing library
@@ -1421,6 +1049,13 @@ recommended:
NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
are deprecated as of the 0.9.2 release.
+=== Testing Cookbook Recipes
+
+You can find some excellent tutorials on testing in the {Sinatra
+Book}[http://sinatra-book.gittr.com/#testing], as well as {community
+contributed
+recipes}[https://github.com/sinatra/sinatra-book-contrib/tree/master/testing].
+
== Sinatra::Base - Middleware, Libraries, and Modular Apps
Defining your app at the top-level works well for micro-apps but has
@@ -1800,3 +1435,5 @@ If you install gems as root, the last step should be
* {Twitter}[http://twitter.com/sinatra]
* {Mailing List}[http://groups.google.com/group/sinatrarb/topics]
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
+* {Sinatra Book}[http://sinatra-book.gittr.com] Cookbook Tutorial
+* {Sinatra Book Contrib}[http://sinatra-book-contrib.com/] Community contributed recipes
Something went wrong with that request. Please try again.