From f19e849ad0dff8da3820b2b82da00d377b669edb Mon Sep 17 00:00:00 2001 From: allejo Date: Tue, 18 Sep 2018 23:01:51 -0700 Subject: [PATCH 1/3] Add a "@theme" keyword for Sass templates --- src/allejo/stakx/AssetEngine/Sass/SassEngine.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/allejo/stakx/AssetEngine/Sass/SassEngine.php b/src/allejo/stakx/AssetEngine/Sass/SassEngine.php index 3ce5925f..664f80ae 100644 --- a/src/allejo/stakx/AssetEngine/Sass/SassEngine.php +++ b/src/allejo/stakx/AssetEngine/Sass/SassEngine.php @@ -73,6 +73,8 @@ public function parse($content, array $options = []) 'sourceMapBasepath' => Service::getWorkingDirectory(), ]; + $this->handleThemeImports($content); + // We don't need to write the source map to a file if (!$this->fileSourceMap) { @@ -161,6 +163,15 @@ private function getSourceMapTargetFile(StaticPageView $pageView) ); } + private function handleThemeImports(&$content) + { + if (($themeName = $this->configuration->getTheme())) + { + $themePath = "../_themes/${themeName}/_sass"; + $content = preg_replace("/(@import ['\"])(@theme)(.+)/", "$1${themePath}$3", $content); + } + } + public static function stringToFormatter($format) { if ($format == 'nested') From 066d00b197e2cebd04ee2340270481610a53a7eb Mon Sep 17 00:00:00 2001 From: allejo Date: Tue, 18 Sep 2018 23:02:06 -0700 Subject: [PATCH 2/3] Add example of including Sass from themes --- example/_sass/styles.scss.twig | 2 ++ example/_themes/bootstrap/_sass/_card.scss | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 example/_themes/bootstrap/_sass/_card.scss diff --git a/example/_sass/styles.scss.twig b/example/_sass/styles.scss.twig index 74ed6bde..6cf56de9 100644 --- a/example/_sass/styles.scss.twig +++ b/example/_sass/styles.scss.twig @@ -2,6 +2,8 @@ permalink: /assets/css/styles.css --- +@import '@theme/card'; + @import 'components/utils'; @import 'components/footer'; @import 'components/calendar'; diff --git a/example/_themes/bootstrap/_sass/_card.scss b/example/_themes/bootstrap/_sass/_card.scss new file mode 100644 index 00000000..f1c53e4b --- /dev/null +++ b/example/_themes/bootstrap/_sass/_card.scss @@ -0,0 +1,3 @@ +.card { + border: 1px solid lightgrey; +} From 8f0d921a1510dd908f35b8977fc1f80fd92c0a9a Mon Sep 17 00:00:00 2001 From: Vladimir Jimenez Date: Tue, 18 Sep 2018 23:10:02 -0700 Subject: [PATCH 3/3] Add CHANGELOG for new Sass theme directive --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08960283..ce3a001b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **New** - Add new `serve` command to take the place of the defunct `watch` command +- Your `*.scss.twig` files now support the `@theme` directive to import partials relative to your theme's `_sass` folder **Fixes**