open-consul/ui/packages/consul-ui/app/helpers/render-template.js
John Cowen c5978b71e8
ui: Change URI helper to a template based approach (#9344)
This moves our uri helper to use a the template renderer we already have for rendering URLs.
2020-12-09 09:22:46 +00:00

20 lines
543 B
JavaScript

import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
// simple mustache regexp `/{{item.Name}}/`
const templateRe = /{{([A-Za-z.0-9_-]+)}}/g;
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);
}
}
compute([template, vars]) {
return render(template, vars);
}
}