From b1ef5bb7d1877cc9aa9e5d567c30fb299f3808ad Mon Sep 17 00:00:00 2001 From: Simon Hanukaev Date: Tue, 2 Feb 2021 22:27:08 +0200 Subject: [PATCH] added attribute function --- src/unibit.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/unibit.js b/src/unibit.js index 30e74b9..81332ab 100644 --- a/src/unibit.js +++ b/src/unibit.js @@ -244,6 +244,7 @@ module.exports = class Unibit { context.paginate = this.paginate.bind(this, context); context.link = this.link.bind(this, context.site); context.classNames = this.classNames.bind(this); + context.attribute = this.attribute.bind(this); // this.logger.log("context:\n" + JSON.stringify(context, null, 4)); return context; @@ -489,6 +490,19 @@ module.exports = class Unibit { } } + attribute(name, value, condition) { + if (typeof condition === 'undefined') { + condition = true; + } + if (!condition) { + return ''; + } + if (value === null) { + return this.env.filters.safe(name); + } + return this.env.filters.safe(`${name}="${value}"`); + } + } class LinkExtension {