Created
March 22, 2018 20:00
-
-
Save thatisuday/3a17a7bd4e6735914f00bed3169261bc to your computer and use it in GitHub Desktop.
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
//- Mixin is used to create reusable block of code. | |
//- Mixin is just a wrapper around proper Pug code. | |
//- Mixin can also be a function with arguments. | |
mixin notAllowed | |
p: b You are not allowed here | |
mixin user(data) | |
li | |
p.name= data.name | |
p.city= data.city | |
//- to use mixin, just use `+` plus operator with mixin name | |
.critical-section | |
+notAllowed | |
- | |
var users = [ | |
{name: "Ross Geller", city: "New York"}, | |
{name: "Monica Geller", city: "Little Rock"}, | |
] | |
ul.user-list | |
for data in users | |
+user(data) | |
//- Mixin has a internal `block` variable which refers to the content of mixin. | |
//- If mixin is used like a tag, then `block` variable will have that content, else it will be empty. | |
mixin user(data) | |
li | |
p.name= data.name | |
p.city= data.city | |
.meta | |
if block | |
block | |
else | |
p This user has no meta information. | |
ul.user-list | |
+user({name: "Ross Geller", city: "New York"}) | |
p Ross likes Rachel. | |
+user({name: "Monica Geller", city: "Little Rock"}) | |
//- Mixin has a internal `attributes` variable. | |
mixin user(data) | |
li(class!=attributes.class) | |
p.name= data.name | |
p.city= data.city | |
.meta | |
if block | |
block | |
else | |
p This user has no meta information. | |
ul.user-list | |
+user({name: "Ross Geller", city: "New York"})(class="active") | |
p Ross likes Rachel. | |
+user({name: "Monica Geller", city: "Little Rock"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment