rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Get file through stdin #42

Closed tissieres closed 3 years ago

tissieres commented 3 years ago

Hello,

Thanks for this great tool. I'm using it for formatting my templates with efm. It would be great if we could open the template through stdin since it would let us use it without needing to save the file beforehand. Currently, if I forgot to save the file before running djhtml, my edits are lost.

Thanks

JaapJoris commented 3 years ago

First of all, I'm really curious what you mean by efm :-)

But to answer your question: it is already possible to pipe a template to DjHTML's stdin. You can either use djhtml with no arguments:

$ cat template.html | djhtml
<h1>Hello, world!</h1>

Or you can use the "special" argument -:

$ cat template.html | djhtml -
<h1>Hello, world!</h1>

In both cases, the output will be written to stdout. If you try the -i / --in-place switch while supplying the template on stdin, you will discover the following easter egg:

$ cat template.html | djhtml -i
I’m sorry Dave, I’m afraid I can’t do that
tissieres commented 3 years ago

Thanks for your answer and sorry for missing that. I did not find any mention of this in the help or README.

I was talking about efm-langserver by the way.

JaapJoris commented 3 years ago

Well, it wouldn't be much of an easter egg if it was mentioned in the README ;-)

But you are right, standard input wasn't mentioned at all. I've updated the README to explain this behavior, minus the easter egg.