2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-09 09:22:46 +00:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import { inject as service } from '@ember/service';
|
2020-10-05 13:10:00 +00:00
|
|
|
|
2021-11-10 17:54:33 +00:00
|
|
|
// simple mustache regexp `/{{item.Name}}/`
|
|
|
|
const templateRe = /{{([A-Za-z.0-9_-]+)}}/g;
|
2020-12-09 09:22:46 +00:00
|
|
|
let render;
|
|
|
|
export default class RenderTemplateHelper extends Helper {
|
|
|
|
@service('encoder') encoder;
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
if (typeof render !== 'function') {
|
|
|
|
render = this.encoder.createRegExpEncoder(templateRe, encodeURIComponent, false);
|
|
|
|
}
|
2020-10-05 13:10:00 +00:00
|
|
|
}
|
2020-12-09 09:22:46 +00:00
|
|
|
|
|
|
|
compute([template, vars]) {
|
|
|
|
return render(template, vars);
|
|
|
|
}
|
|
|
|
}
|