From 6de88a832e065bbf93b494b96010bef833d7d914 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 27 Nov 2015 15:41:42 -0800 Subject: [PATCH] Make Ruby Sass the default, but use SassC if available. Addresses #1648 --- Gemfile | 1 + .../lib/middleman-core/renderers/sass.rb | 17 ++++++++--------- .../middleman-core/renderers/sass_functions.rb | 8 +++++++- middleman-core/middleman-core.gemspec | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index e91581b9..f497569a 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'cucumber', '~> 2.0', require: false # Optional middleman dependencies, included for tests gem 'haml', '>= 4.0.5', require: false +gem 'sassc', '~> 1.8' gem 'coffee-script', '~> 2.2', require: false gem 'kramdown', '~> 1.2', require: false gem 'slim', '>= 2.0', require: false diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index cf373408..1b57c292 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -1,12 +1,5 @@ require 'sass' -SASS_MODULE = begin - require 'sassc' - ::SassC -rescue LoadError => e - ::Sass -end - module Middleman module Renderers # Sass renderer @@ -59,11 +52,17 @@ module Middleman def evaluate(context, _) @context ||= context - @engine = SASS_MODULE::Engine.new(data, sass_options) + sass_module = if defined?(::SassC) + ::SassC + else + ::Sass + end + + @engine = sass_module::Engine.new(data, sass_options) begin @engine.render - rescue SASS_MODULE::SyntaxError => e + rescue sass_module::SyntaxError => e ::Sass::SyntaxError.exception_to_css(e) end end diff --git a/middleman-core/lib/middleman-core/renderers/sass_functions.rb b/middleman-core/lib/middleman-core/renderers/sass_functions.rb index 2e71c8f9..2a587b50 100644 --- a/middleman-core/lib/middleman-core/renderers/sass_functions.rb +++ b/middleman-core/lib/middleman-core/renderers/sass_functions.rb @@ -105,7 +105,13 @@ module Middleman end end -::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions +SASS_MODULE = if defined?(::SassC) + ::SassC +else + ::Sass +end + +SASS_MODULE::Script::Functions.send :include, ::Middleman::Sass::Functions # module SASS_MODULE::Script::Functions # include ::Middleman::Sass::Functions diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index e910d6b9..a58e33c6 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -42,7 +42,7 @@ Gem::Specification.new do |s| s.add_dependency('fastimage', ['~> 1.7.0']) # Minify CSS - s.add_dependency('sassc', ['>= 1.6.0']) + s.add_dependency('sass', ['>= 3.4']) # Minify JS s.add_dependency('uglifier', ['~> 2.6'])