Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecation warning for auto-require of template engines

  • Loading branch information...
commit 7030e25066c19d413f189642fee1c20f2483267d 1 parent 4f30c1c
@sr sr authored rtomayko committed
View
4 compat/helper.rb
@@ -1,10 +1,6 @@
require 'rubygems'
require 'mocha'
-require 'haml'
-require 'sass'
-require 'builder'
-
# disable warnings in compat specs.
$VERBOSE = nil
View
13 lib/sinatra/base.rb
@@ -223,19 +223,27 @@ def back ; request.referer ; end
# 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 @@ def render_builder(template, data, options, locals, &block)
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.
View
1  test/builder_test.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/helper'
+require 'builder'
class BuilderTest < Test::Unit::TestCase
def builder_app(&block)
View
4 test/helper.rb
@@ -16,10 +16,6 @@
require 'contest'
require 'sinatra/test'
-require 'haml'
-require 'sass'
-require 'builder'
-
class Sinatra::Base
# Allow assertions in request context
include Test::Unit::Assertions
View
1  test/sass_test.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/helper'
+require 'sass'
class SassTest < Test::Unit::TestCase
def sass_app(&block)
Please sign in to comment.
Something went wrong with that request. Please try again.