mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Only libsass (#2236)
* Only libsass * Fix sass functions * Test for sass exceptions in the main sass test suite. Re-create css exception rendering in SassC
This commit is contained in:
parent
4feb7b501d
commit
71d684a435
9 changed files with 46 additions and 49 deletions
|
@ -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 }`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
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:"
|
|
@ -0,0 +1 @@
|
|||
@include invalid-mixin;
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'])
|
||||
|
|
Loading…
Add table
Reference in a new issue