mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Merge branch 'master' of github.com:sinatra/sinatra-contrib
This commit is contained in:
commit
38553470df
2 changed files with 11 additions and 1 deletions
|
@ -77,6 +77,10 @@ module Sinatra
|
|||
# <script type="text/javascript" src="/foo.js"></script>
|
||||
# <% end %>
|
||||
#
|
||||
# You can also pass an immediate value instead of a block:
|
||||
#
|
||||
# <% content_for :title, "foo" %>
|
||||
#
|
||||
# You can call +content_for+ multiple times with the same key
|
||||
# (in the example +:head+), and when you render the blocks for
|
||||
# that key all of them will be rendered, in the same order you
|
||||
|
@ -84,7 +88,8 @@ module Sinatra
|
|||
#
|
||||
# Your blocks can also receive values, which are passed to them
|
||||
# by <tt>yield_content</tt>
|
||||
def content_for(key, &block)
|
||||
def content_for(key, value = nil, &block)
|
||||
block ||= proc { |*| value }
|
||||
content_blocks[key.to_sym] << capture_later(&block)
|
||||
end
|
||||
|
||||
|
|
|
@ -65,6 +65,11 @@ describe Sinatra::ContentFor do
|
|||
clear_content_for(:foo)
|
||||
yield_content(:foo).should be_empty
|
||||
end
|
||||
|
||||
it 'takes an immediate value instead of a block' do
|
||||
content_for(:foo, "foo")
|
||||
yield_content(:foo).should == "foo"
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: liquid radius markaby builder nokogiri
|
||||
|
|
Loading…
Reference in a new issue