{{ message }}
feat(core): expressive content replacement#139
Draft
stephancill wants to merge 1 commit into
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
davidfurlong
approved these changes
Dec 25, 2023
davidfurlong
left a comment
Contributor
There was a problem hiding this comment.
I like using existing standards for this.
however I'm a bit hesitant of this exact implementation, as
- mustache hasn't had a commit in a year
- I'm concerned about how many functions will be needed to support all the edge cases
however I think it'll be reasonably easy to change later so I'm ok with going with it
| import Mustache from "mustache"; | ||
|
|
||
| // Prevent default HTML escaping behaviour | ||
| Mustache.escape = function (value) { |
Contributor
There was a problem hiding this comment.
overriding globals is probably not a good idea given that this code is executed in the same context as other apps
| return target.replace(/{{([^{{}}]+)}}/g, (_, key) => get(context, key, ``)); | ||
| const output = Mustache.render(target, { | ||
| ...context, | ||
| decimals: function () { |
Contributor
There was a problem hiding this comment.
with this pattern, this list of functions is going to grow very long and it'll be bundled into every app.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Change Summary
This PR proposes a standard syntax for string manipulation inside Mod elements by adopting mustache.js. This library is lightweight at 6.5kb minified or 2.7kb minified+gzipped (bundlephobia) and uses a familiar
{{}}syntax for replacement as well aspath.to.valuesyntax for accessing nested context values, making it backwards compatible.Arbitrary functions can be exposed to the mustache syntax in the
replaceInlineContextfunction by passing anonymous function builders along with the context to the rendering function (see theLambdassection in the manual and spec).An example adjustment to the
replaceInlineContextfunction which introduces adecimalsoperator which displays a number to a fixed number of decimals would look like this:And would be used like this:
Merge Checklist