- First task of v2 done, tokens can now have unlimited options attached to it

This commit is contained in:
mcndave committed 2023-02-02 16:46:46 +00:00
1 parent afeb8789b5
commit acd9f8c72e
8 files changed
+82 -41

No files matched your search

+10 -9
View File
@@ -22,7 +22,7 @@ PATTERN;
protected array $routesTarget;
public array $tokens = [ "url" , "route", "route.cacheless", "asset", "url.current", "url.parameters", "slug" ];
public array $tokens = [ "url" , "route", "asset", "slug" ];
public function __construct(string $urlBase = "", string $assetToken = "") {
$this->urlBase = trim($urlBase, "/");
@@ -31,6 +31,8 @@ PATTERN;
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : ?string
{
$opt = $context->tokenOptions($token);
switch($token) {
case "asset":
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildAssetUrl($arguments) ?>";
@@ -39,18 +41,17 @@ PATTERN;
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildRouteUrl($arguments) ?>";
case "url":
if ( in_array('parameters', $opt) ) {
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->setUrlParameters($arguments) ?>";
}
elseif ( in_array('current', $opt) ) {
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->currentUrl($arguments) ?>";
}
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildUrl($arguments) ?>";
case "url.current":
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->currentUrl($arguments) ?>";
case "url.parameters":
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->setUrlParameters($arguments) ?>";
case "slug":
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->slug($arguments) ?>";
#return \Transliterator::createFromRules(':: Any-Latin;:: NFD;:: [:Nonspacing Mark:] Remove;:: NFC;:: [:Punctuation:] Remove;:: Lower();[:Separator:] > \'-\'')->transliterate( $arguments );
}
return null;