From 5cd7fa5016900383b00aa9a431fe71d187d1871f Mon Sep 17 00:00:00 2001 From: regazzoj Date: Mon, 13 Aug 2018 13:26:11 +0200 Subject: [PATCH] Issue #11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add 'isMarkdown' property to 'bodyTemplate' object, on true, the content will be parsed thanks to the Markdown syntax Add possibility to create custom filters and add one example 'gogotags' in 'src/js/modules/core/template.module.ts' file Correction typo in the scss file _____________________________________________________________________ Ajout d'une propriété 'isMakrdown' dans l'objet 'bodyTemplate', si true, le contenu sera parsé selon la syntaxe Markdown Ajout de la possibilité de créer des filtres customs et ajout d'un exemple 'gogotags' dans le fichier' src/js/modules/core/template.module.ts' Correction d'une typo dans le fichier scss --- .../components/element/element.component.ts | 4 +- src/js/modules/core/template.module.ts | 46 +++++++++++++++++-- .../components/element/_element-body.scss | 2 +- 3 files changed, 45 insertions(+), 7 deletions(-) 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;