Last active
October 23, 2015 15:27
-
-
Save vvasabi/a487ef6b59084d12a3ff to your computer and use it in GitHub Desktop.
Use SassC in Middleman 3.x. (Also see: https://rubygems.org/gems/middleman3-sassc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'middleman-sassc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'sassc', '~> 1.7.1' | |
gem 'sassc-rails', '~> 1.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sassc' | |
# Monkey patch Sprockets to use SassC | |
module Sprockets::Sass | |
class SassTemplate | |
def evaluate(context, locals, &block) | |
# empty file? | |
if data.empty? | |
@output = '' | |
end | |
@output ||= begin | |
@context = context | |
options = sass_options | |
options = options.merge({ | |
load_paths: context.environment.paths, | |
importer: ::SassC::Rails::Importer, | |
sprockets: { | |
context: context, | |
environment: context.environment | |
} | |
}) | |
::SassC::Engine.new(data, options).render | |
end | |
end | |
end | |
end | |
# Middleman also tries to call the Sass engine sometimes | |
module Middleman::Renderers::Sass | |
class SassPlusCSSFilenameTemplate | |
def evaluate(context, _) | |
@context ||= context | |
sprockets = context.sprockets | |
@sprockets_context ||= sprockets.context_class.new(sprockets, File.basename(file), | |
Pathname.new(file)) | |
@engine = ::SassC::Engine.new(data, sass_options.merge({ | |
load_paths: context.sprockets.paths, | |
importer: ::SassC::Rails::Importer, | |
sprockets: { | |
context: @sprockets_context, | |
environment: sprockets | |
} | |
})) | |
@engine.render | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment