Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mustache Escaping Flag #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,11 @@ This function has been removed. The dependency that makes this function work is
You can continue using the function by manually installing the [`files_scripts_deprecated`](https://github.com/Raudius/files_scripts_deprecated) app, which bundles all the removed functions.
### mustache

`mustache(String template, [Table variables]={}): String`
`mustache(String template, [Table variables]={}, [Bool escape]=true): String`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is actually false

Also see other change request; you should leave this file unchanged and just make the docs changes directly in the class file comment.

Copy link
Author

@stellarpower stellarpower Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep, I think copilot did that and I uncommitted and recommitted. Maybe my force push didn't go through, I hate git. But it should default to true to preserve existing behaviour. Anyway, only added a couple of lines so feel free to add it in your master branch however you want if it's something you'd like to add :)


Renders a [mustache](https://mustache.github.io) template.
Renders a [mustache](https://mustache.github.io) template.
If escape is false, no escaping of special characters (for e.g. HTML) will be performed. This is suitable for use with plaintext or other file formats where no special handling is desired.

Returns the resulting string.
## Util
### create_date_time
Expand Down
11 changes: 9 additions & 2 deletions lib/Interpreter/Functions/Template/Mustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
* Returns the resulting string.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not necessary to update the docs/ markdown files, can you instead add the changes to this doc comment, I use these to generate the markdown files on each release.

*/
class Mustache extends RegistrableFunction {
public function run($template = '', $vars = []): string {
public function run($template = '', $vars = [], $escape = false): string {
if (!$vars || !is_array($vars)) {
$vars = [];
}
$vars = $this->normaliseArray($vars);

return (new Mustache_Engine(['entity_flags' => ENT_QUOTES]))->render($template, $vars);
$options = $escape ? [
'entity_flags' => ENT_QUOTES
] : [
'escape' => function($value) { return $value; }
];

return (new Mustache_Engine($options))->render($template, $vars);

}
}