Permalink
Browse files

Merge branch 'master' of github.com:sinatra/sinatra-contrib

  • Loading branch information...
2 parents f1f2c52 + d696150 commit a430748f9806faf1798b1d9b7bea4ca813cbd426 @rkh committed Mar 15, 2012
View
@@ -1,19 +1,20 @@
----
-rvm:
+---
+rvm:
- 1.8.7
- 1.9.2
- 1.9.3
-- rbx
-- rbx-2.0
+- rbx-18mode
+- rbx-19mode
- jruby
- ruby-head
-env:
+env:
- rack=1.3.0
- rack=master
- tilt=1.3.2
- tilt=master
- sinatra=master
-notifications:
- recipients:
+notifications:
+ recipients:
- k.haase@finn.de
- ohhgabriel@gmail.com
+ - inbox@trevorbramble.com
View
@@ -127,7 +127,7 @@ All extensions:
``` ruby
require 'sinatra/base'
-require 'sinatra/contrib'
+require 'sinatra/contrib/all'
class MyApp < Sinatra::Base
register Sinatra::Contrib
@@ -46,7 +46,7 @@ module Sinatra
# require "sinatra/content_for"
#
# class MyApp < Sinatra::Base
- # register Sinatra::ContentFor
+ # helpers Sinatra::ContentFor
#
# # The rest of your modular application code goes here...
# end
@@ -78,6 +78,20 @@ module ContentFor
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:
#
@@ -45,7 +45,7 @@ module Sinatra
# the application you will use them:
#
# require "sinatra/base"
- # require "sinatra/link_header"
+ # require "sinatra/cookies"
#
# class MyApp < Sinatra::Base
# helpers Sinatra::Cookies
@@ -210,6 +210,7 @@ def self.registered(klass)
end
end
end
+ klass.set(:inline_templates, klass.app_file) if klass == Sinatra::Application
end
# Reloads the modified files, adding, updating and removing the
@@ -231,6 +232,15 @@ def self.thread_safe?
# Contains the methods defined in Sinatra::Base that are overriden.
module BaseMethods
+ # Protects Sinatra::Base.run! from being called more than once.
+ def run!(*args)
+ if settings.reloader?
+ super unless running?
+ else
+ super
+ end
+ end
+
# Does everything Sinatra::Base#route does, but it also tells the
# +Watcher::List+ for the Sinatra application to watch the defined
# route.
@@ -91,7 +91,7 @@ module Sinatra
# require "sinatra/streaming"
#
# class MyApp < Sinatra::Base
- # helpers Streaming
+ # helpers Sinatra::Streaming
# end
module Streaming
def stream(*)
@@ -1,7 +1,7 @@
# Run `rake sinatra-contrib.gemspec` to update the gemspec.
Gem::Specification.new do |s|
s.name = "sinatra-contrib"
- s.version = "1.3.1"
+ s.version = "1.3.2"
s.description = "Collection of useful Sinatra extensions"
s.homepage = "http://github.com/sinatra/sinatra-contrib"
s.summary = s.description
@@ -0,0 +1,3 @@
+<% if content_for? :foo %>
+ <%= yield_content :foo %>
+<% end %>
@@ -0,0 +1,3 @@
+<% if content_for? :foo %>
+ <%= yield_content :foo %>
+<% end %>
@@ -0,0 +1,2 @@
+- if content_for? :foo
+ = yield_content :foo
@@ -0,0 +1,2 @@
+- if content_for? :foo
+ = yield_content :foo
@@ -138,6 +138,18 @@ def render(engine, template)
render(inner, :passes_values).should == "<i>1</i>2"
end
end
+
+ describe "with content_for? in Ruby" do
+ it 'renders block if key is set' do
+ content_for(:foo) { "foot" }
+ render(inner, :footer).should == "foot"
+ end
+
+ it 'does not render a block if different key' do
+ content_for(:different_key) { "foot" }
+ render(inner, :footer).should be_empty
+ end
+ end
engines.each do |outer|
describe "with yield_content in #{outer.capitalize}" do

0 comments on commit a430748

Please sign in to comment.