diff --git a/CHANGELOG.md b/CHANGELOG.md index ba00507b..41b5ad1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ master === +* Only SassC from now on. * Add `--dry-run` to run a build, but skip outputting to disk. * Incremental builds: `--track-dependencies` and `--only-changed` flags (#2220) * Remove Rack support in favor of `resource.filters << proc { |oldbody| newbody }` diff --git a/Gemfile.lock b/Gemfile.lock index bc35a7ad..f1987268 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,7 +27,6 @@ PATH parallel rack (>= 1.4.5, < 3) rgl (~> 0.5.3) - sass (>= 3.4) sassc (~> 2.0) servolux tilt (~> 2.0.9) @@ -198,11 +197,6 @@ GEM celluloid (= 0.16.0) celluloid-io (= 0.16.2) timers (~> 4.0.1) - sass (3.7.2) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) sassc (2.0.0) ffi (~> 1.9.6) rake diff --git a/middleman-core/features/scss-support.feature b/middleman-core/features/scss-support.feature index 0b380f06..6dff8d09 100644 --- a/middleman-core/features/scss-support.feature +++ b/middleman-core/features/scss-support.feature @@ -9,4 +9,9 @@ Feature: Support SCSS Syntax Scenario: Rendering scss Given the Server is running at "scss-app" When I go to "/stylesheets/layout.css" - Then I should see "html" \ No newline at end of file + Then I should see "html" + + Scenario: Rendering scss errors + Given the Server is running at "scss-app" + When I go to "/stylesheets/error.css" + Then I should see "Error:" \ No newline at end of file diff --git a/middleman-core/fixtures/scss-app/source/stylesheets/error.css.sass b/middleman-core/fixtures/scss-app/source/stylesheets/error.css.sass new file mode 100644 index 00000000..fc6f4bd0 --- /dev/null +++ b/middleman-core/fixtures/scss-app/source/stylesheets/error.css.sass @@ -0,0 +1 @@ +@include invalid-mixin; \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/extensions/minify_css.rb b/middleman-core/lib/middleman-core/extensions/minify_css.rb index ba99748f..2859d784 100644 --- a/middleman-core/lib/middleman-core/extensions/minify_css.rb +++ b/middleman-core/lib/middleman-core/extensions/minify_css.rb @@ -2,13 +2,13 @@ require 'active_support/core_ext/object/try' require 'memoist' require 'middleman-core/contracts' require 'rack/mime' +require 'sassc' # Minify CSS Extension class Middleman::Extensions::MinifyCss < ::Middleman::Extension option :inline, false, 'Whether to minify CSS inline within HTML files' option :ignore, [], 'Patterns to avoid minifying' option :compressor, proc { - require 'sass' SassCompressor }, 'Set the CSS compressor to use.' option :content_types, %w[text/css], 'Content types of resources that contain CSS' @@ -20,15 +20,13 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension COMPRESSED_OPTIONS = { style: :compressed }.freeze def self.compress(style, options_hash = ::Middleman::EMPTY_HASH) - root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse + options = if options_hash == ::Middleman::EMPTY_HASH + COMPRESSED_OPTIONS + else + options_hash.merge(COMPRESSED_OPTIONS) + end - root_node.options = if options_hash == ::Middleman::EMPTY_HASH - COMPRESSED_OPTIONS - else - options_hash.merge(COMPRESSED_OPTIONS) - end - - root_node.render.strip + ::SassC::Engine.new(style, options).render.strip end end diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index 117d5e9c..970b0010 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -1,13 +1,8 @@ require 'hamster' -require 'sass' +require 'sassc' require 'middleman-core/dependencies' require 'middleman-core/dependencies/vertices/file_vertex' -begin - require 'sassc' -rescue LoadError -end - module Middleman module Renderers # Sass renderer @@ -25,8 +20,6 @@ module Middleman def initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block) super - logger.info '== Preferring use of LibSass' if defined?(::SassC) - app.files.ignore :sass_cache, :source, /(^|\/)\.sass-cache\// if app.config[:sass_cache_location] == DEFAULT_SASS_CACHE_LOCATION # Tell Tilt to use it as well (for inline sass blocks) @@ -62,21 +55,31 @@ module Middleman def evaluate(context, _) @context ||= context - sass_module = if defined?(::SassC) - ::SassC - else - ::Sass - end - - @engine = sass_module::Engine.new(data, sass_options) + @engine = ::SassC::Engine.new(data, sass_options) begin @engine.render - rescue sass_module::SyntaxError => e - ::Sass::SyntaxError.exception_to_css(e) + rescue ::SassC::SyntaxError => e + exception_to_css(e) end end + def exception_to_css(e) + header = "#{e.class}: #{e.message}" + + <<~END + /* + #{header.gsub('*/', '*\\/')} + + Backtrace:\n#{e.backtrace.join("\n").gsub('*/', '*\\/')} + */ + body:before { + white-space: pre; + font-family: monospace; + content: "#{header.gsub('"', '\"').gsub("\n", '\\A ')}"; } + END + end + def vertices @engine.dependencies.reduce(::Hamster::Set.empty) do |sum, d| sum << ::Middleman::Dependencies::FileVertex.new(@context.app.root_path, d.filename.to_sym) @@ -91,7 +94,7 @@ module Middleman ctx = @context more_opts = { - load_paths: ::Sass.load_paths | ctx.app.config[:sass_assets_paths], + load_paths: ctx.app.config[:sass_assets_paths], filename: eval_file, line: line, syntax: syntax, diff --git a/middleman-core/lib/middleman-core/renderers/sass_functions.rb b/middleman-core/lib/middleman-core/renderers/sass_functions.rb index 5270929f..34c73aa4 100644 --- a/middleman-core/lib/middleman-core/renderers/sass_functions.rb +++ b/middleman-core/lib/middleman-core/renderers/sass_functions.rb @@ -16,7 +16,7 @@ module Middleman # def image_path(source, options_hash = ::Middleman::EMPTY_HASH) p = ::Middleman::Util.asset_path(middleman_context, :images, source.value, map_options(options_hash)) - ::Sass::Script::String.new p.to_s, :string + ::SassC::Script::Value::String.new p.to_s, :string end # Using Middleman::Util#asset_path, return the url CSS @@ -40,7 +40,8 @@ module Middleman options = {} end end - ::Sass::Script::String.new "url(#{image_path(source, options)})" + + ::SassC::Script::Value::String.new "url(#{image_path(source, options)})" end # Using Middleman::Util#asset_path, return the full path @@ -54,7 +55,7 @@ module Middleman # def font_path(source, options_hash = ::Middleman::EMPTY_HASH) p = ::Middleman::Util.asset_path(middleman_context, :fonts, source.value, map_options(options_hash)) - ::Sass::Script::String.new p.to_s, :string + ::SassC::Script::Value::String.new p.to_s, :string end # Using Middleman::Util#asset_path, return the url CSS @@ -78,7 +79,7 @@ module Middleman options = {} end end - ::Sass::Script::String.new "url(#{font_path(source, options)})" + ::SassC::Script::Value::String.new "url(#{font_path(source, options)})" end protected @@ -99,9 +100,9 @@ module Middleman def map_options(options_hash = ::Middleman::EMPTY_HASH) # :nodoc: options = options_hash.dup - ::Sass::Util.map_hash(options) do |key, value| - [key.to_sym, value.respond_to?(:value) ? value.value : value] - end + # ::SassC::Util.map_hash(options) do |key, value| + # [key.to_sym, value.respond_to?(:value) ? value.value : value] + # end options[:current_resource] = current_resource @@ -111,8 +112,4 @@ module Middleman end end -if defined?(::SassC) - ::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions -elsif defined?(::Sass) - ::Sass::Script::Functions.send :include, ::Middleman::Sass::Functions -end +::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index 5bee8451..a6bd34e2 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -44,8 +44,7 @@ Gem::Specification.new do |s| # Automatic Image Sizes s.add_dependency('fastimage', ['~> 2.0']) - # Minify CSS - s.add_dependency('sass', ['>= 3.4']) + # Sass and Minify CSS s.add_dependency('sassc', ['~> 2.0']) # Minify JS diff --git a/middleman/middleman.gemspec b/middleman/middleman.gemspec index a2a517e4..223d5d49 100644 --- a/middleman/middleman.gemspec +++ b/middleman/middleman.gemspec @@ -20,7 +20,6 @@ Gem::Specification.new do |s| s.add_dependency('middleman-core', Middleman::VERSION) s.add_dependency('middleman-cli', Middleman::VERSION) - s.add_dependency('sass', ['>= 3.4.0', '< 4.0']) s.add_dependency('haml', ['>= 4.0.5']) s.add_dependency('coffee-script', ['~> 2.2']) s.add_dependency('kramdown', ['~> 1.2'])