Permalink
Browse files

Do not add Sass functions if sprockets-helpers is not available

  • Loading branch information...
1 parent b71de63 commit 3ab05c639019254e7a30cadffe9199c90a890499 @petebrowne committed Sep 28, 2012
Showing with 36 additions and 6 deletions.
  1. +18 −5 lib/sprockets/sass/sass_template.rb
  2. +18 −1 spec/sprockets-sass_spec.rb
View
23 lib/sprockets/sass/sass_template.rb
@@ -8,18 +8,31 @@ class SassTemplate < Tilt::SassTemplate
# A reference to the current Sprockets context
attr_reader :context
- # Templates are initialized once the functions are added.
- def self.engine_initialized?
- super && (!Sass.add_sass_functions || defined?(Functions))
+ # Determines if the Sass functions have been initialized.
+ # They can be 'initialized' without actually being added.
+ @sass_functions_initialized = false
+ class << self
+ attr_accessor :sass_functions_initialized
+ alias :sass_functions_initialized? :sass_functions_initialized
+
+ # Templates are initialized once the functions are added.
+ def engine_initialized?
+ super && sass_functions_initialized?
+ end
end
# Add the Sass functions if they haven't already been added.
def initialize_engine
super unless self.class.superclass.engine_initialized?
- if Sass.add_sass_functions
- require 'sprockets/sass/functions'
+ if Sass.add_sass_functions != false
+ begin
+ require 'sprockets/helpers'
+ require 'sprockets/sass/functions'
+ rescue LoadError; end
end
+
+ self.class.sass_functions_initialized = true
end
# Define the expected syntax for the template
View
19 spec/sprockets-sass_spec.rb
@@ -320,12 +320,29 @@
template.initialize_engine
end
- it "does not initializes super if super is initinalized to silence warnings" do
+ it 'does not initializes super if super is initinalized to silence warnings' do
Tilt::SassTemplate.stub(:engine_initialized?).and_return true
template = Sprockets::Sass::SassTemplate.new {}
template.should_not_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
template.initialize_engine
end
+
+ it 'does not add Sass functions if sprockets-helpers is not available' do
+ template = Sprockets::Sass::SassTemplate.new {}
+ template.should_receive(:require).with('sprockets/helpers').and_raise LoadError
+ template.should_not_receive(:require).with 'sprockets/sass/functions'
+ template.initialize_engine
+ Sprockets::Sass::SassTemplate.engine_initialized?.should be_true
+ end
+
+ it 'does not add Sass functions if add_sass_functions is false' do
+ Sprockets::Sass.add_sass_functions = false
+ template = Sprockets::Sass::SassTemplate.new {}
+ template.should_not_receive(:require).with 'sprockets/sass/functions'
+ template.initialize_engine
+ Sprockets::Sass::SassTemplate.engine_initialized?.should be_true
+ Sprockets::Sass.add_sass_functions = true
+ end
end
end
end

0 comments on commit 3ab05c6

Please sign in to comment.