[DRE-commits] [SCM] ruby-sinatra-contrib.git branch, master, updated. upstream/1.3.1-13-ge1e3940
Jérémy Bobbio
lunar at debian.org
Sat Mar 16 07:57:44 UTC 2013
The following commit has been merged in the master branch:
commit 89b8127a8760278641c05d72d6c3b35e3f29678e
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Mar 14 22:44:50 2013 +0100
Imported Upstream version 1.3.2
diff --git a/README.md b/README.md
index 2baa473..a53896d 100644
--- a/README.md
+++ b/README.md
@@ -127,7 +127,7 @@ All extensions:
``` ruby
require 'sinatra/base'
-require 'sinatra/contrib'
+require 'sinatra/contrib/all'
class MyApp < Sinatra::Base
register Sinatra::Contrib
diff --git a/lib/sinatra/content_for.rb b/lib/sinatra/content_for.rb
index a3d9995..7729271 100644
--- a/lib/sinatra/content_for.rb
+++ b/lib/sinatra/content_for.rb
@@ -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 Sinatra
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:
#
diff --git a/lib/sinatra/cookies.rb b/lib/sinatra/cookies.rb
index d91ad35..4cdf24d 100644
--- a/lib/sinatra/cookies.rb
+++ b/lib/sinatra/cookies.rb
@@ -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
diff --git a/lib/sinatra/namespace.rb b/lib/sinatra/namespace.rb
index 28c1477..d361ca5 100644
--- a/lib/sinatra/namespace.rb
+++ b/lib/sinatra/namespace.rb
@@ -20,7 +20,7 @@ module Sinatra
# You can define a namespace by a path prefix:
#
# namespace '/blog' do
- # get() { haml :blog }
+ # get { haml :blog }
# get '/:entry_permalink' do
# @entry = Entry.find_by_permalink!(params[:entry_permalink])
# haml :entry
@@ -118,7 +118,7 @@ module Sinatra
Module.new do
extend NamespacedMethods
include InstanceMethods
- @base, @extensions = base, []
+ @base, @extensions, @errors = base, [], {}
@pattern, @conditions = compile(pattern, conditions)
@templates = Hash.new { |h,k| @base.templates[k] }
namespace = self
@@ -135,14 +135,6 @@ module Sinatra
def template_cache
super.fetch(:nested, @namespace) { Tilt::Cache.new }
end
-
- def error_block!(*keys)
- if block = keys.inject(nil) { |b,k| b ||= @namespace.errors[k] }
- instance_eval(&block)
- else
- super
- end
- end
end
module SharedMethods
@@ -180,16 +172,23 @@ module Sinatra
@extensions.each { |e| e.send(name, *args) if e.respond_to?(name) }
end
- def errors
- @errors ||= {}
- end
-
def not_found(&block)
error(404, &block)
end
- def error(codes = Exception, &block)
- [*codes].each { |c| errors[c] = block }
+ def errors
+ base.errors.merge(@errors)
+ end
+
+ def namespace_errors
+ @errors
+ end
+
+ def error(*codes, &block)
+ args = Sinatra::Base.send(:compile!, "ERROR", /^#{@pattern}/, block)
+ codes = codes.map { |c| Array(c) }.flatten
+ codes << Exception if codes.empty?
+ codes.each { |c| @errors[c] = args }
end
def respond_to(*args)
diff --git a/lib/sinatra/reloader.rb b/lib/sinatra/reloader.rb
index da40fb3..ef6b436 100644
--- a/lib/sinatra/reloader.rb
+++ b/lib/sinatra/reloader.rb
@@ -210,6 +210,7 @@ module Sinatra
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 @@ module Sinatra
# 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.
diff --git a/lib/sinatra/streaming.rb b/lib/sinatra/streaming.rb
index 5d796bc..4072b3b 100644
--- a/lib/sinatra/streaming.rb
+++ b/lib/sinatra/streaming.rb
@@ -32,7 +32,7 @@ module Sinatra
# list = []
#
# get '/' do
- # stream(false) do |out|
+ # stream(:keep_open) do |out|
# list << out
# out.callback { list.delete out }
# out.errback do
@@ -91,7 +91,7 @@ module Sinatra
# require "sinatra/streaming"
#
# class MyApp < Sinatra::Base
- # helpers Streaming
+ # helpers Sinatra::Streaming
# end
module Streaming
def stream(*)
diff --git a/metadata.yml b/metadata.yml
index 3b761de..9b8e41e 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,25 +1,32 @@
--- !ruby/object:Gem::Specification
name: sinatra-contrib
version: !ruby/object:Gem::Version
- version: 1.3.1
+ version: 1.3.2
prerelease:
platform: ruby
authors:
- Konstantin Haase
- Gabriel Andretta
+- Trevor Bramble
- Nicolas Sanguinetti
-- Eliot Shepard
+- Ilya Shindyapin
+- Masahiro Fujiwara
+- Adrian Pacała
- Andrew Crump
+- Eliot Shepard
+- Eric Marden
+- Gray Manley
- Matt Lyon
+- lest
- undr
autorequire:
bindir: bin
cert_chain: []
-date: 2011-10-01 00:00:00.000000000Z
+date: 2012-10-22 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: sinatra
- requirement: &2153005720 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
@@ -27,10 +34,15 @@ dependencies:
version: 1.3.0
type: :runtime
prerelease: false
- version_requirements: *2153005720
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ~>
+ - !ruby/object:Gem::Version
+ version: 1.3.0
- !ruby/object:Gem::Dependency
name: backports
- requirement: &2153005140 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -38,10 +50,15 @@ dependencies:
version: '2.0'
type: :runtime
prerelease: false
- version_requirements: *2153005140
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '2.0'
- !ruby/object:Gem::Dependency
name: tilt
- requirement: &2153004220 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
@@ -49,10 +66,15 @@ dependencies:
version: '1.3'
type: :runtime
prerelease: false
- version_requirements: *2153004220
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ~>
+ - !ruby/object:Gem::Version
+ version: '1.3'
- !ruby/object:Gem::Dependency
name: rack-test
- requirement: &2153003320 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -60,10 +82,15 @@ dependencies:
version: '0'
type: :runtime
prerelease: false
- version_requirements: *2153003320
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: rack-protection
- requirement: &2153002460 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -71,10 +98,15 @@ dependencies:
version: '0'
type: :runtime
prerelease: false
- version_requirements: *2153002460
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: eventmachine
- requirement: &2153002020 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -82,10 +114,15 @@ dependencies:
version: '0'
type: :runtime
prerelease: false
- version_requirements: *2153002020
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: rspec
- requirement: &2153001220 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
@@ -93,10 +130,15 @@ dependencies:
version: '2.3'
type: :development
prerelease: false
- version_requirements: *2153001220
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ~>
+ - !ruby/object:Gem::Version
+ version: '2.3'
- !ruby/object:Gem::Dependency
name: haml
- requirement: &2153000680 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -104,10 +146,15 @@ dependencies:
version: '0'
type: :development
prerelease: false
- version_requirements: *2153000680
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: erubis
- requirement: &2152999920 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -115,10 +162,15 @@ dependencies:
version: '0'
type: :development
prerelease: false
- version_requirements: *2152999920
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: slim
- requirement: &2152999280 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -126,10 +178,15 @@ dependencies:
version: '0'
type: :development
prerelease: false
- version_requirements: *2152999280
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
- !ruby/object:Gem::Dependency
name: rake
- requirement: &2152998780 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
@@ -137,15 +194,27 @@ dependencies:
version: '0'
type: :development
prerelease: false
- version_requirements: *2152998780
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
description: Collection of useful Sinatra extensions
email:
- konstantin.mailinglists at googlemail.com
- ohhgabriel at gmail.com
+- inbox at trevorbramble.com
- contacto at nicolassanguinetti.info
-- eshepard at slower.net
+- ilya at shindyapin.com
+- m-fujiwara at axsh.net
+- altpacala at gmail.com
- andrew.crump at ieee.org
+- eshepard at slower.net
+- eric.marden at gmail.com
+- g.manley at tukaiz.com
- matt at flowerpowered.com
+- just.lest at gmail.com
- undr at yandex.ru
executables: []
extensions: []
@@ -186,6 +255,10 @@ files:
- spec/content_for/different_key.erubis
- spec/content_for/different_key.haml
- spec/content_for/different_key.slim
+- spec/content_for/footer.erb
+- spec/content_for/footer.erubis
+- spec/content_for/footer.haml
+- spec/content_for/footer.slim
- spec/content_for/layout.erb
- spec/content_for/layout.erubis
- spec/content_for/layout.haml
@@ -250,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
version: '0'
requirements: []
rubyforge_project:
-rubygems_version: 1.8.10
+rubygems_version: 1.8.24
signing_key:
specification_version: 3
summary: Collection of useful Sinatra extensions
diff --git a/sinatra-contrib.gemspec b/sinatra-contrib.gemspec
index d3bd16a..0ca679e 100644
--- a/sinatra-contrib.gemspec
+++ b/sinatra-contrib.gemspec
@@ -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
@@ -10,10 +10,17 @@ Gem::Specification.new do |s|
s.authors = [
"Konstantin Haase",
"Gabriel Andretta",
+ "Trevor Bramble",
"Nicolas Sanguinetti",
- "Eliot Shepard",
+ "Ilya Shindyapin",
+ "Masahiro Fujiwara",
+ "Adrian Pacała",
"Andrew Crump",
+ "Eliot Shepard",
+ "Eric Marden",
+ "Gray Manley",
"Matt Lyon",
+ "lest",
"undr"
]
@@ -21,10 +28,17 @@ Gem::Specification.new do |s|
s.email = [
"konstantin.mailinglists at googlemail.com",
"ohhgabriel at gmail.com",
+ "inbox at trevorbramble.com",
"contacto at nicolassanguinetti.info",
- "eshepard at slower.net",
+ "ilya at shindyapin.com",
+ "m-fujiwara at axsh.net",
+ "altpacala at gmail.com",
"andrew.crump at ieee.org",
+ "eshepard at slower.net",
+ "eric.marden at gmail.com",
+ "g.manley at tukaiz.com",
"matt at flowerpowered.com",
+ "just.lest at gmail.com",
"undr at yandex.ru"
]
@@ -65,6 +79,10 @@ Gem::Specification.new do |s|
"spec/content_for/different_key.erubis",
"spec/content_for/different_key.haml",
"spec/content_for/different_key.slim",
+ "spec/content_for/footer.erb",
+ "spec/content_for/footer.erubis",
+ "spec/content_for/footer.haml",
+ "spec/content_for/footer.slim",
"spec/content_for/layout.erb",
"spec/content_for/layout.erubis",
"spec/content_for/layout.haml",
diff --git a/spec/content_for/footer.erb b/spec/content_for/footer.erb
new file mode 100644
index 0000000..d5a77c9
--- /dev/null
+++ b/spec/content_for/footer.erb
@@ -0,0 +1,3 @@
+<% if content_for? :foo %>
+ <%= yield_content :foo %>
+<% end %>
\ No newline at end of file
diff --git a/spec/content_for/footer.erubis b/spec/content_for/footer.erubis
new file mode 100644
index 0000000..d5a77c9
--- /dev/null
+++ b/spec/content_for/footer.erubis
@@ -0,0 +1,3 @@
+<% if content_for? :foo %>
+ <%= yield_content :foo %>
+<% end %>
\ No newline at end of file
diff --git a/spec/content_for/footer.haml b/spec/content_for/footer.haml
new file mode 100644
index 0000000..395bb2b
--- /dev/null
+++ b/spec/content_for/footer.haml
@@ -0,0 +1,2 @@
+- if content_for? :foo
+ = yield_content :foo
\ No newline at end of file
diff --git a/spec/content_for/footer.slim b/spec/content_for/footer.slim
new file mode 100644
index 0000000..395bb2b
--- /dev/null
+++ b/spec/content_for/footer.slim
@@ -0,0 +1,2 @@
+- if content_for? :foo
+ = yield_content :foo
\ No newline at end of file
diff --git a/spec/content_for_spec.rb b/spec/content_for_spec.rb
index 23a494b..b318ac2 100644
--- a/spec/content_for_spec.rb
+++ b/spec/content_for_spec.rb
@@ -138,6 +138,18 @@ describe Sinatra::ContentFor do
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
diff --git a/spec/namespace_spec.rb b/spec/namespace_spec.rb
index 1ca2e38..f140e28 100644
--- a/spec/namespace_spec.rb
+++ b/spec/namespace_spec.rb
@@ -487,6 +487,48 @@ describe Sinatra::Namespace do
get('/de/foo').status.should == 404
last_response.body.should == 'nicht gefunden' unless verb == :head
end
+
+ it "should handle custom errors in base. Issue #37." do
+ mock_app {
+ error(404) { 'not found...' }
+ namespace('/en') do
+ end
+ namespace('/de') do
+ error(404) { 'nicht gefunden' }
+ end
+ }
+ send(verb, '/foo').status.should == 404
+ last_response.body.should == 'not found...' unless verb == :head
+ get('/en/foo').status.should == 404
+ last_response.body.should == 'not found...' unless verb == :head
+ get('/de/foo').status.should == 404
+ last_response.body.should == 'nicht gefunden' unless verb == :head
+ end
+
+ it "should allow custom error handlers with Exception class. Issue #37." do
+ mock_app {
+ class AError < StandardError; end
+ class BError < AError; end
+
+ error(AError) { body('auth failed'); 401}
+ namespace('/en') do
+ get '/foo' do
+ raise BError
+ end
+ end
+ namespace('/de') do
+ error(AError) { body('methode nicht erlaubt'); 406}
+
+ get '/foo' do
+ raise BError
+ end
+ end
+ }
+ get('/en/foo').status.should == 401
+ last_response.body.should == 'auth failed' unless verb == :head
+ get('/de/foo').status.should == 406
+ last_response.body.should == 'methode nicht erlaubt' unless verb == :head
+ end
end
describe 'templates' do
diff --git a/spec/reloader_spec.rb b/spec/reloader_spec.rb
index 6850e88..2ec6679 100644
--- a/spec/reloader_spec.rb
+++ b/spec/reloader_spec.rb
@@ -11,14 +11,14 @@ describe Sinatra::Reloader do
# Returns the path of the Sinatra application file created by
# +setup_example_app+.
def app_file_path
- File.join(tmp_dir, "example_app_#{@@example_app_counter}.rb")
+ File.join(tmp_dir, "example_app_#{$example_app_counter}.rb")
end
# Returns the name of the Sinatra application created by
# +setup_example_app+: 'ExampleApp1' for the first application,
# 'ExampleApp2' fo the second one, and so on...
def app_name
- "ExampleApp#{@@example_app_counter}"
+ "ExampleApp#{$example_app_counter}"
end
# Returns the (constant of the) Sinatra application created by
@@ -70,8 +70,8 @@ describe Sinatra::Reloader do
# the new application as the one being tested and enables the
# reloader.
def setup_example_app(options={})
- @@example_app_counter ||= 0
- @@example_app_counter += 1
+ $example_app_counter ||= 0
+ $example_app_counter += 1
FileUtils.mkdir_p(tmp_dir)
write_app_file(options)
--
ruby-sinatra-contrib.git
More information about the Pkg-ruby-extras-commits
mailing list