tocss/scss: Improve _ prefix handling in SCSS imports
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 31 Jul 2018 14:53:03 +0000 (16:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 31 Jul 2018 14:53:03 +0000 (16:53 +0200)
See #5008

hugolib/resource_chain_test.go
resource/tocss/scss/tocss.go

index 3d13d3912dddf8d830c1be73bb7005d833db6f75..3e199d318124a0124d0a156a997abbfe82457357 100644 (file)
@@ -114,7 +114,7 @@ func TestSCSSWithThemeOverrides(t *testing.T) {
 
        b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_imports.scss"), `
 @import "moo";
-
+@import "_boo";
 `)
 
        b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_moo.scss"), `
@@ -123,6 +123,14 @@ $moolor: #fff;
 moo {
   color: $moolor;
 }
+`)
+
+       b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_boo.scss"), `
+$boolor: orange;
+
+boo {
+  color: $boolor;
+}
 `)
 
        b.WithSourceFile(filepath.Join(scssThemeDir, "main.scss"), `
@@ -136,6 +144,14 @@ $moolor: #ccc;
 moo {
   color: $moolor;
 }
+`)
+
+       b.WithSourceFile(filepath.Join(scssDir, "components", "_boo.scss"), `
+$boolor: green;
+
+boo {
+  color: $boolor;
+}
 `)
 
        b.WithTemplatesAdded("index.html", `
@@ -145,7 +161,7 @@ T1: {{ $r.Content }}
 `)
        b.Build(BuildCfg{})
 
-       b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: moo{color:#ccc}`)
+       b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: moo{color:#ccc}boo{color:green}`)
 
 }
 
index c50b054b774f0ddd62101074de7af574396606a7..5ba7793c025e7ee3798217686c76735c93d90ddd 100644 (file)
@@ -93,6 +93,8 @@ func (t *toCSSTransformation) Transform(ctx *resource.ResourceTransformationCtx)
                        namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass"}
                }
 
+               name = strings.TrimPrefix(name, "_")
+
                for _, namePattern := range namePatterns {
                        filenameToCheck := filepath.Join(basePath, fmt.Sprintf(namePattern, name))
                        fi, err := t.c.sfs.Fs.Stat(filenameToCheck)