From 117cc667884f97677def7faff84ad7e991ca1b47 Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Thu, 7 May 2009 02:58:50 -0300
Subject: [PATCH 0001/2904] Initial commit
---
sinatra-contrib/LICENSE | 22 +++++++
sinatra-contrib/README.rdoc | 41 ++++++++++++
sinatra-contrib/lib/sinatra/content_for.rb | 19 ++++++
sinatra-contrib/test/content_for_test.rb | 72 ++++++++++++++++++++++
4 files changed, 154 insertions(+)
create mode 100644 sinatra-contrib/LICENSE
create mode 100644 sinatra-contrib/README.rdoc
create mode 100644 sinatra-contrib/lib/sinatra/content_for.rb
create mode 100644 sinatra-contrib/test/content_for_test.rb
diff --git a/sinatra-contrib/LICENSE b/sinatra-contrib/LICENSE
new file mode 100644
index 0000000000..3eb6c2f498
--- /dev/null
+++ b/sinatra-contrib/LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2008-2009 Nicolas Sanguinetti, entp.com
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/sinatra-contrib/README.rdoc b/sinatra-contrib/README.rdoc
new file mode 100644
index 0000000000..12022a7b56
--- /dev/null
+++ b/sinatra-contrib/README.rdoc
@@ -0,0 +1,41 @@
+= 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 %>
+ ...
+ <% 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.
+
+== Usage
+
+If you're writing "classic" style apps, then requring
+sinatra/content_for should be enough. If you're writing
+"classy" apps, then you also need to call
+helpers Sinatra::ContentFor 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 <% yield_content :scripts_and_styles %> on
+your layout, inside the tag, and each view can call
+content_for setting the appropriate set of tags that should
+be added to the layout.
+
+== Warning
+
+This only works with ERB as a rendering mechanism. I haven't figured
+how to make it work with Haml. If you find a way, contact me and I'll
+include it.
+
+== Credits
+
+Code by foca[http://github.com/foca], inspired on the Ruby on Rails
+helpers with the same name.
diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb
new file mode 100644
index 0000000000..921e06eb46
--- /dev/null
+++ b/sinatra-contrib/lib/sinatra/content_for.rb
@@ -0,0 +1,19 @@
+module Sinatra
+ module ContentFor
+ def content_for(key, &block)
+ content_blocks[key.to_sym] << block
+ end
+
+ def yield_content(key)
+ content_blocks[key.to_sym].map {|content| content.call }.join("")
+ end
+
+ private
+
+ def content_blocks
+ @content_blocks ||= Hash.new {|h,k| h[k] = [] }
+ end
+ end
+
+ helpers ContentFor
+end
diff --git a/sinatra-contrib/test/content_for_test.rb b/sinatra-contrib/test/content_for_test.rb
new file mode 100644
index 0000000000..088129d6b2
--- /dev/null
+++ b/sinatra-contrib/test/content_for_test.rb
@@ -0,0 +1,72 @@
+ENV['RACK_ENV'] = 'test'
+
+begin
+ require 'rack'
+rescue LoadError
+ require 'rubygems'
+ require 'rack'
+end
+
+require 'contest'
+require 'sinatra/test'
+
+require File.dirname(__FILE__) + '/../lib/sinatra/content_for'
+
+Sinatra::Base.set :environment, :test
+
+module Sinatra
+ class Base
+ set :environment, :test
+ helpers ContentFor
+ end
+end
+
+class Test::Unit::TestCase
+ include Sinatra::Test
+
+ class << self
+ alias_method :it, :test
+ end
+
+ def mock_app(base=Sinatra::Base, &block)
+ @app = Sinatra.new(base, &block)
+ end
+end
+
+class ContentForTest < Test::Unit::TestCase
+ def erb_app(view)
+ mock_app {
+ layout { '<% yield_content :foo %>' }
+ get('/') { erb view }
+ }
+ end
+
+ it 'renders blocks declared with the same key you use when rendering' do
+ erb_app '<% content_for :foo do %>foo<% end %>'
+
+ get '/'
+ assert ok?
+ assert_equal 'foo', body
+ end
+
+ it 'does not render a block with a different key' do
+ erb_app '<% content_for :bar do %>bar<% end %>'
+
+ get '/'
+ assert ok?
+ assert_equal '', body
+ end
+
+ it 'renders multiple blocks with the same key' do
+ erb_app <<-erb_snippet
+ <% content_for :foo do %>foo<% end %>
+ <% content_for :foo do %>bar<% end %>
+ <% content_for :baz do %>WON'T RENDER ME<% end %>
+ <% content_for :foo do %>baz<% end %>
+ erb_snippet
+
+ get '/'
+ assert ok?
+ assert_equal 'foobarbaz', body
+ end
+end
From 619e91b5a6625da368c340c58f6689eebb71d383 Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Thu, 7 May 2009 03:03:44 -0300
Subject: [PATCH 0002/2904] We don't need to return the contents as string
Just calling each block works
---
sinatra-contrib/lib/sinatra/content_for.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb
index 921e06eb46..f0426c51be 100644
--- a/sinatra-contrib/lib/sinatra/content_for.rb
+++ b/sinatra-contrib/lib/sinatra/content_for.rb
@@ -5,7 +5,7 @@ def content_for(key, &block)
end
def yield_content(key)
- content_blocks[key.to_sym].map {|content| content.call }.join("")
+ content_blocks[key.to_sym].each {|content| content.call }
end
private
From a54186d4b08effc03745c3a18202563dd3c3272c Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Thu, 7 May 2009 10:58:41 -0300
Subject: [PATCH 0003/2904] Gemspec, Rakefile, etc
---
sinatra-contrib/.gitignore | 3 ++
sinatra-contrib/Rakefile | 33 ++++++++++++++++++++
sinatra-contrib/sinatra-content-for.gemspec | 34 +++++++++++++++++++++
sinatra-contrib/test/content_for_test.rb | 5 +++
4 files changed, 75 insertions(+)
create mode 100644 sinatra-contrib/.gitignore
create mode 100644 sinatra-contrib/Rakefile
create mode 100644 sinatra-contrib/sinatra-content-for.gemspec
diff --git a/sinatra-contrib/.gitignore b/sinatra-contrib/.gitignore
new file mode 100644
index 0000000000..18977f8b50
--- /dev/null
+++ b/sinatra-contrib/.gitignore
@@ -0,0 +1,3 @@
+doc
+dist
+tmp
diff --git a/sinatra-contrib/Rakefile b/sinatra-contrib/Rakefile
new file mode 100644
index 0000000000..379898212f
--- /dev/null
+++ b/sinatra-contrib/Rakefile
@@ -0,0 +1,33 @@
+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
diff --git a/sinatra-contrib/sinatra-content-for.gemspec b/sinatra-contrib/sinatra-content-for.gemspec
new file mode 100644
index 0000000000..8eaf7f0a88
--- /dev/null
+++ b/sinatra-contrib/sinatra-content-for.gemspec
@@ -0,0 +1,34 @@
+Gem::Specification.new do |s|
+ s.name = "sinatra-content-for"
+ s.version = "0.1"
+ s.date = "2009-05-07"
+
+ 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
diff --git a/sinatra-contrib/test/content_for_test.rb b/sinatra-contrib/test/content_for_test.rb
index 088129d6b2..47b788a026 100644
--- a/sinatra-contrib/test/content_for_test.rb
+++ b/sinatra-contrib/test/content_for_test.rb
@@ -10,6 +10,11 @@
require 'contest'
require 'sinatra/test'
+begin
+ require 'redgreen'
+rescue LoadError
+end
+
require File.dirname(__FILE__) + '/../lib/sinatra/content_for'
Sinatra::Base.set :environment, :test
From bd218ec9d7cfd53bbed21046c1b371b151b680c4 Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Thu, 7 May 2009 11:09:27 -0300
Subject: [PATCH 0004/2904] Documentation
---
sinatra-contrib/lib/sinatra/content_for.rb | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb
index f0426c51be..068fe97e35 100644
--- a/sinatra-contrib/lib/sinatra/content_for.rb
+++ b/sinatra-contrib/lib/sinatra/content_for.rb
@@ -1,9 +1,31 @@
module Sinatra
module ContentFor
+ # Capture a block of content to be rendered later. For example:
+ #
+ # <% content_for :head do %>
+ #
+ # <% end %>
+ #
+ # 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.
def content_for(key, &block)
content_blocks[key.to_sym] << block
end
+ # Render the captured blocks for a given key. For example:
+ #
+ #
+ # Example
+ # <% yield_content :head %>
+ #
+ #
+ # Would render everything you declared with content_for
+ # :head before closing the tag.
+ #
+ # *NOTICE* that you call this without an = sign. IE,
+ # in a <% %> block, and not in a <%= %> block.
def yield_content(key)
content_blocks[key.to_sym].each {|content| content.call }
end
From 4950daad2cfe3ec427de979bb0b299f68618236f Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Fri, 8 May 2009 20:14:56 -0300
Subject: [PATCH 0005/2904] Allow passing values to the blocks
---
sinatra-contrib/lib/sinatra/content_for.rb | 15 +++++++++++++--
sinatra-contrib/test/content_for_test.rb | 11 +++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb
index 068fe97e35..9ed130ac88 100644
--- a/sinatra-contrib/lib/sinatra/content_for.rb
+++ b/sinatra-contrib/lib/sinatra/content_for.rb
@@ -10,6 +10,9 @@ module ContentFor
# (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 yield_content
def content_for(key, &block)
content_blocks[key.to_sym] << block
end
@@ -24,10 +27,18 @@ def content_for(key, &block)
# Would render everything you declared with content_for
# :head before closing the tag.
#
+ # You can also pass values to the content blocks by passing them
+ # as arguments after the key:
+ #
+ # <% yield_content :head, 1, 2 %>
+ #
+ # Would pass 1 and 2 to all the blocks registered
+ # for :head.
+ #
# *NOTICE* that you call this without an = sign. IE,
# in a <% %> block, and not in a <%= %> block.
- def yield_content(key)
- content_blocks[key.to_sym].each {|content| content.call }
+ def yield_content(key, *args)
+ content_blocks[key.to_sym].each {|content| content.call(*args) }
end
private
diff --git a/sinatra-contrib/test/content_for_test.rb b/sinatra-contrib/test/content_for_test.rb
index 47b788a026..479c0d250f 100644
--- a/sinatra-contrib/test/content_for_test.rb
+++ b/sinatra-contrib/test/content_for_test.rb
@@ -74,4 +74,15 @@ def erb_app(view)
assert ok?
assert_equal 'foobarbaz', body
end
+
+ it 'passes values to the blocks' do
+ mock_app {
+ layout { '<% yield_content :foo, 1, 2 %>' }
+ get('/') { erb '<% content_for :foo do |a, b| %><%= a %> <%= b %><% end %>' }
+ }
+
+ get '/'
+ assert ok?
+ assert_equal '1 2', body
+ end
end
From 5847190ccd03916fdd959d4762d6546b12e846fd Mon Sep 17 00:00:00 2001
From: Matt Lyon
Date: Sat, 9 May 2009 14:19:25 -0300
Subject: [PATCH 0006/2904] Add Haml support
---
sinatra-contrib/lib/sinatra/content_for.rb | 8 +-
sinatra-contrib/test/content_for_test.rb | 154 +++++++++++++++------
2 files changed, 118 insertions(+), 44 deletions(-)
diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb
index 9ed130ac88..31848c6392 100644
--- a/sinatra-contrib/lib/sinatra/content_for.rb
+++ b/sinatra-contrib/lib/sinatra/content_for.rb
@@ -38,7 +38,13 @@ def content_for(key, &block)
# *NOTICE* that you call this without an = sign. IE,
# in a <% %> block, and not in a <%= %> block.
def yield_content(key, *args)
- content_blocks[key.to_sym].each {|content| content.call(*args) }
+ content_blocks[key.to_sym].map do |content|
+ if respond_to?(:block_is_haml?) && block_is_haml?(content)
+ capture_haml(*args, &content)
+ else
+ content.call(*args)
+ end
+ end.join
end
private
diff --git a/sinatra-contrib/test/content_for_test.rb b/sinatra-contrib/test/content_for_test.rb
index 479c0d250f..c9560f22e5 100644
--- a/sinatra-contrib/test/content_for_test.rb
+++ b/sinatra-contrib/test/content_for_test.rb
@@ -9,6 +9,7 @@
require 'contest'
require 'sinatra/test'
+require 'haml'
begin
require 'redgreen'
@@ -39,50 +40,117 @@ def mock_app(base=Sinatra::Base, &block)
end
class ContentForTest < Test::Unit::TestCase
- def erb_app(view)
- mock_app {
- layout { '<% yield_content :foo %>' }
- get('/') { erb view }
- }
+ context 'using erb' do
+ def erb_app(view)
+ mock_app {
+ layout { '<% yield_content :foo %>' }
+ get('/') { erb view }
+ }
+ end
+
+ it 'renders blocks declared with the same key you use when rendering' do
+ erb_app '<% content_for :foo do %>foo<% end %>'
+
+ get '/'
+ assert ok?
+ assert_equal 'foo', body
+ end
+
+ it 'does not render a block with a different key' do
+ erb_app '<% content_for :bar do %>bar<% end %>'
+
+ get '/'
+ assert ok?
+ assert_equal '', body
+ end
+
+ it 'renders multiple blocks with the same key' do
+ erb_app <<-erb_snippet
+ <% content_for :foo do %>foo<% end %>
+ <% content_for :foo do %>bar<% end %>
+ <% content_for :baz do %>WON'T RENDER ME<% end %>
+ <% content_for :foo do %>baz<% end %>
+ erb_snippet
+
+ get '/'
+ assert ok?
+ assert_equal 'foobarbaz', body
+ end
+
+ it 'passes values to the blocks' do
+ mock_app {
+ layout { '<% yield_content :foo, 1, 2 %>' }
+ get('/') { erb '<% content_for :foo do |a, b| %><%= a %> <%= b %><% end %>' }
+ }
+
+ get '/'
+ assert ok?
+ assert_equal '1 2', body
+ end
end
- it 'renders blocks declared with the same key you use when rendering' do
- erb_app '<% content_for :foo do %>foo<% end %>'
-
- get '/'
- assert ok?
- assert_equal 'foo', body
- end
-
- it 'does not render a block with a different key' do
- erb_app '<% content_for :bar do %>bar<% end %>'
-
- get '/'
- assert ok?
- assert_equal '', body
- end
-
- it 'renders multiple blocks with the same key' do
- erb_app <<-erb_snippet
- <% content_for :foo do %>foo<% end %>
- <% content_for :foo do %>bar<% end %>
- <% content_for :baz do %>WON'T RENDER ME<% end %>
- <% content_for :foo do %>baz<% end %>
- erb_snippet
-
- get '/'
- assert ok?
- assert_equal 'foobarbaz', body
- end
-
- it 'passes values to the blocks' do
- mock_app {
- layout { '<% yield_content :foo, 1, 2 %>' }
- get('/') { erb '<% content_for :foo do |a, b| %><%= a %> <%= b %><% end %>' }
- }
-
- get '/'
- assert ok?
- assert_equal '1 2', body
+ context 'with haml' do
+ def haml_app(view)
+ mock_app {
+ layout { '= yield_content :foo' }
+ get('/') { haml view }
+ }
+ end
+
+ it 'renders blocks declared with the same key you use when rendering' do
+ haml_app <<-haml_end
+- content_for :foo do
+ foo
+haml_end
+
+ get '/'
+ assert ok?
+ assert_equal "foo\n", body
+ end
+
+ it 'does not render a block with a different key' do
+ haml_app <<-haml_end
+- content_for :bar do
+ bar
+haml_end
+
+ get '/'
+ assert ok?
+ assert_equal "\n", body
+ end
+
+ it 'renders multiple blocks with the same key' do
+ haml_app <<-haml_end
+- content_for :foo do
+ foo
+- content_for :foo do
+ bar
+- content_for :baz do
+ WON'T RENDER ME
+- content_for :foo do
+ baz
+haml_end
+
+ get '/'
+ assert ok?
+ assert_equal "foo\nbar\nbaz\n", body
+ end
+
+ it 'passes values to the blocks' do
+ mock_app {
+ layout { '= yield_content :foo, 1, 2' }
+ get('/') {
+ haml <<-haml_end
+- content_for :foo do |a, b|
+ %i= a
+ =b
+haml_end
+ }
+ }
+
+ get '/'
+ assert ok?
+ assert_equal "1\n2\n", body
+ end
end
end
From e7e5ebc57c98a09d58bed784052e6bd2e9fd20d3 Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Sat, 9 May 2009 14:21:13 -0300
Subject: [PATCH 0007/2904] Push version to 0.2
This release adds:
* Support for HAML
* Support to yield values into the content blocks
---
sinatra-contrib/sinatra-content-for.gemspec | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sinatra-contrib/sinatra-content-for.gemspec b/sinatra-contrib/sinatra-content-for.gemspec
index 8eaf7f0a88..63242e6bcb 100644
--- a/sinatra-contrib/sinatra-content-for.gemspec
+++ b/sinatra-contrib/sinatra-content-for.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "sinatra-content-for"
- s.version = "0.1"
- s.date = "2009-05-07"
+ 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'"
From c8e8f737ef7552b00ddff4bd4e444c0a91f64ac4 Mon Sep 17 00:00:00 2001
From: Nicolas Sanguinetti
Date: Tue, 19 May 2009 03:53:54 -0300
Subject: [PATCH 0008/2904] Update the readme (we now support haml)
---
sinatra-contrib/README.rdoc | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/sinatra-contrib/README.rdoc b/sinatra-contrib/README.rdoc
index 12022a7b56..cf7c2abba4 100644
--- a/sinatra-contrib/README.rdoc
+++ b/sinatra-contrib/README.rdoc
@@ -13,6 +13,20 @@ 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
+
+Note that with ERB yield_content is called without
+an '=' block (<%= %>), but with Haml it uses = yield_content.
+
+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
@@ -29,13 +43,7 @@ your layout, inside the tag, and each view can call
content_for setting the appropriate set of tags that should
be added to the layout.
-== Warning
-
-This only works with ERB as a rendering mechanism. I haven't figured
-how to make it work with Haml. If you find a way, contact me and I'll
-include it.
-
== Credits
Code by foca[http://github.com/foca], inspired on the Ruby on Rails
-helpers with the same name.
+helpers with the same name. Haml support by mattly[http://github.com/mattly].
From 1b00d5054ede50fa84a4525b219dd6fa92b04a08 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Mon, 14 Dec 2009 02:40:38 -0800
Subject: [PATCH 0009/2904] Update file manifest in gemspec
---
sinatra.gemspec | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sinatra.gemspec b/sinatra.gemspec
index d28e980ab9..6b79cae98d 100644
--- a/sinatra.gemspec
+++ b/sinatra.gemspec
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.name = 'sinatra'
s.version = '0.10.1'
- s.date = '2009-10-08'
+ s.date = '2009-12-13'
s.description = "Classy web-development dressed in a DSL"
s.summary = "Classy web-development dressed in a DSL"
@@ -26,13 +26,14 @@ Gem::Specification.new do |s|
lib/sinatra/images/500.png
lib/sinatra/main.rb
lib/sinatra/showexceptions.rb
- lib/tilt.rb
+ lib/sinatra/tilt.rb
sinatra.gemspec
test/base_test.rb
test/builder_test.rb
test/contest.rb
test/data/reload_app_file.rb
test/erb_test.rb
+ test/erubis_test.rb
test/extensions_test.rb
test/filter_test.rb
test/haml_test.rb
@@ -53,16 +54,19 @@ Gem::Specification.new do |s|
test/templates_test.rb
test/views/error.builder
test/views/error.erb
+ test/views/error.erubis
test/views/error.haml
test/views/error.sass
test/views/foo/hello.test
test/views/hello.builder
test/views/hello.erb
+ test/views/hello.erubis
test/views/hello.haml
test/views/hello.sass
test/views/hello.test
test/views/layout2.builder
test/views/layout2.erb
+ test/views/layout2.erubis
test/views/layout2.haml
test/views/layout2.test
]
From 7c253c2f80db0f9cf23640347bb70cc28282a8c3 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Mon, 14 Dec 2009 02:47:57 -0800
Subject: [PATCH 0010/2904] Revert 7f5d4df Deprecate Sinatra::Default, use
Sinatra::Application
We're not sure what we want to do with Default yet but it's
most likely not going to end up as a simple alias for Application.
This reverts Default back to the 0.9.x behavior. See #312 in
lighthouse for more on this:
http://sinatra.lighthouseapp.com/projects/9779/tickets/312
---
lib/sinatra/base.rb | 14 +++++++++-----
lib/sinatra/main.rb | 8 +++-----
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 79d41a7396..780b874073 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -1078,9 +1078,8 @@ def caller_locations
end
end
- # The top-level Application. All DSL methods executed on main are delegated
- # to this class.
- class Application < Base
+ # Base class for classic style (top-level) applications.
+ class Default < Base
set :raise_errors, Proc.new { test? }
set :show_exceptions, Proc.new { development? }
set :dump_errors, true
@@ -1097,6 +1096,11 @@ def self.register(*extensions, &block) #:nodoc:
end
end
+ # The top-level Application. All DSL methods executed on main are delegated
+ # to this class.
+ class Application < Default
+ end
+
# Sinatra delegation mixin. Mixing this module into an object causes all
# methods to be delegated to the Sinatra::Application class. Used primarily
# at the top-level.
@@ -1128,11 +1132,11 @@ def self.new(base=Base, options={}, &block)
# Extend the top-level DSL with the modules provided.
def self.register(*extensions, &block)
- Application.register(*extensions, &block)
+ Default.register(*extensions, &block)
end
# Include the helper modules provided in Sinatra's request context.
def self.helpers(*extensions, &block)
- Application.helpers(*extensions, &block)
+ Default.helpers(*extensions, &block)
end
end
diff --git a/lib/sinatra/main.rb b/lib/sinatra/main.rb
index c2f7a18bd7..f890c3dfda 100644
--- a/lib/sinatra/main.rb
+++ b/lib/sinatra/main.rb
@@ -1,7 +1,7 @@
require 'sinatra/base'
module Sinatra
- class Application < Base
+ class Default < Base
# we assume that the first file that requires 'sinatra' is the
# app_file. all other path related options are calculated based
@@ -20,11 +20,9 @@ class Application < Base
op.on('-h addr') { |val| set :host, val }
}.parse!(ARGV.dup)
end
-
- at_exit do
- run! if $!.nil? && run?
- end
end
+
+ at_exit { Application.run! if $!.nil? && Application.run? }
end
include Sinatra::Delegator
From 056bd7bb770884d064c4a94e23cd16d38b11c474 Mon Sep 17 00:00:00 2001
From: Blake Mizerany
Date: Thu, 17 Dec 2009 18:25:18 -0800
Subject: [PATCH 0011/2904] closes #308 - Depricate use_in_file_templates! in
favor of slurp_file_templates
---
lib/sinatra.rb | 2 +-
lib/sinatra/base.rb | 4 ++--
test/templates_test.rb | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/sinatra.rb b/lib/sinatra.rb
index ce3ad6a464..448d27b22e 100644
--- a/lib/sinatra.rb
+++ b/lib/sinatra.rb
@@ -4,4 +4,4 @@
require 'sinatra/base'
require 'sinatra/main'
-use_in_file_templates!
+slup_file_templates
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 780b874073..6d809e1a95 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -722,7 +722,7 @@ def layout(name=:layout, &block)
# Load embeded templates from the file; uses the caller's __FILE__
# when no file is specified.
- def use_in_file_templates!(file=nil)
+ def slup_file_templates(file=nil)
file ||= caller_files.first
begin
@@ -1119,7 +1119,7 @@ def #{method_name}(*args, &b)
delegate :get, :put, :post, :delete, :head, :template, :layout,
:before, :after, :error, :not_found, :configure, :set, :mime_type,
:enable, :disable, :use, :development?, :test?,
- :production?, :use_in_file_templates!, :helpers
+ :production?, :slup_file_templates, :helpers
end
# Create a new Sinatra application. The block is evaluated in the new app's
diff --git a/test/templates_test.rb b/test/templates_test.rb
index 2f8d4e5044..b01ab2e466 100644
--- a/test/templates_test.rb
+++ b/test/templates_test.rb
@@ -76,9 +76,9 @@ def with_default_layout
assert_equal "Layout 3!\nHello World!\n", body
end
- it 'loads templates from source file with use_in_file_templates!' do
+ it 'loads templates from source file with slup_file_templates' do
mock_app {
- use_in_file_templates!
+ slup_file_templates
}
assert_equal "this is foo\n\n", @app.templates[:foo][0]
assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
@@ -90,10 +90,10 @@ def with_default_layout
assert_equal "from another views directory\n", body
end
- test 'use_in_file_templates simply ignores IO errors' do
+ test 'slup_file_templates simply ignores IO errors' do
assert_nothing_raised {
mock_app {
- use_in_file_templates!('/foo/bar')
+ slup_file_templates('/foo/bar')
}
}
From c6304830cb588f30160db3a28b22014a8c765cb1 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:48:19 +0100
Subject: [PATCH 0012/2904] options_test.rb => settings_test.rb
---
test/{options_test.rb => settings_test.rb} | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
rename test/{options_test.rb => settings_test.rb} (98%)
diff --git a/test/options_test.rb b/test/settings_test.rb
similarity index 98%
rename from test/options_test.rb
rename to test/settings_test.rb
index 0249b934d0..13a058e86e 100644
--- a/test/options_test.rb
+++ b/test/settings_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/helper'
-class OptionsTest < Test::Unit::TestCase
+class SettingsTest < Test::Unit::TestCase
setup do
@base = Sinatra.new(Sinatra::Base)
@application = Sinatra.new(Sinatra::Application)
@@ -251,7 +251,7 @@ def clean_backtrace(trace)
}
get '/'
- assert body.include?("RuntimeError") && body.include?("options_test.rb")
+ assert body.include?("RuntimeError") && body.include?("settings_test.rb")
end
end
From b1936b6a28eedea44115fe7bc4136756b85c4b18 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:50:40 +0100
Subject: [PATCH 0013/2904] Clean-up settings test
---
test/settings_test.rb | 95 +++++++++++++++++++------------------------
1 file changed, 42 insertions(+), 53 deletions(-)
diff --git a/test/settings_test.rb b/test/settings_test.rb
index 13a058e86e..039bfde659 100644
--- a/test/settings_test.rb
+++ b/test/settings_test.rb
@@ -3,24 +3,25 @@
class SettingsTest < Test::Unit::TestCase
setup do
@base = Sinatra.new(Sinatra::Base)
+ @base.set :environment, :foo
+
@application = Sinatra.new(Sinatra::Application)
- @base.set :environment, :development
- @application.set :environment, :development
+ @application.set :environment, :foo
end
- it 'sets options to literal values' do
+ it 'sets settings to literal values' do
@base.set(:foo, 'bar')
assert @base.respond_to?(:foo)
assert_equal 'bar', @base.foo
end
- it 'sets options to Procs' do
+ it 'sets settings to Procs' do
@base.set(:foo, Proc.new { 'baz' })
assert @base.respond_to?(:foo)
assert_equal 'baz', @base.foo
end
- it "sets multiple options with a Hash" do
+ it "sets multiple settings with a Hash" do
@base.set :foo => 1234,
:bar => 'Hello World',
:baz => Proc.new { 'bizzle' }
@@ -29,7 +30,7 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'bizzle', @base.baz
end
- it 'inherits option methods when subclassed' do
+ it 'inherits settings methods when subclassed' do
@base.set :foo, 'bar'
@base.set :biz, Proc.new { 'baz' }
@@ -40,7 +41,7 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'baz', sub.biz
end
- it 'overrides options in subclass' do
+ it 'overrides settings in subclass' do
@base.set :foo, 'bar'
@base.set :biz, Proc.new { 'baz' }
sub = Class.new(@base)
@@ -78,31 +79,42 @@ def foo=(value)
assert_equal 'oops', @base.foo
end
- it "sets multiple options to true with #enable" do
+ it "sets multiple settings to true with #enable" do
@base.enable :sessions, :foo, :bar
assert @base.sessions
assert @base.foo
assert @base.bar
end
- it "sets multiple options to false with #disable" do
+ it "sets multiple settings to false with #disable" do
@base.disable :sessions, :foo, :bar
assert !@base.sessions
assert !@base.foo
assert !@base.bar
end
- it 'enables MethodOverride middleware when :methodoverride is enabled' do
- @base.set :methodoverride, true
- @base.put('/') { 'okay' }
- @app = @base
- post '/', {'_method'=>'PUT'}, {}
- assert_equal 200, status
- assert_equal 'okay', body
- end
it 'is accessible from instances via #settings' do
- assert_equal :development, @base.new.settings.environment
+ assert_equal :foo, @base.new.settings.environment
+ end
+
+ describe 'methodoverride' do
+ it 'is disabled on Base' do
+ assert ! @base.methodoverride?
+ end
+
+ it 'is enabled on Application' do
+ assert @application.methodoverride?
+ end
+
+ it 'enables MethodOverride middleware' do
+ @base.set :methodoverride, true
+ @base.put('/') { 'okay' }
+ @app = @base
+ post '/', {'_method'=>'PUT'}, {}
+ assert_equal 200, status
+ assert_equal 'okay', body
+ end
end
describe 'clean_trace' do
@@ -156,16 +168,12 @@ def clean_backtrace(trace)
assert ! @base.run?
end
- it 'is enabled on Application when not in test environment' do
- @application.set :environment, :development
- assert @application.development?
+ it 'is enabled on Application except in test environment' do
assert @application.run?
- @application.set :environment, :development
- assert @application.run?
+ @application.set :environment, :test
+ assert ! @application.run?
end
-
- # TODO: it 'is enabled when $0 == app_file'
end
describe 'raise_errors' do
@@ -174,11 +182,6 @@ def clean_backtrace(trace)
end
it 'is enabled on Application only in test' do
- @application.set(:environment, :development)
- assert @application.development?
- assert ! @application.raise_errors?
-
- @application.set(:environment, :production)
assert ! @application.raise_errors?
@application.set(:environment, :test)
@@ -187,23 +190,15 @@ def clean_backtrace(trace)
end
describe 'show_exceptions' do
- %w[development test production none].each do |environment|
- it "is disabled on Base in #{environment} environments" do
- @base.set(:environment, environment)
- assert ! @base.show_exceptions?
- end
+ it 'is disabled on Base' do
+ assert ! @base.show_exceptions?
end
- it 'is enabled on Application only in development' do
- @base.set(:environment, :development)
- assert @application.development?
- assert @application.show_exceptions?
-
- @application.set(:environment, :test)
+ it 'is disabled on Application except in development' do
assert ! @application.show_exceptions?
- @base.set(:environment, :production)
- assert ! @base.show_exceptions?
+ @application.set(:environment, :development)
+ assert @application.show_exceptions?
end
it 'returns a friendly 500' do
@@ -263,8 +258,6 @@ def clean_backtrace(trace)
it 'is disabled on Application' do
assert ! @application.sessions?
end
-
- # TODO: it 'uses Rack::Session::Cookie when enabled' do
end
describe 'logging' do
@@ -272,14 +265,12 @@ def clean_backtrace(trace)
assert ! @base.logging?
end
- it 'is enabled on Application when not in test environment' do
+ it 'is enabled on Application except in test environment' do
assert @application.logging?
@application.set :environment, :test
assert ! @application.logging
end
-
- # TODO: it 'uses Rack::CommonLogger when enabled' do
end
describe 'static' do
@@ -290,9 +281,6 @@ def clean_backtrace(trace)
it 'is enabled on Application' do
assert @application.static?
end
-
- # TODO: it setup static routes if public is enabled
- # TODO: however, that's already tested in static_test so...
end
describe 'host' do
@@ -318,8 +306,8 @@ def clean_backtrace(trace)
describe 'app_file' do
it 'is nil' do
- assert @base.app_file.nil?
- assert @application.app_file.nil?
+ assert_nil @base.app_file
+ assert_nil @application.app_file
end
end
@@ -371,6 +359,7 @@ def clean_backtrace(trace)
describe 'lock' do
it 'is disabled by default' do
assert ! @base.lock?
+ assert ! @application.lock?
end
end
end
From 01b5f659698f776a4cb8fe483bc6926bc65feef9 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:51:59 +0100
Subject: [PATCH 0014/2904] options => settings in ShowExceptions
---
lib/sinatra/showexceptions.rb | 2 +-
test/settings_test.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sinatra/showexceptions.rb b/lib/sinatra/showexceptions.rb
index c5aa178849..477f0c4cbe 100644
--- a/lib/sinatra/showexceptions.rb
+++ b/lib/sinatra/showexceptions.rb
@@ -294,7 +294,7 @@ def frame_class(frame)
You're seeing this error because you have
-enabled the show_exceptions option.
+enabled the show_exceptions setting.
diff --git a/test/settings_test.rb b/test/settings_test.rb
index 039bfde659..b050f0dcd5 100644
--- a/test/settings_test.rb
+++ b/test/settings_test.rb
@@ -214,7 +214,7 @@ def clean_backtrace(trace)
get '/'
assert_equal 500, status
assert body.include?("StandardError")
- assert body.include?("show_exceptions option")
+ assert body.include?("show_exceptions setting")
end
end
From 0067232e1f75c02b9ea51bba2ca5e5fb3b7ae070 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 19 Dec 2009 01:54:11 +0100
Subject: [PATCH 0015/2904] Revert "closes #308 - Depricate
use_in_file_templates! in favor of slurp_file_templates"
This reverts commit 056bd7bb770884d064c4a94e23cd16d38b11c474.
---
lib/sinatra.rb | 2 +-
lib/sinatra/base.rb | 4 ++--
test/templates_test.rb | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/sinatra.rb b/lib/sinatra.rb
index 448d27b22e..ce3ad6a464 100644
--- a/lib/sinatra.rb
+++ b/lib/sinatra.rb
@@ -4,4 +4,4 @@
require 'sinatra/base'
require 'sinatra/main'
-slup_file_templates
+use_in_file_templates!
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 6d809e1a95..780b874073 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -722,7 +722,7 @@ def layout(name=:layout, &block)
# Load embeded templates from the file; uses the caller's __FILE__
# when no file is specified.
- def slup_file_templates(file=nil)
+ def use_in_file_templates!(file=nil)
file ||= caller_files.first
begin
@@ -1119,7 +1119,7 @@ def #{method_name}(*args, &b)
delegate :get, :put, :post, :delete, :head, :template, :layout,
:before, :after, :error, :not_found, :configure, :set, :mime_type,
:enable, :disable, :use, :development?, :test?,
- :production?, :slup_file_templates, :helpers
+ :production?, :use_in_file_templates!, :helpers
end
# Create a new Sinatra application. The block is evaluated in the new app's
diff --git a/test/templates_test.rb b/test/templates_test.rb
index b01ab2e466..2f8d4e5044 100644
--- a/test/templates_test.rb
+++ b/test/templates_test.rb
@@ -76,9 +76,9 @@ def with_default_layout
assert_equal "Layout 3!\nHello World!\n", body
end
- it 'loads templates from source file with slup_file_templates' do
+ it 'loads templates from source file with use_in_file_templates!' do
mock_app {
- slup_file_templates
+ use_in_file_templates!
}
assert_equal "this is foo\n\n", @app.templates[:foo][0]
assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
@@ -90,10 +90,10 @@ def with_default_layout
assert_equal "from another views directory\n", body
end
- test 'slup_file_templates simply ignores IO errors' do
+ test 'use_in_file_templates simply ignores IO errors' do
assert_nothing_raised {
mock_app {
- slup_file_templates('/foo/bar')
+ use_in_file_templates!('/foo/bar')
}
}
From 3ef8eedef257b513f531dd48bfedcbc8df8a622b Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 19 Dec 2009 02:07:01 +0100
Subject: [PATCH 0016/2904] Deprecate use_in_file_templates!
Use enable :inline_templates instead
---
README.rdoc | 8 ++++----
lib/sinatra.rb | 2 +-
lib/sinatra/base.rb | 10 ++++++++--
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/README.rdoc b/README.rdoc
index b8543c7965..0a92a1a57d 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -219,7 +219,7 @@ Or, specify an explicit Hash of local variables:
This is typically used when rendering templates as partials from within
other templates.
-=== In-file Templates
+=== Inline Templates
Templates may be defined at the end of the source file:
@@ -239,9 +239,9 @@ Templates may be defined at the end of the source file:
@@ index
%div.title Hello world!!!!!
-NOTE: In-file templates defined in the source file that requires sinatra
-are automatically loaded. Call the use_in_file_templates!
-method explicitly if you have in-file templates in other source files.
+NOTE: Inline templates defined in the source file that requires sinatra
+are automatically loaded. Call `enable :inline_templates` explicitly if you
+have inline templates in other source files.
=== Named Templates
diff --git a/lib/sinatra.rb b/lib/sinatra.rb
index ce3ad6a464..71b122d1af 100644
--- a/lib/sinatra.rb
+++ b/lib/sinatra.rb
@@ -4,4 +4,4 @@
require 'sinatra/base'
require 'sinatra/main'
-use_in_file_templates!
+enable :inline_templates
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 780b874073..47cf3bd6ac 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -720,10 +720,16 @@ def layout(name=:layout, &block)
template name, &block
end
+ def use_in_file_templates!(file=nil)
+ warn "use_in_file_templates! is deprecated; " \
+ "use enable :inline_templates instead"
+ set :inline_templates, file
+ end
+
# Load embeded templates from the file; uses the caller's __FILE__
# when no file is specified.
- def use_in_file_templates!(file=nil)
- file ||= caller_files.first
+ def inline_templates=(file=nil)
+ file = (file.nil? || file == true) ? caller_files.first : file
begin
app, data =
From f9a792396ca6172e983b7eb4d7fa2b30b3e3ccef Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Wed, 23 Dec 2009 20:32:23 -0600
Subject: [PATCH 0017/2904] Set X-Cascade header when using pass
Setting X-Cascade: pass allows middleware outside the Sinatra stack
to continue trying to match the request.
Signed-off-by: Ryan Tomayko
---
lib/sinatra/base.rb | 7 ++++---
test/helpers_test.rb | 13 +++++++++++++
test/routing_test.rb | 26 ++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 47cf3bd6ac..405401d552 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -583,9 +583,10 @@ def dispatch!
end
def handle_not_found!(boom)
- @env['sinatra.error'] = boom
- @response.status = 404
- @response.body = ['Not Found
']
+ @env['sinatra.error'] = boom
+ @response.status = 404
+ @response.headers['X-Cascade'] = 'pass'
+ @response.body = ['Not Found
']
error_block! boom.class, NotFound
end
diff --git a/test/helpers_test.rb b/test/helpers_test.rb
index 61ccdf8fc5..7c8c09200f 100644
--- a/test/helpers_test.rb
+++ b/test/helpers_test.rb
@@ -142,6 +142,19 @@ def test_default
assert_equal 404, status
assert_equal '', body
end
+
+ it 'does not set a X-Cascade header' do
+ mock_app {
+ get '/' do
+ not_found
+ fail 'not_found should halt'
+ end
+ }
+
+ get '/'
+ assert_equal 404, status
+ assert_equal nil, response.headers['X-Cascade']
+ end
end
describe 'headers' do
diff --git a/test/routing_test.rb b/test/routing_test.rb
index 6ef3254796..9976b679fb 100644
--- a/test/routing_test.rb
+++ b/test/routing_test.rb
@@ -60,6 +60,15 @@ class RoutingTest < Test::Unit::TestCase
assert_equal 404, status
end
+ it "404s and sets X-Cascade header when no route satisfies the request" do
+ mock_app {
+ get('/foo') { }
+ }
+ get '/bar'
+ assert_equal 404, status
+ assert_equal 'pass', response.headers['X-Cascade']
+ end
+
it "overrides the content-type in error handlers" do
mock_app {
before { content_type 'text/plain' }
@@ -462,6 +471,23 @@ class RoutingTest < Test::Unit::TestCase
assert not_found?
end
+ it "transitions to 404 and sets X-Cascade header when passed and no subsequent route matches" do
+ mock_app {
+ get '/:foo' do
+ pass
+ 'Hello Foo'
+ end
+
+ get '/bar' do
+ 'Hello Bar'
+ end
+ }
+
+ get '/foo'
+ assert not_found?
+ assert_equal 'pass', response.headers['X-Cascade']
+ end
+
it "uses optional block passed to pass as route block if no other route is found" do
mock_app {
get "/" do
From 8d45055ac6a6440473844b6dbdbc09d59d1e3486 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Thu, 24 Dec 2009 06:50:27 +0100
Subject: [PATCH 0018/2904] Get ride of unused fixture
---
test/data/reload_app_file.rb | 3 ---
1 file changed, 3 deletions(-)
delete mode 100644 test/data/reload_app_file.rb
diff --git a/test/data/reload_app_file.rb b/test/data/reload_app_file.rb
deleted file mode 100644
index 673ab7cd92..0000000000
--- a/test/data/reload_app_file.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-$reload_count += 1
-
-$reload_app.get('/') { 'Hello from reload file' }
From 7ab3565256b05ea657ef1a4dafc778ce9f538007 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 26 Dec 2009 03:57:55 +0100
Subject: [PATCH 0019/2904] Get rid of use_in_file_templates!
---
lib/sinatra/base.rb | 6 ------
test/templates_test.rb | 6 +++---
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 405401d552..5766ca5dae 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -721,12 +721,6 @@ def layout(name=:layout, &block)
template name, &block
end
- def use_in_file_templates!(file=nil)
- warn "use_in_file_templates! is deprecated; " \
- "use enable :inline_templates instead"
- set :inline_templates, file
- end
-
# Load embeded templates from the file; uses the caller's __FILE__
# when no file is specified.
def inline_templates=(file=nil)
diff --git a/test/templates_test.rb b/test/templates_test.rb
index 2f8d4e5044..985607058e 100644
--- a/test/templates_test.rb
+++ b/test/templates_test.rb
@@ -76,9 +76,9 @@ def with_default_layout
assert_equal "Layout 3!\nHello World!\n", body
end
- it 'loads templates from source file with use_in_file_templates!' do
+ it 'loads templates from source file with inline_templates enabled' do
mock_app {
- use_in_file_templates!
+ enable :inline_templates
}
assert_equal "this is foo\n\n", @app.templates[:foo][0]
assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
@@ -93,7 +93,7 @@ def with_default_layout
test 'use_in_file_templates simply ignores IO errors' do
assert_nothing_raised {
mock_app {
- use_in_file_templates!('/foo/bar')
+ set :inline_templates, '/foo/bar'
}
}
From b90d00c84ef7f7edce97bb869b085b0225e1e9f9 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 19 Dec 2009 09:06:28 +0100
Subject: [PATCH 0020/2904] Update sass example re. options
---
README.rdoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.rdoc b/README.rdoc
index 0a92a1a57d..5d9514da48 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -187,7 +187,7 @@ and overridden on an individual basis.
get '/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8'
- sass :stylesheet, :sass_options => {:style => :expanded } # overridden
+ sass :stylesheet, :style => :expanded # overridden
end
From fbbd822752e1bef86e35f29d6692ee84312f6dae Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 19 Dec 2009 09:16:31 +0100
Subject: [PATCH 0021/2904] More 'halt' doc
---
README.rdoc | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/README.rdoc b/README.rdoc
index 5d9514da48..6c7ae39726 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -311,14 +311,22 @@ To immediately stop a request within a filter or route use:
halt
-You can also specify a body when halting ...
+You can also specify the status when halting ...
+
+ halt 410
+
+Or the body ...
halt 'this will be the body'
-Or set the status and body ...
+Or both ...
halt 401, 'go away!'
+With headers ...
+
+ halt 402, {'Content-Type' => 'text/plain'}, 'revenge'
+
== Passing
A route can punt processing to the next matching route using pass:
From 63fd77348ddbc1a68503abe231f5f6466ee05f73 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Sat, 19 Dec 2009 22:03:37 +0100
Subject: [PATCH 0022/2904] Small doc fix re. after filter
---
README.rdoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.rdoc b/README.rdoc
index 6c7ae39726..ee59863ca1 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -383,7 +383,7 @@ code is 404, the not_found handler is invoked:
=== Error
The +error+ handler is invoked any time an exception is raised from a route
-block or before filter. The exception object can be obtained from the
+block or a filter. The exception object can be obtained from the
sinatra.error Rack variable:
error do
From 59e797e99775c5abc7493bf24b9027de3ccad96d Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:10:14 +0100
Subject: [PATCH 0023/2904] Doc for error(500) { }
---
README.rdoc | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/README.rdoc b/README.rdoc
index ee59863ca1..9569c0e7ef 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -406,6 +406,22 @@ You get this:
So what happened was... something bad
+Alternatively, you can install error handler for a status code:
+
+ error 403 do
+ 'Access forbidden'
+ end
+
+ get '/secret' do
+ 403
+ end
+
+Or a range:
+
+ error 400..510 do
+ 'Boom'
+ end
+
Sinatra installs special not_found and error handlers when
running under the development environment.
From 7c5d69371854033e8d7f9ec4eab1a62eca8944b3 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:11:09 +0100
Subject: [PATCH 0024/2904] Doc for erubis
---
README.rdoc | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/README.rdoc b/README.rdoc
index 9569c0e7ef..58267703fe 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -150,6 +150,19 @@ and overridden on an individual basis.
Renders ./views/index.erb
+=== Erubis
+
+The erubis gem/library is required to render builder templates:
+
+ ## You'll need to require erubis in your app
+ require 'erubis'
+
+ get '/' do
+ erubis :index
+ end
+
+Renders ./views/index.erubis
+
=== Builder Templates
The builder gem/library is required to render builder templates:
From cb8fcb6350a49106073bf8e1c280ea2f7e2a8df2 Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:12:23 +0100
Subject: [PATCH 0025/2904] Doc for content_type :foo
---
README.rdoc | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.rdoc b/README.rdoc
index 58267703fe..a98df3b777 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -445,6 +445,10 @@ doesn't understand. Use +mime_type+ to register them by file extension:
mime_type :foo, 'text/foo'
+You can also use it with the +content_type+ helper:
+
+ content_type :foo
+
== Rack Middleware
Sinatra rides on Rack[http://rack.rubyforge.org/], a minimal standard
From 2624423bdf8fbbcfe379a66a2b06a07ccf9e0e3f Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:12:53 +0100
Subject: [PATCH 0026/2904] Doc for -h option
---
README.rdoc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.rdoc b/README.rdoc
index a98df3b777..06155d04a0 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -573,12 +573,13 @@ being {included into the main namespace}[http://github.com/sinatra/sinatra/blob/
Sinatra applications can be run directly:
- ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-s HANDLER]
+ ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-h HOST] [-s HANDLER]
Options are:
-h # help
-p # set the port (default is 4567)
+ -h # set the host (default is 0.0.0.0)
-e # set the environment (default is development)
-s # specify rack server/handler (default is thin)
-x # turn on the mutex lock (default is off)
From 6c9488e22a9ca76b66c31e74ee26f737ba0e87cb Mon Sep 17 00:00:00 2001
From: Simon Rozet
Date: Wed, 23 Dec 2009 03:13:35 +0100
Subject: [PATCH 0027/2904] Stick to single quote; kill a blank line
---
README.rdoc | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/README.rdoc b/README.rdoc
index 06155d04a0..1c4f273f2e 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -203,7 +203,6 @@ and overridden on an individual basis.
sass :stylesheet, :style => :expanded # overridden
end
-
=== Inline Templates
get '/' do
@@ -346,11 +345,11 @@ A route can punt processing to the next matching route using pass:
get '/guess/:who' do
pass unless params[:who] == 'Frank'
- "You got me!"
+ 'You got me!'
end
get '/guess/*' do
- "You missed!"
+ 'You missed!'
end
The route block is immediately exited and control continues with the next
From 574226fd86d7125d04aff4ef0d142dd949df27db Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Fri, 15 Jan 2010 05:46:25 -0800
Subject: [PATCH 0028/2904] rake test puts work dir on explicitly for 1.9
---
Rakefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Rakefile b/Rakefile
index 5bb0cafae9..e9a10a5642 100644
--- a/Rakefile
+++ b/Rakefile
@@ -9,7 +9,7 @@ task :spec => :test
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
- t.ruby_opts = ['-rubygems'] if defined? Gem
+ t.ruby_opts = ['-rubygems -I.'] if defined? Gem
end
# PACKAGING ============================================================
From 9b82444d02002fc3ac9ff0af26886457ac616b4b Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Fri, 15 Jan 2010 05:46:56 -0800
Subject: [PATCH 0029/2904] Use proc instead lambda for 1.9.2 compatibility
[#311]
---
lib/sinatra/base.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 5766ca5dae..41ba875d6a 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -838,9 +838,9 @@ def route(verb, path, options={}, &block)
unbound_method = instance_method("#{verb} #{path}")
block =
if block.arity != 0
- lambda { unbound_method.bind(self).call(*@block_params) }
+ proc { unbound_method.bind(self).call(*@block_params) }
else
- lambda { unbound_method.bind(self).call }
+ proc { unbound_method.bind(self).call }
end
invoke_hook(:route_added, verb, path, block)
From 466cc74b8f393f98de227122c78ed55cb745cbc6 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Sat, 16 Jan 2010 07:12:47 -0800
Subject: [PATCH 0030/2904] simplify gemspec loading, fix spec warnings under
1.9
---
Rakefile | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/Rakefile b/Rakefile
index e9a10a5642..0cfabdcd35 100644
--- a/Rakefile
+++ b/Rakefile
@@ -16,14 +16,8 @@ end
# Load the gemspec using the same limitations as github
def spec
- @spec ||=
- begin
- require 'rubygems/specification'
- data = File.read('sinatra.gemspec')
- spec = nil
- Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
- spec
- end
+ require 'rubygems' unless defined? Gem::Specification
+ @spec ||= eval(File.read('sinatra.gemspec'))
end
def package(ext='')
From e7b5985f991230b7036f85c486cd3c182416816c Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 05:24:40 -0800
Subject: [PATCH 0031/2904] don't override Request#params/#user_agent when rack
>= 1.1
---
lib/sinatra/base.rb | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 41ba875d6a..0f8eaa45d3 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -18,25 +18,29 @@ module Sinatra
# The request object. See Rack::Request for more info:
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
class Request < Rack::Request
- def user_agent
- @env['HTTP_USER_AGENT']
- end
-
# Returns an array of acceptable media types for the response
def accept
@env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.strip }
end
- # Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
- def params
- self.GET.update(self.POST)
- rescue EOFError, Errno::ESPIPE
- self.GET
- end
-
def secure?
(@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
end
+
+ # Override Rack < 1.1's Request#params implementation (see lh #72 for
+ # more info) and add a Request#user_agent method.
+ # XXX remove when we require rack > 1.1
+ if Rack.release < '1.1'
+ def params
+ self.GET.update(self.POST)
+ rescue EOFError, Errno::ESPIPE
+ self.GET
+ end
+
+ def user_agent
+ @env['HTTP_USER_AGENT']
+ end
+ end
end
# The response object. See Rack::Response and Rack::ResponseHelpers for
From fed9db550496c2d26007bd9d517e7789439ca0b2 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 05:25:44 -0800
Subject: [PATCH 0032/2904] remove old rubyforge release rake tasks
---
Rakefile | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/Rakefile b/Rakefile
index 0cfabdcd35..f4369ef1db 100644
--- a/Rakefile
+++ b/Rakefile
@@ -49,16 +49,6 @@ file package('.tar.gz') => %w[pkg/] + spec.files do |f|
SH
end
-# Rubyforge Release / Publish Tasks ==================================
-
-desc 'Publish gem and tarball to rubyforge'
-task 'release' => [package('.gem'), package('.tar.gz')] do |t|
- sh <<-end
- rubyforge add_release sinatra sinatra #{spec.version} #{package('.gem')} &&
- rubyforge add_file sinatra sinatra #{spec.version} #{package('.tar.gz')}
- end
-end
-
# Website ============================================================
# Building docs requires HAML and the hanna gem:
# gem install mislav-hanna --source=http://gems.github.com
From 0781c28fc3c23fb46430f9596746859aee9573b6 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 05:29:13 -0800
Subject: [PATCH 0033/2904] only define gem packaging tasks if rubygems is
already loaded
---
Rakefile | 140 +++++++++++++++++++++++++++----------------------------
1 file changed, 70 insertions(+), 70 deletions(-)
diff --git a/Rakefile b/Rakefile
index f4369ef1db..54875e6079 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,6 +5,11 @@ require 'fileutils'
task :default => :test
task :spec => :test
+def source_version
+ line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
+ line.match(/.*VERSION = '(.*)'/)[1]
+end
+
# SPECS ===============================================================
Rake::TestTask.new(:test) do |t|
@@ -12,50 +17,23 @@ Rake::TestTask.new(:test) do |t|
t.ruby_opts = ['-rubygems -I.'] if defined? Gem
end
-# PACKAGING ============================================================
-
-# Load the gemspec using the same limitations as github
-def spec
- require 'rubygems' unless defined? Gem::Specification
- @spec ||= eval(File.read('sinatra.gemspec'))
-end
-
-def package(ext='')
- "pkg/sinatra-#{spec.version}" + ext
-end
-
-desc 'Build packages'
-task :package => %w[.gem .tar.gz].map {|e| package(e)}
-
-desc 'Build and install as local gem'
-task :install => package('.gem') do
- sh "gem install #{package('.gem')}"
-end
-
-directory 'pkg/'
-CLOBBER.include('pkg')
-
-file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
- sh "gem build sinatra.gemspec"
- mv File.basename(f.name), f.name
-end
-
-file package('.tar.gz') => %w[pkg/] + spec.files do |f|
- sh <<-SH
- git archive \
- --prefix=sinatra-#{source_version}/ \
- --format=tar \
- HEAD | gzip > #{f.name}
- SH
+# Rcov ================================================================
+namespace :test do
+ desc 'Mesures test coverage'
+ task :coverage do
+ rm_f "coverage"
+ rcov = "rcov --text-summary --test-unit-only -Ilib"
+ system("#{rcov} --no-html --no-color test/*_test.rb")
+ end
end
-# Website ============================================================
+# Website =============================================================
# Building docs requires HAML and the hanna gem:
# gem install mislav-hanna --source=http://gems.github.com
+desc 'Generate RDoc under doc/api'
task 'doc' => ['doc:api']
-desc 'Generate Hanna RDoc under doc/api'
task 'doc:api' => ['doc/api/index.html']
file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
@@ -73,41 +51,63 @@ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
end
CLEAN.include 'doc/api'
-# Gemspec Helpers ====================================================
+# PACKAGING ============================================================
-def source_version
- line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
- line.match(/.*VERSION = '(.*)'/)[1]
-end
+if defined?(Gem)
+ # Load the gemspec using the same limitations as github
+ def spec
+ require 'rubygems' unless defined? Gem::Specification
+ @spec ||= eval(File.read('sinatra.gemspec'))
+ end
-task 'sinatra.gemspec' => FileList['{lib,test,compat}/**','Rakefile','CHANGES','*.rdoc'] do |f|
- # read spec file and split out manifest section
- spec = File.read(f.name)
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
- # replace version and date
- head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
- head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
- # determine file list from git ls-files
- files = `git ls-files`.
- split("\n").
- sort.
- reject{ |file| file =~ /^\./ }.
- reject { |file| file =~ /^doc/ }.
- map{ |file| " #{file}" }.
- join("\n")
- # piece file back together and write...
- manifest = " s.files = %w[\n#{files}\n ]\n"
- spec = [head,manifest,tail].join(" # = MANIFEST =\n")
- File.open(f.name, 'w') { |io| io.write(spec) }
- puts "updated #{f.name}"
-end
+ def package(ext='')
+ "pkg/sinatra-#{spec.version}" + ext
+ end
-# Rcov ==============================================================
-namespace :test do
- desc 'Mesures test coverage'
- task :coverage do
- rm_f "coverage"
- rcov = "rcov --text-summary --test-unit-only -Ilib"
- system("#{rcov} --no-html --no-color test/*_test.rb")
+ desc 'Build packages'
+ task :package => %w[.gem .tar.gz].map {|e| package(e)}
+
+ desc 'Build and install as local gem'
+ task :install => package('.gem') do
+ sh "gem install #{package('.gem')}"
+ end
+
+ directory 'pkg/'
+ CLOBBER.include('pkg')
+
+ file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
+ sh "gem build sinatra.gemspec"
+ mv File.basename(f.name), f.name
+ end
+
+ file package('.tar.gz') => %w[pkg/] + spec.files do |f|
+ sh <<-SH
+ git archive \
+ --prefix=sinatra-#{source_version}/ \
+ --format=tar \
+ HEAD | gzip > #{f.name}
+ SH
+ end
+
+ task 'sinatra.gemspec' => FileList['{lib,test,compat}/**','Rakefile','CHANGES','*.rdoc'] do |f|
+ # read spec file and split out manifest section
+ spec = File.read(f.name)
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
+ # replace version and date
+ head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
+ head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
+ # determine file list from git ls-files
+ files = `git ls-files`.
+ split("\n").
+ sort.
+ reject{ |file| file =~ /^\./ }.
+ reject { |file| file =~ /^doc/ }.
+ map{ |file| " #{file}" }.
+ join("\n")
+ # piece file back together and write...
+ manifest = " s.files = %w[\n#{files}\n ]\n"
+ spec = [head,manifest,tail].join(" # = MANIFEST =\n")
+ File.open(f.name, 'w') { |io| io.write(spec) }
+ puts "updated #{f.name}"
end
end
From f889c75cd4ac425f8b3041fc6ab75c01b7a9277b Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 06:05:10 -0800
Subject: [PATCH 0034/2904] reload_templates setting; on by default in
:development [#321]
Enabling the reload_templates setting causes template files to be
reread from disk and recompiled on each request. It's disabled by
default in all environments except for development.
---
CHANGES | 5 ++++-
lib/sinatra/base.rb | 4 +++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/CHANGES b/CHANGES
index ff999d0862..cfd71b7b07 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,9 +9,12 @@
template backtraces, and support for new template engines, like
mustache and liquid.
+ * New boolean 'reload_templates' setting controls whether template files
+ are reread from disk and recompiled on each request. Template read/compile
+ is cached by default in all environments except development.
+
* New 'settings' method gives access to options in both class and request
scopes. This replaces the 'options' method.
-
* New 'erubis' helper method for rendering Erubis templates.
* New 'expires' helper method is like cache_control but takes an
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 0f8eaa45d3..876e6f272c 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -387,6 +387,7 @@ def call!(env)
@request = Request.new(env)
@response = Response.new
@params = indifferent_params(@request.params)
+ @template_cache.clear if settings.reload_templates
invoke { dispatch! }
invoke { error_block!(response.status) }
@@ -1039,8 +1040,9 @@ def caller_locations
set :app_file, nil
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
- set :views, Proc.new { root && File.join(root, 'views') }
set :public, Proc.new { root && File.join(root, 'public') }
+ set :views, Proc.new { root && File.join(root, 'views') }
+ set :reload_templates, Proc.new { !development? }
set :lock, false
error ::Exception do
From ce3a8a89bbab4ef1eb64c1a833ce76ad08df91c7 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 06:13:08 -0800
Subject: [PATCH 0035/2904] rearrange a couple of bullets in CHANGES for easier
reading
---
CHANGES | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/CHANGES b/CHANGES
index cfd71b7b07..14348449eb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,16 +17,16 @@
scopes. This replaces the 'options' method.
* New 'erubis' helper method for rendering Erubis templates.
- * New 'expires' helper method is like cache_control but takes an
- integer number of seconds or Time object:
- expires 300, :public, :must_revalidate
-
* New 'cache_control' helper method provides a convenient way of
setting the Cache-Control response header. Takes a variable number
of boolean directives followed by a hash of value directives, like
this:
cache_control :public, :must_revalidate, :max_age => 60
+ * New 'expires' helper method is like cache_control but takes an
+ integer number of seconds or Time object:
+ expires 300, :public, :must_revalidate
+
* Sinatra apps can now be run with a `-h ` argument to specify
the address to bind to.
From 3ac8cb76da7f91dc93eb533c1b063592cb80f2b9 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 06:22:02 -0800
Subject: [PATCH 0036/2904] remove erubis test (let tilt handle this)
---
test/erubis_test.rb | 82 ---------------------------------------------
1 file changed, 82 deletions(-)
delete mode 100644 test/erubis_test.rb
diff --git a/test/erubis_test.rb b/test/erubis_test.rb
deleted file mode 100644
index 447f25fa21..0000000000
--- a/test/erubis_test.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require File.dirname(__FILE__) + '/helper'
-require 'erubis'
-
-class ERubisTest < Test::Unit::TestCase
- def erubis_app(&block)
- mock_app {
- set :views, File.dirname(__FILE__) + '/views'
- get '/', &block
- }
- get '/'
- end
-
- it 'renders inline ERubis strings' do
- erubis_app { erubis '<%= 1 + 1 %>' }
- assert ok?
- assert_equal '2', body
- end
-
- it 'renders .erubis files in views path' do
- erubis_app { erubis :hello }
- assert ok?
- assert_equal "Hello World\n", body
- end
-
- it 'takes a :locals option' do
- erubis_app {
- locals = {:foo => 'Bar'}
- erubis '<%= foo %>', :locals => locals
- }
- assert ok?
- assert_equal 'Bar', body
- end
-
- it "renders with inline layouts" do
- mock_app {
- layout { 'THIS. IS. <%= yield.upcase %>!' }
- get('/') { erubis 'Sparta' }
- }
- get '/'
- assert ok?
- assert_equal 'THIS. IS. SPARTA!', body
- end
-
- it "renders with file layouts" do
- erubis_app {
- erubis 'Hello World', :layout => :layout2
- }
- assert ok?
- assert_equal "ERubis Layout!\nHello World\n", body
- end
-
- it "renders erubis with blocks" do
- mock_app {
- def container
- @_out_buf << "THIS."
- yield
- @_out_buf << "SPARTA!"
- end
- def is; "IS." end
- get '/' do
- erubis '<% container do %> <%= is %> <% end %>'
- end
- }
- get '/'
- assert ok?
- assert_equal 'THIS. IS. SPARTA!', body
- end
-
- it "can be used in a nested fashion for partials and whatnot" do
- mock_app {
- template(:inner) { "<%= 'hi' %>" }
- template(:outer) { "<%= erubis :inner %>" }
- get '/' do
- erubis :outer
- end
- }
-
- get '/'
- assert ok?
- assert_equal 'hi', body
- end
-end
From 99378cdb5dbaf81bb6f87ef290e848cdbb59d380 Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 06:32:49 -0800
Subject: [PATCH 0037/2904] bump shotgun devel dependency to 0.6
---
sinatra.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sinatra.gemspec b/sinatra.gemspec
index 6b79cae98d..f0d4f71e4d 100644
--- a/sinatra.gemspec
+++ b/sinatra.gemspec
@@ -76,7 +76,7 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
s.add_dependency 'rack', '>= 1.0'
- s.add_development_dependency 'shotgun', '>= 0.3', '< 1.0'
+ s.add_development_dependency 'shotgun', '>= 0.6', '< 1.0'
s.add_development_dependency 'rack-test', '>= 0.3.0'
s.has_rdoc = true
From 473c112764174aef65b32857a9ecd8967934083c Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Thu, 28 Jan 2010 06:33:12 -0800
Subject: [PATCH 0038/2904] add devel dependencies for template engines we test
---
sinatra.gemspec | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sinatra.gemspec b/sinatra.gemspec
index f0d4f71e4d..7c25e8c857 100644
--- a/sinatra.gemspec
+++ b/sinatra.gemspec
@@ -78,6 +78,9 @@ Gem::Specification.new do |s|
s.add_dependency 'rack', '>= 1.0'
s.add_development_dependency 'shotgun', '>= 0.6', '< 1.0'
s.add_development_dependency 'rack-test', '>= 0.3.0'
+ s.add_development_dependency 'haml'
+ s.add_development_dependency 'builder'
+ s.add_development_dependency 'erubis'
s.has_rdoc = true
s.homepage = "http://sinatra.rubyforge.org"
From d8af6c48d23ef2e4e2d393b29143f0d577a6f20b Mon Sep 17 00:00:00 2001
From: Ryan Tomayko
Date: Mon, 26 Oct 2009 04:32:58 -0700
Subject: [PATCH 0039/2904] add height/width to showexceptions spill image
---
lib/sinatra/showexceptions.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/sinatra/showexceptions.rb b/lib/sinatra/showexceptions.rb
index 477f0c4cbe..3ef43966ae 100644
--- a/lib/sinatra/showexceptions.rb
+++ b/lib/sinatra/showexceptions.rb
@@ -137,7 +137,7 @@ def frame_class(frame)