Created
February 22, 2017 10:50
-
-
Save govorov/b40ca2e1e9f49677719e2b50be7875f9 to your computer and use it in GitHub Desktop.
pug mixins for underscore template engine
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
| //- 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