Created
February 28, 2018 23:41
-
-
Save renzocastro/2eaed84c816c838a20639aba21753a07 to your computer and use it in GitHub Desktop.
mixin BEM on pugJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- | |
function htmlEscape(str) { | |
return str | |
.replace(/&/g, '&') | |
.replace(/"/g, '"') | |
.replace(/'/g, ''') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(/\//g, '/'); | |
}; | |
/** | |
* @param {string} className | |
* @param {string|array} modifiers | |
* @return {array} | |
*/ | |
function BEM(className, modifiers) { | |
var classes = [className]; | |
if (modifiers !== undefined) { | |
if (typeof modifiers === 'string') { | |
modifiers = [modifiers]; | |
} | |
classes = classes.concat( | |
modifiers | |
.filter(item => item !== '' && item !== undefined) | |
.map(item => classes[0] + '--' + item) | |
); | |
} | |
return classes; | |
} | |
mixin BEM(classname, modifiers) | |
div(class=BEM(classname, modifiers))&attributes(attributes) | |
block | |
// @use | |
+BEM('btn', 'primary') Enviar | |
// @output | |
// <div class="btn btn--primary">Enviar</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment