Glavin001 / atom-beautify

:mega: Help Wanted - Looking for Maintainer: https://github.com/Glavin001/atom-beautify/issues/2572 | :lipstick: Universal beautification package for Atom editor (:warning: Currently migrating to https://github.com/Unibeautify/ and have very limited bandwidth for Atom-Beautify Issues. Thank you for your patience and understanding :heart: )
http://unibeautify.com/
MIT License
1.5k stars 453 forks source link

Underscore template with .TPL extension gets destroyed by beautify #325

Open nikmartin opened 9 years ago

nikmartin commented 9 years ago

I use client side underscore templates using requirejs and the text plugin, with a .tpl extension My templates look like normal ejs/underscore style templates:

<td><%= data.eScene ? data.eScene.eScene_15 : '???' %></td>
<td><%= data.eDispatch ? data.txReason[data.eDispatch.eDispatch_01] : '???' %></td>

The file is detected as 'HTML' byt atom, and on saving it gets beautified into:

<td>
  <%=d ata.eScene ? data.eScene.eScene_15 : '???' %>
</td>
<td>
  <%=d ata.eDispatch ? data.txReason[data.eDispatch.eDispatch_01] : '???' %>
</td>

note the space: <%=d ata

This pretty much hoses my files. Is there a way to NOT beautify anything inside "<% * "%>", or to map .tpl to ejs? in the status bar, the fiel type is listed as 'HTML' and if i try to change that, ejs is not a choice

nikmartin commented 9 years ago

Also, atom-beautify is version 0.27.0

Glavin001 commented 9 years ago

Install language-ejs first and then try changing the grammar in Atom to JavaScript Template (EJS). You were on the right track. Let me know if that works.

nikmartin commented 9 years ago

Looks good! I was not aware that I needed to install a language support package.

Glavin001 commented 9 years ago

If that works for beautifying .TPL then I would like to add explicit support for it, instead of this work around.

What language package do you use for TPL extension and could you provide a nice sample input file so I could add to the tests. Thanks!

nikmartin commented 9 years ago

OK sure. I use lodash and/or underscore templates, and they are functionally equivalent to EJS. The tpl extension is of my own making, since I wanted to distinguish them from server-side ejs templates which I also use. A .tpl is typically NOT a complete html file and does not embed a template using <script></script> tags.

Here is a self contained template that works using underscore.js AND lodash.js: https://gist.github.com/nikmartin/d19c65ae5a07c19bbfef Since this is a proper HTML file <script type="text/template" class="template"> ...</script> is properly beautified if the file Grammar is HTML.

A test case of using a pure inline template with require.js is: https://gist.github.com/nikmartin/c04980c85ac0d6b6c11b It currently gets beautified properly when the Grammar is set to 'JavaScript Template' This is a standalone inline .tpl that would be typical using client side .tpl files that are included at runtime using require.js I intentionally uglified it to see if it gets beautified peoperly, and it does.

nikmartin commented 9 years ago

Actually, this is a test that fails. the href gets stripped from links:

`<%= data.a %>

<%= data.b %>

`

Glavin001 commented 9 years ago

/cc @prettydiff any ideas on the failing test above?

Glavin001 commented 9 years ago

Let me know when this is working on Pretty Diff and it can be expedited on Atom Beautify. Thanks!