diff --git a/src/js/components/element/element.component.ts b/src/js/components/element/element.component.ts index 6fe5a2d..f2f1ba4 100644 --- a/src/js/components/element/element.component.ts +++ b/src/js/components/element/element.component.ts @@ -62,11 +62,11 @@ export class ElementComponent if (App.config.infobar.bodyTemplate) { // Compile the body template once for all - if(!App.config.infobar.bodyTemplate.compiled) App.config.infobar.bodyTemplate = nunjucks.compile(App.config.infobar.bodyTemplate.content); + if(!App.config.infobar.bodyTemplate.compiled) App.config.infobar.bodyTemplate = App.templateModule.compile(App.config.infobar.bodyTemplate.content); options.body = App.config.infobar.bodyTemplate.render(this.element); options.body = options.body.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"'); } - else options.body = nunjucks.render('components/element/body.html.njk', options); + else options.body = App.templateModule.defaultBodyRender(options); let html = App.templateModule.render('element', options); diff --git a/src/js/modules/core/template.module.ts b/src/js/modules/core/template.module.ts index 4a802c0..9e44bf9 100644 --- a/src/js/modules/core/template.module.ts +++ b/src/js/modules/core/template.module.ts @@ -9,13 +9,27 @@ declare var commonmark; export class TemplateModule { + nunjucksEnvironment: any; + constructor() { // we can configure this path and the templates names from GoGoCarto // to override default templates // As default templates are precompiled into javascript templates.js file // if there is some templates we did not override, nunjucks will get the precompiled one - nunjucks.configure('../src/views', { autoescape: true }); + this.nunjucksEnvironment = nunjucks.configure('../src/views', { autoescape: true }); + + // Add custom filters here + this.nunjucksEnvironment.addFilter('gogotags', function(tags) { + let value = '
'; + for(let currentIndex=0;currentIndex'; + } + value += '
' + + return value; + }); } initialize(config: GoGoConfig, callback: () => void) @@ -30,7 +44,14 @@ export class TemplateModule { content = content.join('\n'); } - config.infobar.bodyTemplate.content = this.parseMarkdownSyntax(content); + if(config.infobar.bodyTemplate.isMarkdown) + { + config.infobar.bodyTemplate.content = this.parseMarkdownSyntax(content); + } + else + { + config.infobar.bodyTemplate.content = content; + } config.infobar.bodyTemplate.compiled = false; callback(); break; @@ -40,7 +61,14 @@ export class TemplateModule dataType: 'text', url: config.infobar.bodyTemplate.content, success: (data) => { - config.infobar.bodyTemplate.content = that.parseMarkdownSyntax(data); + if(config.infobar.bodyTemplate.isMarkdown) + { + config.infobar.bodyTemplate.content = this.parseMarkdownSyntax(data); + } + else + { + config.infobar.bodyTemplate.content = data; + } config.infobar.bodyTemplate.compiled = false; callback(); }, @@ -76,6 +104,16 @@ export class TemplateModule default: console.warn('[GoGoCarto] No template associated to templateName', templateName); } - return nunjucks.render(fileUrl, options); + return this.nunjucksEnvironment.render(fileUrl, options); + } + + compile(template:string): any + { + return nunjucks.compile(template, this.nunjucksEnvironment); + } + + defaultBodyRender(options: any = {}) + { + return this.nunjucksEnvironment.render('components/element/body.html.njk', options); } } \ No newline at end of file diff --git a/src/scss/components/element/_element-body.scss b/src/scss/components/element/_element-body.scss index 07ae5be..5f56e8e 100644 --- a/src/scss/components/element/_element-body.scss +++ b/src/scss/components/element/_element-body.scss @@ -1,6 +1,6 @@ .collapsible-body { - background-color: transpraent; + background-color: transparent; padding: 0; position: relative;