Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:sinatra/sinatra-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed May 23, 2016
2 parents fef4722 + 166ff5d commit ef9bb80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/sinatra/content_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ module ContentFor
# <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
# captured them.
#
# 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

Expand Down
5 changes: 5 additions & 0 deletions spec/content_for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def render(engine, template)
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
Expand Down

0 comments on commit ef9bb80

Please sign in to comment.