Skip to content

Commit

Permalink
closes #9779 Auto-require haml/erb/builder/sass
Browse files Browse the repository at this point in the history
this is causing thread-saftey issues.
  • Loading branch information
bmizerany committed Apr 25, 2009
1 parent 64d852e commit 801163e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.rdoc
Expand Up @@ -118,6 +118,9 @@ any strings passed to them directly.


The haml gem/library is required to render HAML templates: The haml gem/library is required to render HAML templates:


## You'll need to require haml in your app
require 'haml'

get '/' do get '/' do
haml :index haml :index
end end
Expand All @@ -138,6 +141,9 @@ and overridden on an individual basis.


=== Erb Templates === Erb Templates


## You'll need to require erb in your app
require 'erb'

get '/' do get '/' do
erb :index erb :index
end end
Expand All @@ -148,6 +154,9 @@ Renders <tt>./views/index.erb</tt>


The builder gem/library is required to render builder templates: The builder gem/library is required to render builder templates:


## You'll need to require builder in your app
require 'builder'

get '/' do get '/' do
content_type 'application/xml', :charset => 'utf-8' content_type 'application/xml', :charset => 'utf-8'
builder :index builder :index
Expand All @@ -159,6 +168,9 @@ Renders <tt>./views/index.builder</tt>.


The sass gem/library is required to render Sass templates: 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 get '/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8' content_type 'text/css', :charset => 'utf-8'
sass :stylesheet sass :stylesheet
Expand Down
4 changes: 4 additions & 0 deletions compat/helper.rb
@@ -1,6 +1,10 @@
require 'rubygems' require 'rubygems'
require 'mocha' require 'mocha'


require 'haml'
require 'sass'
require 'builder'

# disable warnings in compat specs. # disable warnings in compat specs.
$VERBOSE = nil $VERBOSE = nil


Expand Down
4 changes: 0 additions & 4 deletions lib/sinatra/base.rb
Expand Up @@ -223,23 +223,19 @@ def back ; request.referer ; end
# in the template # in the template
module Templates module Templates
def erb(template, options={}, locals={}) def erb(template, options={}, locals={})
require 'erb' unless defined? ::ERB
render :erb, template, options, locals render :erb, template, options, locals
end end


def haml(template, options={}, locals={}) def haml(template, options={}, locals={})
require 'haml' unless defined? ::Haml::Engine
render :haml, template, options, locals render :haml, template, options, locals
end end


def sass(template, options={}, locals={}) def sass(template, options={}, locals={})
require 'sass' unless defined? ::Sass::Engine
options[:layout] = false options[:layout] = false
render :sass, template, options, locals render :sass, template, options, locals
end end


def builder(template=nil, options={}, locals={}, &block) def builder(template=nil, options={}, locals={}, &block)
require 'builder' unless defined? ::Builder
options, template = template, nil if template.is_a?(Hash) options, template = template, nil if template.is_a?(Hash)
template = lambda { block } if template.nil? template = lambda { block } if template.nil?
render :builder, template, options, locals render :builder, template, options, locals
Expand Down
1 change: 1 addition & 0 deletions test/haml_test.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
require 'haml'


class HAMLTest < Test::Unit::TestCase class HAMLTest < Test::Unit::TestCase
def haml_app(&block) def haml_app(&block)
Expand Down
4 changes: 4 additions & 0 deletions test/helper.rb
Expand Up @@ -14,6 +14,10 @@
require 'contest' require 'contest'
require 'sinatra/test' require 'sinatra/test'


require 'haml'
require 'sass'
require 'builder'

class Sinatra::Base class Sinatra::Base
# Allow assertions in request context # Allow assertions in request context
include Test::Unit::Assertions include Test::Unit::Assertions
Expand Down

1 comment on commit 801163e

@halorgium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.