Permalink
Browse files

improve Sinatra::ContentFor docs

  • Loading branch information...
1 parent 6b3500e commit 0d2f1b46bb121bfddf0d2bc1e091c250424e37ad @gnandretta gnandretta committed Jul 6, 2011
Showing with 40 additions and 17 deletions.
  1. +40 −17 lib/sinatra/content_for.rb
View
@@ -2,40 +2,63 @@
require 'sinatra/capture'
module Sinatra
- ##
+
# = Sinatra::ContentFor
#
- # Small extension for the Sinatra[http://sinatrarb.com] web framework
- # that allows you to use the following helpers in your views:
+ # <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.
+ #
+ # The currently supported engines are: Erb, Erubis, Haml and Slim.
+ #
+ # == Usage
#
+ # You call +content_for+, generally from a view, to capture a block of markup
+ # giving it an identifier:
+ #
+ # # index.erb
# <% content_for :some_key do %>
# <chunk of="html">...</chunk>
# <% end %>
#
+ # Then, you call +yield_content+ with that identifier, generally from a
+ # layout, to render the captured block:
+ #
+ # # layout.erb
# <%= yield_content :some_key %>
#
- # This allows you to capture blocks inside views to be rendered later
- # in this request. For example, to populate different parts of your
- # layout from your view.
+ # === Classic Application
#
- # When using this with the Haml rendering engine, you should do the
- # following:
+ # To use the helpers in a classic application all you need to do is require
+ # them:
#
- # - content_for :some_key do
- # %chunk{ :of => "html" } ...
+ # require "sinatra"
+ # require "sinatra/content_for"
#
- # = yield_content :some_key
+ # # Your classic application code goes here...
#
- # Supported engines: Erb, Erubis, Haml and Slim.
+ # === Modular Application
#
- # == And how is this useful?
+ # To use the helpers in a modular application you need to require them, and
+ # then, tell the application you will use them:
+ #
+ # require "sinatra/base"
+ # require "sinatra/content_for"
+ #
+ # class MyApp < Sinatra::Base
+ # register Sinatra::ContentFor
+ #
+ # # The rest of your modular application code goes here...
+ # end
+ #
+ # == And How Is This Useful?
#
# 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><% yield_content :scripts_and_styles %></tt> on
- # your layout, inside the <head> tag, and each view can call
- # <tt>content_for</tt> setting the appropriate set of tags that should
- # be added to the layout.
+ # Then you can put <tt><% yield_content :scripts_and_styles %></tt> on your
+ # layout, inside the <head> tag, and each view can call <tt>content_for</tt>
+ # setting the appropriate set of tags that should be added to the layout.
+ #
module ContentFor
include Capture

0 comments on commit 0d2f1b4

Please sign in to comment.