Skip to content

Commit

Permalink
Add new sass package based on less package.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1mmy committed Apr 26, 2012
1 parent c01f3fa commit eb80170
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/sass/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Package.describe({
summary: "Sassy CSS pre-processor."
});

var sass = require('sass');
var fs = require('fs');

Package.register_extension(
"sass", function (bundle, source_path, serve_path, where) {
serve_path = serve_path + '.css';

try {
var contents = fs.readFileSync(source_path);
var css = sass.render(contents.toString('utf8'));
// NOTE: sass does not seem to return any sort of error. It just
// silently ignores bad sass code.

bundle.add_resource({
type: "css",
path: serve_path,
data: new Buffer(css),
where: where
});
} catch (e) {
// Haven't been able to get sass to throw, but just in case.
bundle.error(source_path + ": Sass compiler error: " + e.message);
}
}
);

Package.on_test(function (api) {
api.add_files(['sass_tests.sass', 'sass_tests.js'], 'client');
});
20 changes: 20 additions & 0 deletions packages/sass/sass_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Tinytest.add("sass - presence", function(test) {

// find the .sass stylesheet, whose first rule contains "sass-tests"
// in the selector
var sheet = _.find(document.styleSheets, function(sh) {
var rules = sh.cssRules || sh.rules;
return /sass-tests/.test(rules[0].selectorText);
});

test.isTrue(sheet);

// `cssRules` is the W3C name, but isn't supported in IE until
// version 9. IE<=8 has `rules`. We prefer `cssRules` as
// it is less likely to have quirks if both are present.
var rules = sheet.cssRules || sheet.rules;

test.equal(rules[1].style.borderLeftWidth, "13px");
});

7 changes: 7 additions & 0 deletions packages/sass/sass_tests.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#sass-tests
:zoom 1

unlucky: 13px

.unlucky-left-border
:border-left-width !unlucky

0 comments on commit eb80170

Please sign in to comment.