Skip to content

Instantly share code, notes, and snippets.

@vvasabi
Last active October 23, 2015 15:27
Show Gist options
  • Save vvasabi/a487ef6b59084d12a3ff to your computer and use it in GitHub Desktop.
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)
require 'middleman-sassc'
gem 'sassc', '~> 1.7.1'
gem 'sassc-rails', '~> 1.1.0'
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