Skip to content

Commit

Permalink
Support for @import directive
Browse files Browse the repository at this point in the history
  • Loading branch information
screendriver committed Sep 1, 2015
1 parent 4f560f1 commit 373d567
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# plugin-sass [![Build Status](https://travis-ci.org/screendriver/plugin-sass.svg?branch=master)](https://travis-ci.org/screendriver/plugin-sass)
# plugin-sass

[![Build Status](https://travis-ci.org/screendriver/plugin-sass.svg?branch=master)](https://travis-ci.org/screendriver/plugin-sass)
[![Dependency Status](https://david-dm.org/screendriver/plugin-sass.svg)](https://david-dm.org/screendriver/plugin-sass)

[SystemJS](https://github.com/systemjs/systemjs)
[SASS](http://sass-lang.com) loader plugin. Can easily be installed with
Expand Down
13 changes: 13 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ System.config({
"fetch": "npm:[email protected]",
"sass.js": "npm:[email protected]",
"scss": "src/sass.js",
"url": "github:jspm/[email protected]",
"github:jspm/[email protected]": {
"assert": "npm:[email protected]"
},
Expand All @@ -44,6 +45,9 @@ System.config({
"github:jspm/[email protected]": {
"stream-browserify": "npm:[email protected]"
},
"github:jspm/[email protected]": {
"url": "npm:[email protected]"
},
"github:jspm/[email protected]": {
"util": "npm:[email protected]"
},
Expand Down Expand Up @@ -201,6 +205,9 @@ System.config({
"parse-asn1": "npm:[email protected]",
"randombytes": "npm:[email protected]"
},
"npm:[email protected]": {
"process": "github:jspm/[email protected]"
},
"npm:[email protected]": {
"buffer": "github:jspm/[email protected]",
"crypto": "github:jspm/[email protected]",
Expand Down Expand Up @@ -241,6 +248,12 @@ System.config({
"npm:[email protected]": {
"buffer": "github:jspm/[email protected]"
},
"npm:[email protected]": {
"assert": "github:jspm/[email protected]",
"punycode": "npm:[email protected]",
"querystring": "npm:[email protected]",
"util": "github:jspm/[email protected]"
},
"npm:[email protected]": {
"inherits": "npm:[email protected]",
"process": "github:jspm/[email protected]"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plugin-sass",
"version": "0.0.1",
"version": "0.0.2",
"description": "SystemJS SASS loader plugin",
"registry": "jspm",
"main": "./src/sass.js",
Expand Down Expand Up @@ -36,7 +36,8 @@
"directories": {},
"dependencies": {
"fetch": "npm:whatwg-fetch@^0.9.0",
"sass.js": "npm:sass.js@^0.9.2"
"sass.js": "npm:sass.js@^0.9.2",
"url": "github:jspm/nodelibs-url@^0.1.0"
},
"devDependencies": {
"babel": "npm:babel-core@^5.8.22",
Expand Down
17 changes: 15 additions & 2 deletions src/sass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import 'fetch';
import url from 'url';
import sass from 'sass.js';

let urlBase;

// intercept file loading requests (@import directive) from libsass
sass.importer((request, done) => {
const importUrl = url.resolve(urlBase, `${request.current}.scss`);
fetch(importUrl)
.then(response => response.text())
.then(content => done({ content }));
});

const compile = scss => {
return new Promise((resolve, reject) => {
sass.compile(scss, result => {
Expand All @@ -11,14 +22,16 @@ const compile = scss => {
document.getElementsByTagName('head')[0].appendChild(style);
resolve('');
} else {
reject();
reject(result.formatted);
}
});
});
};

const scssFetch = load => {
return fetch(load.address)
urlBase = load.address;
// fetch initial scss file
return fetch(urlBase)
.then(response => response.text())
.then(compile);
};
Expand Down
2 changes: 1 addition & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</head>

<body>
<h1>Background should become green</h1>
<h1>I should become blue and background should become green</h1>
<h2>Loading...</h2>
</body>

Expand Down
6 changes: 4 additions & 2 deletions test/test.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$color: green;
@import 'headings';

$bodyColor: green;

body {
background-color: $color;
background-color: $bodyColor;
}

0 comments on commit 373d567

Please sign in to comment.