lib/sinatra/content_for.rb in sinatra-contrib-1.3.1 vs lib/sinatra/content_for.rb in sinatra-contrib-1.3.2
- old
+ new
@@ -44,11 +44,11 @@
#
# require "sinatra/base"
# require "sinatra/content_for"
#
# class MyApp < Sinatra::Base
- # register Sinatra::ContentFor
+ # helpers Sinatra::ContentFor
#
# # The rest of your modular application code goes here...
# end
#
# == And How Is This Useful?
@@ -75,9 +75,23 @@
#
# Your blocks can also receive values, which are passed to them
# by <tt>yield_content</tt>
def content_for(key, &block)
content_blocks[key.to_sym] << capture_later(&block)
+ end
+
+ # Check if a block of content with the given key was defined. For
+ # example:
+ #
+ # <% content_for :head do %>
+ # <script type="text/javascript" src="/foo.js"></script>
+ # <% end %>
+ #
+ # <% if content_for? :head %>
+ # <span>content "head" was defined.</span>
+ # <% end %>
+ def content_for?(key)
+ content_blocks[key.to_sym].any?
end
# Render the captured blocks for a given key. For example:
#
# <head>