Skip to content

Commit

Permalink
added attribute function
Browse files Browse the repository at this point in the history
  • Loading branch information
smnh committed Feb 2, 2021
1 parent 223df01 commit b1ef5bb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/unibit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b1ef5bb

Please sign in to comment.