2020-07-17 13:42:45 +00:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
2020-12-09 09:22:46 +00:00
|
|
|
const templateRe = /\${([A-Za-z.0-9_-]+)}/g;
|
|
|
|
let render;
|
2020-12-08 09:27:28 +00:00
|
|
|
export default class UriHelper extends Helper {
|
|
|
|
@service('encoder') encoder;
|
2020-12-09 09:22:46 +00:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
if (typeof render !== 'function') {
|
|
|
|
render = this.encoder.createRegExpEncoder(templateRe, encodeURIComponent);
|
|
|
|
}
|
|
|
|
}
|
2020-12-08 09:27:28 +00:00
|
|
|
|
2020-12-09 09:22:46 +00:00
|
|
|
compute([template, vars]) {
|
|
|
|
return render(template, vars);
|
2020-12-08 09:27:28 +00:00
|
|
|
}
|
|
|
|
}
|