From 7030e25066c19d413f189642fee1c20f2483267d Mon Sep 17 00:00:00 2001 From: Simon Rozet Date: Sat, 2 May 2009 14:49:43 +0200 Subject: [PATCH] Deprecation warning for auto-require of template engines --- compat/helper.rb | 4 ---- lib/sinatra/base.rb | 13 +++++++++++++ test/builder_test.rb | 1 + test/helper.rb | 4 ---- test/sass_test.rb | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compat/helper.rb b/compat/helper.rb index 562a75b9..420c484c 100644 --- a/compat/helper.rb +++ b/compat/helper.rb @@ -1,10 +1,6 @@ require 'rubygems' require 'mocha' -require 'haml' -require 'sass' -require 'builder' - # disable warnings in compat specs. $VERBOSE = nil diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index e3c4376e..14284f63 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -223,19 +223,27 @@ module Sinatra # in the template module Templates def erb(template, options={}, locals={}) + require_warn('ERB') unless defined?(::ERB) + render :erb, template, options, locals end def haml(template, options={}, locals={}) + require_warn('Haml') unless defined?(::Haml::Engine) + render :haml, template, options, locals end def sass(template, options={}, locals={}) + require_warn('Sass') unless defined?(::Sass::Engine) + options[:layout] = false render :sass, template, options, locals end def builder(template=nil, options={}, locals={}, &block) + require_warn('Builder') unless defined?(::Builder) + options, template = template, nil if template.is_a?(Hash) template = lambda { block } if template.nil? render :builder, template, options, locals @@ -331,6 +339,11 @@ module Sinatra end xml.target! end + + def require_warn(engine) + warn "Auto-require of #{engine} is deprecated; add require '#{engine}' to your app." + require engine.downcase + end end # Base class for all Sinatra applications and middleware. diff --git a/test/builder_test.rb b/test/builder_test.rb index 0977a0c0..04ab3a58 100644 --- a/test/builder_test.rb +++ b/test/builder_test.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/helper' +require 'builder' class BuilderTest < Test::Unit::TestCase def builder_app(&block) diff --git a/test/helper.rb b/test/helper.rb index ed12d982..08f526aa 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -16,10 +16,6 @@ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir) require 'contest' require 'sinatra/test' -require 'haml' -require 'sass' -require 'builder' - class Sinatra::Base # Allow assertions in request context include Test::Unit::Assertions diff --git a/test/sass_test.rb b/test/sass_test.rb index 4b37e01e..c8d6a731 100644 --- a/test/sass_test.rb +++ b/test/sass_test.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/helper' +require 'sass' class SassTest < Test::Unit::TestCase def sass_app(&block)