Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.

Commit 5133b6a

Browse files
committed
Add old style Sass support
1 parent 471c87b commit 5133b6a

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

‎scss/common.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type Options struct {
7676
// to another URL or to return the body.
7777
ImportResolver func(url string, prev string) (newURL string, body string, resolved bool)
7878

79+
// Used to indicate "old style" SASS for the input stream.
80+
SassSyntax bool
81+
7982
// Source map settings
8083
SourceMapFilename string
8184
SourceMapRoot string

‎scss/libsass/transpiler.go‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package libsass
88

99
import (
10+
"bytes"
1011
"io"
1112
"io/ioutil"
1213
"os"
@@ -30,12 +31,24 @@ func New(options scss.Options) (tocss.Transpiler, error) {
3031
// older SASS (.sass) files, but the main entry (src) currently needs to be SCSS.
3132
func (t *libsassTranspiler) Execute(dst io.Writer, src io.Reader) (tocss.Result, error) {
3233
var result tocss.Result
33-
34-
b, err := ioutil.ReadAll(src)
35-
if err != nil {
36-
return result, err
34+
var sourceStr string
35+
36+
if t.options.SassSyntax {
37+
// LibSass does not support this directly, so have to handle the main SASS content
38+
// special.
39+
var buf bytes.Buffer
40+
err := libs.ToScss(src, &buf)
41+
if err != nil {
42+
return result, err
43+
}
44+
sourceStr = buf.String()
45+
} else {
46+
b, err := ioutil.ReadAll(src)
47+
if err != nil {
48+
return result, err
49+
}
50+
sourceStr = string(b)
3751
}
38-
sourceStr := string(b)
3952

4053
dataCtx := libs.SassMakeDataContext(sourceStr)
4154

‎scss/libsass/transpiler_test.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ div { p { color: $white; } }`)
4141
assert.Equal("div p {\n color: #fff; }\n", dst.String())
4242
}
4343

44+
func TestSassSyntax(t *testing.T) {
45+
assert := require.New(t)
46+
src := bytes.NewBufferString(`
47+
$color: #333;
48+
49+
.content-navigation
50+
border-color: $color
51+
`)
52+
53+
var dst bytes.Buffer
54+
55+
transpiler, err := New(scss.Options{OutputStyle: scss.CompressedStyle, SassSyntax: true})
56+
assert.NoError(err)
57+
58+
_, err = transpiler.Execute(&dst, src)
59+
assert.NoError(err)
60+
assert.Equal(".content-navigation{border-color:#333}\n", dst.String())
61+
}
62+
4463
func TestOutputStyle(t *testing.T) {
4564
assert := require.New(t)
4665
src := bytes.NewBufferString(`

0 commit comments

Comments
 (0)