Skip to content

Commit

Permalink
Issue #11
Browse files Browse the repository at this point in the history
Custom filters are now defined in nunjucks files (see src/views/templates/element-filters/gogotags.html.njk)

______________________________________________________________________

Les filtres customs sont maintenant définis dans des fichiers nunjucks (voir src/views/templates/element-filters/gogotags.html.njk)
  • Loading branch information
regazzoj committed Aug 21, 2018
1 parent df92b33 commit ce0c01b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/js/modules/element/template-element-filters.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,21 @@ declare var commonmark;

export class TemplateElementFiltersModule
{
nunjucksEnvironment : any;
filters = [ 'gogotags' ];

public addGoGoFilters(nunjucksEnvironment)
{
this.nunjucksEnvironment = nunjucksEnvironment;

// adds custom fitlers here
this.addGoGoTags();

return this.nunjucksEnvironment;
}

private addGoGoTags()
{
this.nunjucksEnvironment.addFilter('gogotags', function(tags) {
let value = '<div class="tags-container">';
for(let currentIndex=0;currentIndex<tags.length;++currentIndex)
{
value += '<span class="gogo-tag">' + tags[currentIndex] + '</span>';
}
value += '</div>'

return value;
});
for(let currentIndex=0; currentIndex<this.filters.length; ++currentIndex)
{
let currentFilter = this.filters[currentIndex];
nunjucksEnvironment.addFilter(currentFilter, function(value) {
let objectArgument = {};
objectArgument[currentFilter] = value;
return nunjucksEnvironment.render("templates/element-filters/"+ currentFilter +".html.njk", objectArgument);
});
}

return nunjucksEnvironment;
}
}
1 change: 1 addition & 0 deletions src/views/templates/element-filters/gogotags.html.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="tags-container">{% for tag in gogotags %}<span class="gogo-tag">{{ tag }}</span>{% endfor %}</div>

0 comments on commit ce0c01b

Please sign in to comment.