From 2f9090f8860f41f2aa5cbb9baccb7727bd22d041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 5 Dec 2023 13:08:11 +0100 Subject: [PATCH 1/8] feat: assets in Markdown --- .../site/config/packages/yassg_routes.yaml | 2 +- .../site/content/articles/images.md | 6 +++ .../fixtures/en/article/images/index.html | 26 +++++++++++++ .../site/fixtures/en/articles/1/index.html | 11 ++++-- .../site/fixtures/en/articles/2/index.html | 7 +++- .../site/fixtures/en/articles/3/index.html | 38 +++++++++++++++++++ tests/functional/site/fixtures/index.html | 4 ++ .../site/templates/pages/articles.html.twig | 4 +- 8 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 tests/functional/site/content/articles/images.md create mode 100644 tests/functional/site/fixtures/en/article/images/index.html create mode 100644 tests/functional/site/fixtures/en/articles/3/index.html diff --git a/tests/functional/site/config/packages/yassg_routes.yaml b/tests/functional/site/config/packages/yassg_routes.yaml index 5b0ee3a..3829c4f 100644 --- a/tests/functional/site/config/packages/yassg_routes.yaml +++ b/tests/functional/site/config/packages/yassg_routes.yaml @@ -22,7 +22,7 @@ sigwin_yassg: defaults: page: 1 catalog: - page: "yassg_pages('articles', 'item.publishedAt.getTimestamp() <= 1658238497')" + page: "yassg_pages('articles', 'item.publishedAt.getTimestamp() <= 1701776753')" product: path: /{_locale}/{slug} catalog: diff --git a/tests/functional/site/content/articles/images.md b/tests/functional/site/content/articles/images.md new file mode 100644 index 0000000..734384d --- /dev/null +++ b/tests/functional/site/content/articles/images.md @@ -0,0 +1,6 @@ +--- +title: Images! +slug: images +publishedAt: "2022-07-20 12:35:00" +--- + diff --git a/tests/functional/site/fixtures/en/article/images/index.html b/tests/functional/site/fixtures/en/article/images/index.html new file mode 100644 index 0000000..6e06868 --- /dev/null +++ b/tests/functional/site/fixtures/en/article/images/index.html @@ -0,0 +1,26 @@ + + + + + + + + Images! + + + + + +
+
+
+

Images!

+

20.07.2022. 12:35

+ +
+
+
+ + + + diff --git a/tests/functional/site/fixtures/en/articles/1/index.html b/tests/functional/site/fixtures/en/articles/1/index.html index 82f336a..6e725e1 100644 --- a/tests/functional/site/fixtures/en/articles/1/index.html +++ b/tests/functional/site/fixtures/en/articles/1/index.html @@ -15,10 +15,10 @@

Articles

-

Hello World!

-

18.07.2022. 12:44

-

Paragraphs!

-

19.07.2022. 12:09

+

Images!

+

20.07.2022. 12:35

+

Lists!

+

19.07.2022. 12:13

diff --git a/tests/functional/site/fixtures/en/articles/2/index.html b/tests/functional/site/fixtures/en/articles/2/index.html index 1a68fcc..0e8dece 100644 --- a/tests/functional/site/fixtures/en/articles/2/index.html +++ b/tests/functional/site/fixtures/en/articles/2/index.html @@ -17,8 +17,8 @@

Articles

Titles!

19.07.2022. 12:11

-

Lists!

-

19.07.2022. 12:13

+

Paragraphs!

+

19.07.2022. 12:09

diff --git a/tests/functional/site/fixtures/en/articles/3/index.html b/tests/functional/site/fixtures/en/articles/3/index.html new file mode 100644 index 0000000..9816d3b --- /dev/null +++ b/tests/functional/site/fixtures/en/articles/3/index.html @@ -0,0 +1,38 @@ + + + + + + + + Articles, page #3 + + + + + +
+
+
+

Articles

+

Hello World!

+

18.07.2022. 12:44

+ +
    +
  • + 1 +
  • +
  • + 2 +
  • +
  • + 3 +
  • +
+
+
+
+ + + + diff --git a/tests/functional/site/fixtures/index.html b/tests/functional/site/fixtures/index.html index f2ef5bc..42eda00 100644 --- a/tests/functional/site/fixtures/index.html +++ b/tests/functional/site/fixtures/index.html @@ -36,6 +36,8 @@

Index

/sub/dir/another/en/article/hello-world/
+
/sub/dir/another/en/article/images/
+
/sub/dir/another/en/article/lists/
/sub/dir/another/en/article/paragraphs/
@@ -48,6 +50,8 @@

Index

/sub/dir/another/en/articles/1/
/sub/dir/another/en/articles/2/
+ +
/sub/dir/another/en/articles/3/
product
/sub/dir/another/en/nested-example/
diff --git a/tests/functional/site/templates/pages/articles.html.twig b/tests/functional/site/templates/pages/articles.html.twig index a067a4f..8c19345 100644 --- a/tests/functional/site/templates/pages/articles.html.twig +++ b/tests/functional/site/templates/pages/articles.html.twig @@ -1,8 +1,8 @@ {% extends 'layout.html.twig' %} -{% set condition = 'item.publishedAt.getTimestamp() <= 1658238497' %} +{% set condition = 'item.publishedAt.getTimestamp() <= 1701776753' %} -{% set articles = yassg_paginate('articles', page, {condition: condition, sort: {'item.publishedAt': 'asc'}}) %} +{% set articles = yassg_paginate('articles', page, {condition: condition, sort: {'item.publishedAt': 'desc'}}) %} {% block title %}Articles, page #{{ page }}{% endblock %} From 48f1b8a7697307f36509a7ef0a56481c010e2ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 5 Dec 2023 17:18:46 +0100 Subject: [PATCH 2/8] feat: expressions in Markdown --- config/services.yaml | 5 ++ psalm.baseline.xml | 25 +++---- .../Delimiter/ExpressionDelimiter.php | 65 +++++++++++++++++++ src/Bridge/CommonMark/Node/Expression.php | 25 +++++++ .../NodeRenderer/ExpressionRenderer.php | 46 +++++++++++++ .../site/content/articles/images.md | 4 +- 6 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php create mode 100644 src/Bridge/CommonMark/Node/Expression.php create mode 100644 src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php diff --git a/config/services.yaml b/config/services.yaml index 5486e73..fde0747 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -38,6 +38,7 @@ services: arguments: $locator: !tagged_locator { tag: 'sigwin_yassg.database', index_by: 'name' } + Symfony\Component\ExpressionLanguage\ExpressionLanguage: '@sigwin_yassg.expression_language' sigwin_yassg.expression_language: class: Symfony\Component\ExpressionLanguage\ExpressionLanguage calls: @@ -122,6 +123,10 @@ services: addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\FencedCode, '@Spatie\CommonMarkHighlighter\FencedCodeRenderer', 10 ] - addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode, '@Spatie\CommonMarkHighlighter\IndentedCodeRenderer', 10 ] + - + addDelimiterProcessor: [ '@Sigwin\YASSG\Bridge\CommonMark\Delimiter\ExpressionDelimiter'] + - + addRenderer: [Sigwin\YASSG\Bridge\CommonMark\Node\Expression, '@Sigwin\YASSG\Bridge\CommonMark\NodeRenderer\ExpressionRenderer'] League\CommonMark\Environment\EnvironmentInterface: '@League\CommonMark\Environment\Environment' League\CommonMark\MarkdownConverter: ~ diff --git a/psalm.baseline.xml b/psalm.baseline.xml index f95308a..9a531d9 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -18,6 +18,16 @@ Page + + + ExpressionDelimiter + + + + + ExpressionRenderer + + GenerateCommand @@ -138,9 +148,6 @@ variableNode variableNode - - end - end @@ -297,9 +304,6 @@ CollectionNormalizer - - $format - @@ -314,9 +318,6 @@ ExpressionNormalizer - - $format - @@ -342,17 +343,11 @@ LocalizingNormalizer - - $format - ResourceLocatorNormalizer - - $format - diff --git a/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php b/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php new file mode 100644 index 0000000..e13a54d --- /dev/null +++ b/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php @@ -0,0 +1,65 @@ +insertAfter($this->expression($opener, $closer)); + } + + private function expression(AbstractStringContainer $opener, AbstractStringContainer $closer): AbstractStringContainer + { + $expressionNode = new Expression(); + + $node = $opener->next(); + while ($node !== null && $node !== $closer) { + if ($node instanceof StringContainerInterface === false) { + throw new \RuntimeException('Invalid node type found'); + } + $expressionNode->append($node); + $expressionNode->appendChild($node); + $node = $node->next(); + } + + return $expressionNode; + } +} diff --git a/src/Bridge/CommonMark/Node/Expression.php b/src/Bridge/CommonMark/Node/Expression.php new file mode 100644 index 0000000..9001b9f --- /dev/null +++ b/src/Bridge/CommonMark/Node/Expression.php @@ -0,0 +1,25 @@ +literal .= $node->getLiteral(); + } +} diff --git a/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php b/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php new file mode 100644 index 0000000..7728d83 --- /dev/null +++ b/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php @@ -0,0 +1,46 @@ +children() as $child) { + $expression = $child->getLiteral(); + $value = $this->expressionLanguage->evaluate($child->getLiteral(), [ + 'provider' => $this->provider, + ]); + if (! \is_scalar($value)) { + throw new \RuntimeException(sprintf('Expression "%1$s" did not evaluate to a scalar, got %2$s', $expression, \gettype($value))); + } + $child->setLiteral((string) $value); + } + + return $childRenderer->renderNodes($node->children()); + } +} diff --git a/tests/functional/site/content/articles/images.md b/tests/functional/site/content/articles/images.md index 734384d..ea7f79c 100644 --- a/tests/functional/site/content/articles/images.md +++ b/tests/functional/site/content/articles/images.md @@ -1,6 +1,8 @@ --- -title: Images! +title: Images slug: images publishedAt: "2022-07-20 12:35:00" --- +This is a database lookup example: {{yassg_get('articles', '/hello-world.md').title}} + From bdbabd2c42d9d5ae48734e79ea202118dce45594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 5 Dec 2023 17:23:14 +0100 Subject: [PATCH 3/8] feat: expressions in Markdown --- tests/functional/site/content/articles/images.md | 2 +- tests/functional/site/fixtures/en/article/images/index.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/functional/site/content/articles/images.md b/tests/functional/site/content/articles/images.md index ea7f79c..945d278 100644 --- a/tests/functional/site/content/articles/images.md +++ b/tests/functional/site/content/articles/images.md @@ -1,5 +1,5 @@ --- -title: Images +title: Images! slug: images publishedAt: "2022-07-20 12:35:00" --- diff --git a/tests/functional/site/fixtures/en/article/images/index.html b/tests/functional/site/fixtures/en/article/images/index.html index 6e06868..494129a 100644 --- a/tests/functional/site/fixtures/en/article/images/index.html +++ b/tests/functional/site/fixtures/en/article/images/index.html @@ -16,7 +16,8 @@

Images!

20.07.2022. 12:35

- +

This is a database lookup example: Hello World!

+
From 4d7760e744b2c92606311c759bee2d4645d92750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 5 Dec 2023 17:26:49 +0100 Subject: [PATCH 4/8] feat: expressions in Markdown --- psalm.baseline.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 9a531d9..5294452 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -148,6 +148,9 @@ variableNode variableNode + + end + end @@ -304,6 +307,9 @@ CollectionNormalizer + + $format +
@@ -318,6 +324,9 @@ ExpressionNormalizer + + $format + @@ -343,11 +352,17 @@ LocalizingNormalizer + + $format + ResourceLocatorNormalizer + + $format + From bf4766dcf59f7731b991aee1a21543d1c20f7fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 5 Dec 2023 17:40:11 +0100 Subject: [PATCH 5/8] feat: expressions in Markdown --- src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php | 6 ++++++ tests/functional/site/content/articles/images.md | 3 +++ tests/functional/site/fixtures/en/article/images/index.html | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php b/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php index 430225c..71f3ed7 100644 --- a/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php +++ b/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php @@ -14,14 +14,20 @@ namespace Sigwin\YASSG\Bridge\Symfony\ExpressionLanguage; use Sigwin\YASSG\DatabaseProvider; +use Symfony\Component\Asset\Packages; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; final class FunctionProvider implements ExpressionFunctionProviderInterface { + public function __construct(private Packages $packages) {} + public function getFunctions(): array { return [ + new ExpressionFunction('asset', static fn (string $url): string => sprintf('$packages->getUrl(%s)', $url), function (array $variables, string $url) { + return $this->packages->getUrl($url); + }), new ExpressionFunction('yassg_find_all', static fn (string $name): string => sprintf('$provider->getDatabase(%s)', $name), static function (array $variables, string $name, array $arguments = []) { /** @var DatabaseProvider $provider */ $provider = $variables['provider']; diff --git a/tests/functional/site/content/articles/images.md b/tests/functional/site/content/articles/images.md index 945d278..4efbb3b 100644 --- a/tests/functional/site/content/articles/images.md +++ b/tests/functional/site/content/articles/images.md @@ -6,3 +6,6 @@ publishedAt: "2022-07-20 12:35:00" This is a database lookup example: {{yassg_get('articles', '/hello-world.md').title}} +This is an asset lookup: {{asset('assets/images/sigwin.svg')}} + +![Logo]({{asset('assets/images/sigwin.svg')}}) diff --git a/tests/functional/site/fixtures/en/article/images/index.html b/tests/functional/site/fixtures/en/article/images/index.html index 494129a..40df42b 100644 --- a/tests/functional/site/fixtures/en/article/images/index.html +++ b/tests/functional/site/fixtures/en/article/images/index.html @@ -17,6 +17,8 @@

Images!

20.07.2022. 12:35

This is a database lookup example: Hello World!

+

This is an asset lookup: /sub/dir/another/assets/images/sigwin.6f9a3d5b.svg

+

Logo

From 605730f01678235270c03c57be37187ecc8fae62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 7 Dec 2023 17:30:46 +0100 Subject: [PATCH 6/8] feat: Twig (!) in Markdown --- config/services.yaml | 4 -- .../Delimiter/ExpressionDelimiter.php | 65 ------------------- src/Bridge/CommonMark/Node/Expression.php | 25 ------- .../NodeRenderer/ExpressionRenderer.php | 46 ------------- src/Decoder/MarkdownFileDecoder.php | 20 +++++- .../site/content/articles/images.md | 6 +- .../fixtures/en/article/images/index.html | 2 +- tests/functional/site/src/Model/Article.php | 1 + 8 files changed, 24 insertions(+), 145 deletions(-) delete mode 100644 src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php delete mode 100644 src/Bridge/CommonMark/Node/Expression.php delete mode 100644 src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php diff --git a/config/services.yaml b/config/services.yaml index fde0747..d9e11aa 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -123,10 +123,6 @@ services: addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\FencedCode, '@Spatie\CommonMarkHighlighter\FencedCodeRenderer', 10 ] - addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode, '@Spatie\CommonMarkHighlighter\IndentedCodeRenderer', 10 ] - - - addDelimiterProcessor: [ '@Sigwin\YASSG\Bridge\CommonMark\Delimiter\ExpressionDelimiter'] - - - addRenderer: [Sigwin\YASSG\Bridge\CommonMark\Node\Expression, '@Sigwin\YASSG\Bridge\CommonMark\NodeRenderer\ExpressionRenderer'] League\CommonMark\Environment\EnvironmentInterface: '@League\CommonMark\Environment\Environment' League\CommonMark\MarkdownConverter: ~ diff --git a/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php b/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php deleted file mode 100644 index e13a54d..0000000 --- a/src/Bridge/CommonMark/Delimiter/ExpressionDelimiter.php +++ /dev/null @@ -1,65 +0,0 @@ -insertAfter($this->expression($opener, $closer)); - } - - private function expression(AbstractStringContainer $opener, AbstractStringContainer $closer): AbstractStringContainer - { - $expressionNode = new Expression(); - - $node = $opener->next(); - while ($node !== null && $node !== $closer) { - if ($node instanceof StringContainerInterface === false) { - throw new \RuntimeException('Invalid node type found'); - } - $expressionNode->append($node); - $expressionNode->appendChild($node); - $node = $node->next(); - } - - return $expressionNode; - } -} diff --git a/src/Bridge/CommonMark/Node/Expression.php b/src/Bridge/CommonMark/Node/Expression.php deleted file mode 100644 index 9001b9f..0000000 --- a/src/Bridge/CommonMark/Node/Expression.php +++ /dev/null @@ -1,25 +0,0 @@ -literal .= $node->getLiteral(); - } -} diff --git a/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php b/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php deleted file mode 100644 index 7728d83..0000000 --- a/src/Bridge/CommonMark/NodeRenderer/ExpressionRenderer.php +++ /dev/null @@ -1,46 +0,0 @@ -children() as $child) { - $expression = $child->getLiteral(); - $value = $this->expressionLanguage->evaluate($child->getLiteral(), [ - 'provider' => $this->provider, - ]); - if (! \is_scalar($value)) { - throw new \RuntimeException(sprintf('Expression "%1$s" did not evaluate to a scalar, got %2$s', $expression, \gettype($value))); - } - $child->setLiteral((string) $value); - } - - return $childRenderer->renderNodes($node->children()); - } -} diff --git a/src/Decoder/MarkdownFileDecoder.php b/src/Decoder/MarkdownFileDecoder.php index cb6f74a..ab14dc6 100644 --- a/src/Decoder/MarkdownFileDecoder.php +++ b/src/Decoder/MarkdownFileDecoder.php @@ -16,6 +16,8 @@ use League\CommonMark\ConverterInterface; use League\CommonMark\Extension\FrontMatter\FrontMatterProviderInterface; use Sigwin\YASSG\FileDecoder; +use Symfony\Component\Yaml\Yaml; +use Twig\Environment; final readonly class MarkdownFileDecoder implements FileDecoder { @@ -23,7 +25,7 @@ private const EXTENSIONS = ['md', 'markdown']; - public function __construct(private ConverterInterface $converter) {} + public function __construct(private ConverterInterface $converter, private Environment $twig) {} public function decode(\SplFileInfo $file): array { @@ -37,8 +39,22 @@ public function decode(\SplFileInfo $file): array throw new \RuntimeException('Failed to read file'); } - $result = $this->converter->convert($content); $metadata = []; + if (str_contains($content, '{{') || str_contains($content, '{%')) { + if (str_starts_with($content, '---')) { + $parts = explode('---', ltrim($content, '-'), 3); + if (\count($parts) !== 2) { + throw new \RuntimeException('Failed to extract frontmatter'); + } + $metadata = Yaml::parse($parts[0]); + } + + $content = $this->twig->createTemplate($content)->render([ + 'item' => $metadata, + ]); + } + + $result = $this->converter->convert($content); if ($result instanceof FrontMatterProviderInterface) { /** @var array $metadata */ $metadata = $result->getFrontMatter(); diff --git a/tests/functional/site/content/articles/images.md b/tests/functional/site/content/articles/images.md index 4efbb3b..e4dddbc 100644 --- a/tests/functional/site/content/articles/images.md +++ b/tests/functional/site/content/articles/images.md @@ -2,10 +2,12 @@ title: Images! slug: images publishedAt: "2022-07-20 12:35:00" +image: assets/images/sigwin.svg --- This is a database lookup example: {{yassg_get('articles', '/hello-world.md').title}} -This is an asset lookup: {{asset('assets/images/sigwin.svg')}} +This is an asset lookup: {{asset(item.image)}} + +![Logo]({{ asset(item.image) }}) -![Logo]({{asset('assets/images/sigwin.svg')}}) diff --git a/tests/functional/site/fixtures/en/article/images/index.html b/tests/functional/site/fixtures/en/article/images/index.html index 40df42b..a765b0d 100644 --- a/tests/functional/site/fixtures/en/article/images/index.html +++ b/tests/functional/site/fixtures/en/article/images/index.html @@ -18,7 +18,7 @@

Images!

20.07.2022. 12:35

This is a database lookup example: Hello World!

This is an asset lookup: /sub/dir/another/assets/images/sigwin.6f9a3d5b.svg

-

Logo

+

Logo

diff --git a/tests/functional/site/src/Model/Article.php b/tests/functional/site/src/Model/Article.php index e03a1a5..7ef55a6 100644 --- a/tests/functional/site/src/Model/Article.php +++ b/tests/functional/site/src/Model/Article.php @@ -20,6 +20,7 @@ final class Article public string $title; public string $slug; public string $body; + public string $image; #[Context(['datetime_format' => 'Y-m-d H:i:s'])] public \DateTimeInterface $publishedAt; From d8f999595bbad9c39d4b8561f033e41049d868e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 7 Dec 2023 17:34:17 +0100 Subject: [PATCH 7/8] feat: Twig (!) in Markdown --- psalm.baseline.xml | 1 + src/Decoder/MarkdownFileDecoder.php | 1 + 2 files changed, 2 insertions(+) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 5294452..5e2d639 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -656,6 +656,7 @@ $publishedAt $slug $title + $image Article diff --git a/src/Decoder/MarkdownFileDecoder.php b/src/Decoder/MarkdownFileDecoder.php index ab14dc6..e3aa595 100644 --- a/src/Decoder/MarkdownFileDecoder.php +++ b/src/Decoder/MarkdownFileDecoder.php @@ -46,6 +46,7 @@ public function decode(\SplFileInfo $file): array if (\count($parts) !== 2) { throw new \RuntimeException('Failed to extract frontmatter'); } + /** @var array $metadata */ $metadata = Yaml::parse($parts[0]); } From 2788682d72692238a81394e9db71b73c779d693f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 7 Dec 2023 17:41:53 +0100 Subject: [PATCH 8/8] feat: Twig (!) in Markdown --- config/services.yaml | 1 - psalm.baseline.xml | 10 ---------- .../Symfony/ExpressionLanguage/FunctionProvider.php | 6 ------ 3 files changed, 17 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index d9e11aa..5486e73 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -38,7 +38,6 @@ services: arguments: $locator: !tagged_locator { tag: 'sigwin_yassg.database', index_by: 'name' } - Symfony\Component\ExpressionLanguage\ExpressionLanguage: '@sigwin_yassg.expression_language' sigwin_yassg.expression_language: class: Symfony\Component\ExpressionLanguage\ExpressionLanguage calls: diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 5e2d639..318662d 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -18,16 +18,6 @@ Page
- - - ExpressionDelimiter - - - - - ExpressionRenderer - - GenerateCommand diff --git a/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php b/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php index 71f3ed7..430225c 100644 --- a/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php +++ b/src/Bridge/Symfony/ExpressionLanguage/FunctionProvider.php @@ -14,20 +14,14 @@ namespace Sigwin\YASSG\Bridge\Symfony\ExpressionLanguage; use Sigwin\YASSG\DatabaseProvider; -use Symfony\Component\Asset\Packages; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; final class FunctionProvider implements ExpressionFunctionProviderInterface { - public function __construct(private Packages $packages) {} - public function getFunctions(): array { return [ - new ExpressionFunction('asset', static fn (string $url): string => sprintf('$packages->getUrl(%s)', $url), function (array $variables, string $url) { - return $this->packages->getUrl($url); - }), new ExpressionFunction('yassg_find_all', static fn (string $name): string => sprintf('$provider->getDatabase(%s)', $name), static function (array $variables, string $name, array $arguments = []) { /** @var DatabaseProvider $provider */ $provider = $variables['provider'];