Suggestion to choose a "recommended" file extension for uniformity in the community

157 views
Skip to first unread message

Joel Schwartz

unread,
Feb 19, 2016, 2:14:18 PM2/19/16
to Nunjucks

Would including an "officially recommended" file extension in Nunjucks' documentation go against the philosophy of Nunjucks? Even though the compiler is agnostic, it seems like the community is interested in one. There are a number of unofficial extensions floating around: .nunjucks, .nunjs, .nunj,.njk., .njs, ...


I think this is worth discussion because (1) in absence of official direction, the community has come up with its own file extensions, and (2) Jinja2's recommendation to hijack another file extension, in my opinion, seems to contradict the purpose of file extensions. An ideal outcome from this discussion might be updating the Nunjucks documentation with a recommendation, to inspire some uniformity in the community and among all the tutorials and recipes for implementing Nunjucks.


I understand Nunjucks is based heavily on Jinja2, and that Jinja2 recommends:

A Jinja template is simply a text file. Jinja can generate any text-based format (HTML, XML, CSV, LaTeX, etc.). A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine.

But even if it doesn't need a specific extension, it would be be helpful to guide the folks that want to give it one. I agree with Carl Meyer's response to a related question I (wrongly) posted on Github:

Personally I use the .j2 extension for both Jinja2 and Nunjucks templates (in some cases I will render the same template with either renderer, so I prefer having a single extension for both). I don't agree with the recommendation in the Jinja2 docs -- an HTML file is not the same thing as a Jinja2 template of an HTML file; I'll often "stack" extensions and use e.g. .html.j2 for an HTML Jinja2 template.
That's all just my personal preference, though -- I'm not really aware of any community standard here.


I'm grabbing the list of .nunjucks, .nunjs, .nunj,.njk., and .njs from Nunjucks syntax plugins for AtomBracketsSublime, and Vim. I'm not sure what the relative prevalence is among these extensions. Maybe worth noting that .nj doesn't seem to contradict an existing extension either, if brevity is a chief concern.


Any thoughts?

Carl Meyer

unread,
Feb 19, 2016, 2:17:07 PM2/19/16
to nunj...@googlegroups.com
Thanks Joel.

On 02/19/2016 12:14 PM, Joel Schwartz wrote:
> Would including an "officially recommended" file extension in Nunjucks'
> documentation go against the philosophy of Nunjucks? Even though the
> compiler is agnostic, it seems like the community is interested in one.
> There are a number of unofficial extensions floating
> around: |.nunjucks|, |.nunjs|, |.nunj|,|.njk|., |.njs|, ...
...
> I'm grabbing the list of |.nunjucks|, |.nunjs|, |.nunj|,|.njk|.,
> and |.njs| from Nunjucks syntax plugins for Atom
> <https://github.com/alohaas/language-nunjucks/blob/master/grammars/html%20(nunjucks%20templates).cson>, Brackets
> <https://github.com/axelboc/nunjucks-brackets/>, Sublime
> <https://github.com/mogga/sublime-nunjucks/blob/master/Nunjucks.tmLanguage>,
> and Vim
> <https://github.com/Glench/Vim-Jinja2-Syntax/blob/master/ftdetect/jinja.vim>.
> I'm not sure what the relative prevalence is among these extensions.
> Maybe worth noting that .nj doesn't seem to contradict an existing
> extension
> <https://en.wikipedia.org/wiki/List_of_filename_extensions_(M%E2%80%93R)> either,
> if brevity is a chief concern.

FWIW I'd be happy with documenting `.nj` as the standard extension for
Nunjucks templates.

Carl

signature.asc

David Kebler

unread,
Feb 19, 2016, 3:11:54 PM2/19/16
to nunj...@googlegroups.com
.nj works for me just something shorter than nunjucks.  

Three letter extensions like njs  njk are more old school and easier to probably remember months on  "oh yea that's a nunjucks file" and thus appealing.  Too they are less likely to be adopted by some other project in the future.



--
You received this message because you are subscribed to the Google Groups "Nunjucks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunjucks+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers, Cuidate, TTFN
David

Carl Meyer

unread,
Feb 19, 2016, 3:29:23 PM2/19/16
to nunj...@googlegroups.com
On 02/19/2016 01:11 PM, David Kebler wrote:
> .nj works for me just something shorter than nunjucks.
>
> Three letter extensions like njs njk are more old school and easier to
> probably remember months on "oh yea that's a nunjucks file" and thus
> appealing. Too they are less likely to be adopted by some other project
> in the future.

.njs and .njk are fine with me too. This is a case where whoever paints
the bikeshed (i.e. actually submits a pull request for the docs) will
get to pick the color, because I don't care at all between those three.
(Just don't want anything longer than three characters.)

Carl

signature.asc

Tory Berra

unread,
Feb 19, 2016, 11:07:20 PM2/19/16
to Nunjucks
my vote is .njk

David Kebler

unread,
Feb 20, 2016, 3:27:15 PM2/20/16
to Nunjucks
So  as a final method of choosing I asked a total non-coder to abbreviate nunjucks to either njk or njs.   She chose njk.  So it is.

painted this in the AM with https://github.com/mozilla/nunjucks/pull/687  
Put in top of the "Templating" section hope that's the best place?

--
You received this message because you are subscribed to the Google Groups "Nunjucks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunjucks+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joel Schwartz

unread,
Feb 20, 2016, 4:39:45 PM2/20/16
to David Kebler, Nunjucks
Sounds great to me.
You received this message because you are subscribed to a topic in the Google Groups "Nunjucks" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nunjucks/mJbJ96OPUGQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nunjucks+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages