-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
251 additions
and
121 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var path = require("path") | ||
var postcss = require("postcss") | ||
var sugarss | ||
|
||
module.exports = function processContent( | ||
result, | ||
content, | ||
filename, | ||
options | ||
) { | ||
var plugins = options.plugins | ||
var ext = path.extname(filename) | ||
|
||
var parserList = [] | ||
|
||
// SugarSS support: | ||
if (ext === ".sss") { | ||
if (!sugarss) { | ||
try { | ||
sugarss = require("sugarss") | ||
} | ||
catch (e) { | ||
// Ignore | ||
} | ||
} | ||
if (sugarss) return runPostcss(content, filename, plugins, [ sugarss ]) | ||
} | ||
|
||
// Syntax support: | ||
if (result.opts.syntax && result.opts.syntax.parse) { | ||
parserList.push(result.opts.syntax.parse) | ||
} | ||
|
||
// Parser support: | ||
if (result.opts.parser) parserList.push(result.opts.parser) | ||
// Try the default as a last resort: | ||
parserList.push(null) | ||
|
||
return runPostcss(content, filename, plugins, parserList) | ||
} | ||
|
||
function runPostcss( | ||
content, | ||
filename, | ||
plugins, | ||
parsers, | ||
index | ||
) { | ||
if (!index) index = 0 | ||
return postcss(plugins).process(content, { | ||
from: filename, | ||
parser: parsers[index], | ||
}) | ||
.catch(function(err) { | ||
// If there's an error, try the next parser | ||
index++ | ||
// If there are no parsers left, throw it | ||
if (index === parsers.length) throw err | ||
return runPostcss(content, filename, plugins, parsers, index) | ||
}) | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import test from "ava" | ||
import scss from "postcss-scss" | ||
import sugarss from "sugarss" | ||
import compareFixtures from "./helpers/compare-fixtures" | ||
import compareFixturesExt from "./helpers/compare-fixtures-ext" | ||
|
||
test("should process custom syntax", t => { | ||
return compareFixtures(t, "scss-syntax", null, { | ||
syntax: scss, | ||
}) | ||
}) | ||
|
||
test("should process custom syntax by parser", t => { | ||
return compareFixtures(t, "scss-parser", null, { | ||
parser: scss, | ||
}) | ||
}) | ||
|
||
test(".css importing .sss should work", t => { | ||
return compareFixtures(t, "import-sss") | ||
}) | ||
|
||
test(".sss importing .sss should work", t => { | ||
return compareFixturesExt(t, "sugar", ".sss", null, { | ||
parser: sugarss, | ||
}) | ||
}) | ||
|
||
test(".sss importing .css should work", t => { | ||
return compareFixturesExt(t, "sugar-import-css", ".sss", null, { | ||
parser: sugarss, | ||
}) | ||
}) | ||
|
||
test(".css importing .sss importing .css should work", t => { | ||
return compareFixtures(t, "import-sss-css") | ||
}) | ||
|
||
test(".sss importing .css importing .sss should work", t => { | ||
return compareFixturesExt(t, "import-css-sss", ".sss", null, { | ||
parser: sugarss, | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.sugarbar{ | ||
color: blue | ||
} | ||
|
||
import.sugarbar{} | ||
|
||
.sugar{ | ||
color: white | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@import "import-sugarbar.css" | ||
|
||
.sugar | ||
color: white |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "foo-recursive.sss"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bar{} | ||
|
||
foo.recursive{ | ||
color: red | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "sugarbar.sss"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.sugarbar { | ||
color: blue | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@import "bar.css" | ||
|
||
foo.recursive | ||
color: red |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "sugarbar.sss"; | ||
|
||
import.sugarbar{} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.sugarbar | ||
color: blue |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bar{} | ||
.sugar{ | ||
color: white | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "bar.css" | ||
.sugar | ||
color: white |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.sugarbar { | ||
color: blue | ||
} | ||
.sugar { | ||
color: white | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "sugarbar.sss" | ||
.sugar | ||
color: white |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var fs = require("fs") | ||
var postcss = require("postcss") | ||
var assign = require("object-assign") | ||
var atImport = require("../..") | ||
|
||
function read(name, ext) { | ||
if (!ext) ext = ".css" | ||
return fs.readFileSync("fixtures/" + name + ext, "utf8") | ||
} | ||
|
||
module.exports = function(t, name, ext, opts, postcssOpts, warnings) { | ||
opts = assign({ path: "fixtures/imports" }, opts) | ||
return postcss(atImport(opts)) | ||
.process(read(name, ext), postcssOpts || {}) | ||
.then(function(result) { | ||
var actual = result.css | ||
var expected = read(name + ".expected") | ||
// handy thing: checkout actual in the *.actual.css file | ||
fs.writeFile("fixtures/" + name + ".actual.css", actual) | ||
t.is(actual, expected) | ||
if (!warnings) { | ||
warnings = [] | ||
} | ||
result.warnings().forEach(function(warning, index) { | ||
t.is( | ||
warning.text, | ||
warnings[index], | ||
"unexpected warning: \"" + warning.text + "\"" | ||
) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.