Skip to content

Commit

Permalink
Merge pull request #698 from anomalylabs/feature/production_parse
Browse files Browse the repository at this point in the history
Use custom lexer to avoid minified CSS breaking twig comments in parse
  • Loading branch information
RyanThompson committed Jul 9, 2020
2 parents ab41f74 + 41e046d commit 4645ed8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/en/01.prologue/02.change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Features that are deprecated will generally be removed in the next `minor` updat

## Releases

### [1.7.34] - 2020-07-07
- Modified the `parse` filter in `Asset` to allow for minified CSS to be parsed (such as from Laravel Mix).

### [1.7.33] - 2020-07-04
- Added a deprecated CacheConfig in the correct PSR-4 autoloading location for backwards compatibility in `anomaly/settings-module`.

Expand Down
2 changes: 1 addition & 1 deletion docs/en/12.front-end-development/03.assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $asset->add("collection.css", "theme::example.scss", ["min", "live"]);
- `less`: parses LESS into CSS
- `styl`: parses STYL into CSS
- `scss`: parses SCSS into CSS
- `parse`: parses content with Twig
- `parse`: parses content with Twig. Uses an alternate comment syntax `{* *}` to prevent clashes with CSS selectors.
- `coffee`: compiles CoffeeScript into Javascript
- `embed`: embeds image data in your stylesheets
- `live`: refreshes content when LIVE_ASSETS is enabled
Expand Down
15 changes: 15 additions & 0 deletions src/Asset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,15 @@ protected function publish($path, $collection, $additionalFilters)
* Parse the content. Always parse CSS.
*/
if (in_array('parse', $filters) || $hint == 'css') {
/** @var Bridge $twig */
$twig = resolve('twig');

$twig->setLexer(
new \Twig_Lexer($twig, [
'tag_comment' => ['{^', '^}']
])
);

try {
$contents = $this->template
->render($contents)
Expand All @@ -586,6 +595,12 @@ protected function publish($path, $collection, $additionalFilters)

\Log::error($e->getMessage());
}

$twig->setLexer(
new \Twig_Lexer($twig, [
'tag_comment' => ['{#', '#}']
])
);
}

/**
Expand Down

0 comments on commit 4645ed8

Please sign in to comment.