Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When calling a mixin in Jade, what's the difference between "+" and mixin keyword?

The docmentation tells us to call a mixin by prepending the keyword mixin to the actual mixin.

.bar
    mixin foo(arguments)

But on different places I saw people calling a mixin by prepending a plus (+) sign, like:

.bar
    +foo(arguments)

Could someone please explain the difference since the documentation does not seem to show it. I tried both examples and both seemed to work.

Is + just a shorthand?

like image 995
Saucier Avatar asked Apr 26 '13 10:04

Saucier


People also ask

What is a jade mixin?

Mixins in Jade are much like functions/methods in many other programming languages. Basically, if you're repeating your code at many places, you could place that code inside a mixin and replace your code with the mixin call. This would make your code cleaner and maintainable over long run.

What is Jade in node?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.

Why use Jade view engine?

It's used to produce XML documents like (HTML, RSS etc.), so we can't use it to create the plain text like HTML/CSS other documents. Jade Template Engine is used to make the template more beautiful and more meaningful with the help of description and their layout.


1 Answers

Yes, it appears so. If you look at lib/lexer.js in the Call mixin section, you can see that terms beginning with a + get tokenized with type call. Later in lib/parser.js the call token causes parseCall to create a new mixin invocation node.

Furthermore the commit was made with with the comment:

Added preliminary mixin block support and the new + mixin invocation syntax.

like image 190
David Weldon Avatar answered Sep 23 '22 16:09

David Weldon