Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sass plugin for Jekyll
module Jekyll
# Sass plugin to convert .scss to .css
#
# Note: This is configured to use the new css like syntax available in sass.
require 'sass'
class SassConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /scss/i
end
def output_ext(ext)
".css"
end
def convert(content)
begin
puts "Performing Sass Conversion."
engine = Sass::Engine.new(content, :syntax => :scss, :load_paths => ["./css/"])
engine.render
rescue StandardError => e
puts "!!! SASS Error: " + e.message
end
end
end
end
@itsgoofer
Copy link

itsgoofer commented Aug 20, 2013

Thanks @wolfeidau. I have put this plugin in the _plugins directory of my jekyll project but I can't figure out why my scss files are not converted. Am I missing something?

Thanks!

@itsgoofer
Copy link

itsgoofer commented Aug 20, 2013

Thanks @wolfeidau. I have put this plugin in the _plugins directory of my jekyll project but I can't figure out why my scss files are not converted. Am I missing something?

Thanks!

@cjdsie
Copy link

cjdsie commented Aug 20, 2013

I'm in the same boat as @Omarfouad. I've added it and nothing is converting for me. What am I missing?

@jeffkamo
Copy link

jeffkamo commented Sep 16, 2013

@cjdsie, @Omarfouad. I think you have to make sure you include a YAML front-matter statement at the top of any file (in this case a scss file) that you want to convert.

This is mentioned in Jekyll's Plugin page under Converters: "Jekyll will only convert files that have a YAML header at the top, even for converters you add using a plugin."

For example:


---
title: stylesheet.scss

---

body { background: red; }

That seemed to do the trick for me.

@tamouse
Copy link

tamouse commented Oct 4, 2013

Front matter can be empty, thus

---

---

should work as well.

@homeyer
Copy link

homeyer commented Dec 12, 2013

Had to change
engine = Sass::Engine.new(content, :syntax => :scss, :load_paths => ["./css/"])
to
engine = Sass::Engine.new(content, :syntax => :scss, :load_paths => ["#{@config['source']}/css/"])

to support running jekyll build with a different --source flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment