Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

this is causing thread-saftey issues.
  • Loading branch information...
commit 801163e9f3d1e0452054dbccf9f876f62bf022a0 1 parent 64d852e
@bmizerany bmizerany authored
View
12 README.rdoc
@@ -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
4 compat/helper.rb
@@ -1,6 +1,10 @@
require 'rubygems'
require 'mocha'
+require 'haml'
+require 'sass'
+require 'builder'
+
# disable warnings in compat specs.
$VERBOSE = nil
View
4 lib/sinatra/base.rb
@@ -223,23 +223,19 @@ def back ; request.referer ; end
# 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
1  test/haml_test.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/helper'
+require 'haml'
class HAMLTest < Test::Unit::TestCase
def haml_app(&block)
View
4 test/helper.rb
@@ -14,6 +14,10 @@
require 'contest'
require 'sinatra/test'
+require 'haml'
+require 'sass'
+require 'builder'
+
class Sinatra::Base
# Allow assertions in request context
include Test::Unit::Assertions

1 comment on commit 801163e

@halorgium

Perhaps this should "disable" the helper methods if the code isn't loaded.

raise 'haml is not loaded...' unless defined? ::Haml::Engine

Please sign in to comment.
Something went wrong with that request. Please try again.