closes #9779 Auto-require haml/erb/builder/sass

this is causing thread-saftey issues.
This commit is contained in:
Blake Mizerany 2009-04-24 17:10:46 -07:00
parent 64d852ea6f
commit 801163e9f3
5 changed files with 21 additions and 4 deletions

View File

@ -118,6 +118,9 @@ any strings passed to them directly.
The haml gem/library is required to render HAML templates:
## You'll need to require haml in your app
require 'haml'
get '/' do
haml :index
end
@ -138,6 +141,9 @@ and overridden on an individual basis.
=== Erb Templates
## You'll need to require erb in your app
require 'erb'
get '/' do
erb :index
end
@ -148,6 +154,9 @@ Renders <tt>./views/index.erb</tt>
The builder gem/library is required to render builder templates:
## You'll need to require builder in your app
require 'builder'
get '/' do
content_type 'application/xml', :charset => 'utf-8'
builder :index
@ -159,6 +168,9 @@ Renders <tt>./views/index.builder</tt>.
The sass gem/library is required to render Sass templates:
## You'll need to require haml or sass in your app
require 'sass'
get '/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8'
sass :stylesheet

View File

@ -1,6 +1,10 @@
require 'rubygems'
require 'mocha'
require 'haml'
require 'sass'
require 'builder'
# disable warnings in compat specs.
$VERBOSE = nil

View File

@ -223,23 +223,19 @@ module Sinatra
# in the template
module Templates
def erb(template, options={}, locals={})
require 'erb' unless defined? ::ERB
render :erb, template, options, locals
end
def haml(template, options={}, locals={})
require 'haml' unless defined? ::Haml::Engine
render :haml, template, options, locals
end
def sass(template, options={}, locals={})
require 'sass' unless defined? ::Sass::Engine
options[:layout] = false
render :sass, template, options, locals
end
def builder(template=nil, options={}, locals={}, &block)
require 'builder' unless defined? ::Builder
options, template = template, nil if template.is_a?(Hash)
template = lambda { block } if template.nil?
render :builder, template, options, locals

View File

@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/helper'
require 'haml'
class HAMLTest < Test::Unit::TestCase
def haml_app(&block)

View File

@ -14,6 +14,10 @@ $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