Sha256: 6d2ea0c362bf0d3c9516d0b043fa2318097b80c4aada7abb6a86da9f84e7ffa5

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

= ContentFor

Small extension for the Sinatra[http://sinatrarb.com] web framework
that allows you to use the following helpers in your views:

    <% content_for :some_key do %>
      <chunk of="html">...</chunk>
    <% end %>
    
    <% 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.

== Usage

If you're writing "classic" style apps, then requring 
<tt>sinatra/content_for</tt> should be enough. If you're writing
"classy" apps, then you also need to call 
<tt>helpers Sinatra::ContentFor</tt> in your app definition.

== 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.

== Warning

This only works with ERB as a rendering mechanism. I haven't figured
how to make it work with Haml. If you find a way, contact me and I'll
include it.

== Credits

Code by foca[http://github.com/foca], inspired on the Ruby on Rails
helpers with the same name.

Version data entries

12 entries across 11 versions & 2 rubygems

Version Path
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.12.2 lib/middleman/vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.12.1 lib/middleman/vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.10.17 vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.10.16 vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.10.15 vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
middleman-0.10.14 vendor/gems/gems/sinatra-content-for-0.2/README.rdoc
sinatra-content-for-0.1 README.rdoc