pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.64k stars 1.96k forks source link

Provide single-line way of var+include or include+mixin #2253

Open thybzi opened 8 years ago

thybzi commented 8 years ago

Reading endless stackoverflow topics and tickets like #798 or #1692, all concerning "how to pass parameters to include", I've come to idea.

How is about making shortcut of:

- var arg1 = 'some value'
- var arg2 = true
- var arg3 = 42
include my-block

in the following format?

include my-block(arg1='some value', arg2=true, arg3=42)

Or maybe even more consistent way — another way of shortcut, making:

include my-block
+myBlock('some value', true, 42)

from the following format (my personal favorite, auto-translating filename to contained mixin name, or just getting first containing mixin):

include my-block('some value', true, 42)

or, if you prefer:

include my-block#myBlock('some value', true, 42)

or:

+my-block#myBlock('some value', true, 42)

or (my less favorite, but still better that currently available variants):

include my-block +myBlock('some value', true, 42)

Main purpose in to provide a simple, readable and SINGLE-LINE way of including component templates.

Possible use-case:

div.button-wrapper
  include social-button(facebook, 'Share on Facebook', 173)
  include social-button(twitter, 'Tweet it!', 2504)

and in social-button.jade:

mixin socialButton(type, caption, sharesCount)
  a.social-button(class=type, 'data-shares'=sharesCount)= caption
catherine-jones commented 8 years ago

:+1:

thybzi commented 8 years ago

Which syntax variant are you going to implement?

ForbesLindesay commented 8 years ago

I'm not sure. I'm not even certain that we will implement this feature exactly, vs. other ways of improving include/extends. I think if we do build something, the most likely option would be something like:

include(arg1='some value' arg2=true arg3=42) my-block

but I was mostly just tagging this issue to be reviewed once 2.0.0 is stabilised and released.