Skip to content

Commit

Permalink
Merge pull request #76 from stakx-io/feature/sass-in-themes
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo authored Sep 19, 2018
2 parents 14a89c7 + 8f0d921 commit 6d8b44c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
2 changes: 2 additions & 0 deletions example/_sass/styles.scss.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
permalink: /assets/css/styles.css
---

@import '@theme/card';

@import 'components/utils';
@import 'components/footer';
@import 'components/calendar';
3 changes: 3 additions & 0 deletions example/_themes/bootstrap/_sass/_card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.card {
border: 1px solid lightgrey;
}
11 changes: 11 additions & 0 deletions src/allejo/stakx/AssetEngine/Sass/SassEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 6d8b44c

Please sign in to comment.