Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-31 10:34:56 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-31 11:54:10 +0300
commitf219ac09f6b7e26d84599401512233d77c1bdb4c (patch)
treef644d0feebe52d88028cdaab8c1176d269231be3 /hugolib
parent786f72302f65580ca8d1df2132a7756584539ea0 (diff)
tocss/scss: Improve SCSS project vs themes import resolution
Before this commit, only SASS/SCSS components imported from main.scss at first level can be overwritten by homonymous files in projects or over-preceding theme components. This commit fixes that by implementing a custom import resolver which will be tried first. This resolver will make sure that the project/theme hierarchy is always respected. Fixes #5008
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/resource_chain_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index 61ae7e611..3d13d3912 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -79,6 +79,76 @@ T1: {{ $r.Content }}
}
+func TestSCSSWithThemeOverrides(t *testing.T) {
+ if !scss.Supports() {
+ t.Skip("Skip SCSS")
+ }
+ assert := require.New(t)
+ workDir, clean, err := createTempDir("hugo-scss-include")
+ assert.NoError(err)
+ defer clean()
+
+ theme := "mytheme"
+ themesDir := filepath.Join(workDir, "themes")
+ themeDirs := filepath.Join(themesDir, theme)
+ v := viper.New()
+ v.Set("workingDir", workDir)
+ v.Set("theme", theme)
+ b := newTestSitesBuilder(t).WithLogger(loggers.NewWarningLogger())
+ b.WithViper(v)
+ b.WithWorkingDir(workDir)
+ // Need to use OS fs for this.
+ b.Fs = hugofs.NewDefault(v)
+
+ fooDir := filepath.Join(workDir, "node_modules", "foo")
+ scssDir := filepath.Join(workDir, "assets", "scss")
+ scssThemeDir := filepath.Join(themeDirs, "assets", "scss")
+ assert.NoError(os.MkdirAll(fooDir, 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(workDir, "data"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(scssDir, "components"), 0777))
+ assert.NoError(os.MkdirAll(filepath.Join(scssThemeDir, "components"), 0777))
+
+ b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_imports.scss"), `
+@import "moo";
+
+`)
+
+ b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_moo.scss"), `
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+`)
+
+ b.WithSourceFile(filepath.Join(scssThemeDir, "main.scss"), `
+@import "components/imports";
+
+`)
+
+ b.WithSourceFile(filepath.Join(scssDir, "components", "_moo.scss"), `
+$moolor: #ccc;
+
+moo {
+ color: $moolor;
+}
+`)
+
+ b.WithTemplatesAdded("index.html", `
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) ) }}
+{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
+T1: {{ $r.Content }}
+`)
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent(filepath.Join(workDir, "public/index.html"), `T1: moo{color:#ccc}`)
+
+}
+
func TestResourceChain(t *testing.T) {
t.Parallel()