Skip to content

Instantly share code, notes, and snippets.

@govorov
Created February 22, 2017 10:50
Show Gist options
  • Select an option

  • Save govorov/b40ca2e1e9f49677719e2b50be7875f9 to your computer and use it in GitHub Desktop.

Select an option

Save govorov/b40ca2e1e9f49677719e2b50be7875f9 to your computer and use it in GitHub Desktop.
pug mixins for underscore template engine
//- pug mixins for underscore template engine
//- Examples:
+if('js_expression')
div ...
+else
div ...
+endIf
+each('js_arr','obj,key')
|{{key}} : {{obj.prop}}
+endEach
mixin if(condition)
-var str = `{!!{if (${condition}) { }}`
|!{str}
if block
block
mixin else
-var str = "{!!{ } else { }}"
|!{str}
if block
block
mixin elseIf(condition)
-var str = `{!!{ } else if (${condition}) { }}`
|!{str}
if block
block
mixin endIf
-var str = "{!!{ } }}"
|!{str}
mixin each(obj,args)
-var str = `{!!{ _.each(${obj},function(${args}){ }}`
|!{str}
if block
block
mixin endEach
-var str = "{!!{ }); }}"
|!{str}
mixin repeat(n)
-var str = `{!!{var n = ${n}; for (var i = 1; i <= n; i++) { }}`
|!{str}
if block
block
mixin endRepeat
-var str = "{!!{ } }}"
|!{str}
-var _if = (condition,value) => { return `{!!{ if(${condition}) { }} ${value} {!!{ } }}` }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment