prepare merge

This commit is contained in:
Konstantin Haase 2011-03-27 17:52:30 +02:00
parent c8e8f737ef
commit 9c82988a0e
6 changed files with 52 additions and 125 deletions

View File

@ -1,3 +0,0 @@
doc
dist
tmp

View File

@ -1,6 +1,4 @@
(The MIT License)
Copyright (c) 2008-2009 Nicolas Sanguinetti, entp.com
Copyright (c) 2008-2011 Nicolas Sanguinetti, entp.com, Konstantin Haase
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -1,49 +0,0 @@
= 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.
When using this with the Haml rendering engine, you should do the
following:
- content_for :some_key do
%chunk{ :of => "html" } ...
= yield_content :some_key
<b>Note</b> that with ERB <tt>yield_content</tt> is called <b>without</b>
an '=' block (<tt><%= %></tt>), but with Haml it uses <tt>= yield_content</tt>.
Using an '=' block in ERB will output the content twice for each block,
so if you have problems with that, make sure to check for this.
== 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.
== Credits
Code by foca[http://github.com/foca], inspired on the Ruby on Rails
helpers with the same name. Haml support by mattly[http://github.com/mattly].

View File

@ -1,33 +0,0 @@
require "rake/testtask"
begin
require "hanna/rdoctask"
rescue LoadError
require "rake/rdoctask"
end
begin
require "metric_fu"
rescue LoadError
end
begin
require "mg"
MG.new("sinatra-content-for.gemspec")
rescue LoadError
end
desc "Default: run all tests"
task :default => :test
desc "Run library tests"
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
end
Rake::RDocTask.new do |rd|
rd.main = "README"
rd.title = "Documentation for ContentFor"
rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
rd.rdoc_dir = "doc"
end

View File

@ -1,4 +1,52 @@
module Sinatra
##
# 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.
#
# When using this with the Haml rendering engine, you should do the
# following:
#
# - content_for :some_key do
# %chunk{ :of => "html" } ...
#
# = yield_content :some_key
#
# <b>Note</b> that with ERB <tt>yield_content</tt> is called <b>without</b>
# an '=' block (<tt><%= %></tt>), but with Haml it uses <tt>= yield_content</tt>.
#
# Using an '=' block in ERB will output the content twice for each block,
# so if you have problems with that, make sure to check for this.
#
# == 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.
#
# == Credits
#
# Code by foca[http://github.com/foca], inspired on the Ruby on Rails
# helpers with the same name. Haml support by mattly[http://github.com/mattly].
module ContentFor
# Capture a block of content to be rendered later. For example:
#
@ -49,9 +97,9 @@ module Sinatra
private
def content_blocks
@content_blocks ||= Hash.new {|h,k| h[k] = [] }
end
def content_blocks
@content_blocks ||= Hash.new {|h,k| h[k] = [] }
end
end
helpers ContentFor

View File

@ -1,34 +0,0 @@
Gem::Specification.new do |s|
s.name = "sinatra-content-for"
s.version = "0.2"
s.date = "2009-05-09"
s.description = "Small Sinatra extension to add a content_for helper similar to Rails'"
s.summary = "Small Sinatra extension to add a content_for helper similar to Rails'"
s.homepage = "http://sinatrarb.com"
s.authors = ["Nicolás Sanguinetti"]
s.email = "contacto@nicolassanguinetti.info"
s.require_paths = ["lib"]
s.rubyforge_project = "sinatra-ditties"
s.has_rdoc = true
s.rubygems_version = "1.3.1"
s.add_dependency "sinatra"
if s.respond_to?(:add_development_dependency)
s.add_development_dependency "contest"
s.add_development_dependency "sr-mg"
s.add_development_dependency "redgreen"
end
s.files = %w[
.gitignore
LICENSE
README.rdoc
sinatra-content-for.gemspec
lib/sinatra/content_for.rb
test/content_for_test.rb
]
end