mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
fix: convert ruby date format to php in Liquid
This commit is contained in:
parent
c1786dfb6d
commit
c8f6dd3bec
2 changed files with 37 additions and 5 deletions
|
|
@ -216,14 +216,14 @@ class Plugin extends Model
|
|||
*/
|
||||
private function applyLiquidReplacements(string $template): string
|
||||
{
|
||||
$replacements = [
|
||||
'date: "%N"' => 'date: "u"',
|
||||
'date: "%u"' => 'date: "u"',
|
||||
'%-m/%-d/%Y' => 'm/d/Y',
|
||||
];
|
||||
|
||||
$replacements = [];
|
||||
|
||||
// Apply basic replacements
|
||||
$template = str_replace(array_keys($replacements), array_values($replacements), $template);
|
||||
|
||||
// Convert Ruby/strftime date formats to PHP date formats
|
||||
$template = $this->convertDateFormats($template);
|
||||
|
||||
// Convert {% render "template" with %} syntax to {% render "template", %} syntax
|
||||
$template = preg_replace(
|
||||
|
|
@ -251,6 +251,25 @@ class Plugin extends Model
|
|||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Ruby/strftime date formats to PHP date formats in Liquid templates
|
||||
*/
|
||||
private function convertDateFormats(string $template): string
|
||||
{
|
||||
// Handle date filter formats: date: "format"
|
||||
$template = preg_replace_callback(
|
||||
'/date:\s*"([^"]+)"/',
|
||||
function ($matches): string {
|
||||
$format = $matches[1];
|
||||
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
|
||||
return 'date: "'.$convertedFormat.'"';
|
||||
},
|
||||
$template
|
||||
);
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve Liquid variables in a template string using the Liquid template engine
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue