smartntml/ts/index.ts
2023-03-30 11:02:15 +02:00

40 lines
1.2 KiB
TypeScript

import * as plugins from './smartntml.plugins.js';
import * as deesElement from '@designestate/dees-element';
export class Smartntml {
// STATIC
public static async create() {
const smartntml = new Smartntml();
return smartntml;
}
private static smartntmlSingletonDeferred: plugins.smartpromise.Deferred<Smartntml>;
public static async createSingleton() {
if (this.smartntmlSingletonDeferred) {
return this.smartntmlSingletonDeferred.promise;
}
this.smartntmlSingletonDeferred = plugins.smartpromise.defer();
const smartntmlInstance = await this.create();
this.smartntmlSingletonDeferred.resolve(smartntmlInstance);
return this.smartntmlSingletonDeferred.promise;
}
// INSTANCE
private render = deesElement.render;
public html = deesElement.html;
public unsafeHTML = deesElement.unsafeHTML;
constructor() {
}
public async renderTemplateResult(templateResult: deesElement.TemplateResult, stripCommentsArg = true) {
const element = document.createElement('div');
this.render(templateResult, element);
let stringResult = element.innerHTML;
if (stripCommentsArg) {
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
}
return stringResult;
}
}