gruntjs / grunt-contrib-jst

Compile underscore templates to JST file.
http://gruntjs.com/
MIT License
113 stars 45 forks source link

Difference between Mac OSX/Windows #38

Open johannesnagl opened 10 years ago

johannesnagl commented 10 years ago

We're having a multi-platform dev-environment setup.

Most of our users are having OS X, whereas one brave team member is using Windows.

If he is building templates, the js code is translated to "\r\n" for every linebreak. when building the exact same template on OSX, it's changed to "\n" instead because the two platforms deal linebreaks differently.

is there any chance to have an (streamlining-)option within jst?

shama commented 10 years ago

Try the separator option: https://github.com/gruntjs/grunt-contrib-jst#separator It defaults to grunt.util.linefeed + grunt.util.linefeed. Just change it to options: { separator: '\n' }.

johannesnagl commented 10 years ago

Hi @shama. Thx for your quick response. the described problem is not the due to the concatenation of more than one file, it consists within one single template itself. let's have the following example:

<div>
  <strong><%=status%></strong>
</div>

and compare it to these two outputs

Mac OSX (with \n):

with (obj) __p += "<div>\n  <strong>" + (null == (__t = status) ? "" : __t) + "</strong>\n</div>";

Windows 7 (with \r\n):

with (obj) __p += "<div>\r\n  <strong>" + (null == (__t = status) ? "" : __t) + "</strong>\r\n</div>";
NessDan commented 10 years ago

Johannes - I'm happy I'm not alone!

I just joined a team and am the lone Windows user. After running grunt on my Windows machine, the compiled files have "\r\n" where linefeeds exist. The only issue is that my Mac coworkers who run the same command get "\n" in their compiled output.

We're using grunt-contrib-handlebars.

johannesnagl commented 10 years ago

@NessDan sorry, we're switched to gulpjs in the meantime. afaik we hadn't found any solution for this problem though. is that correct, windows-team-mate @catearcher?

catearcher commented 10 years ago

@NessDan @johannesnagl No solution, but a workaround: Step 1: Add a .gitattributes file to your JS templates folder, containing the following line: * text eol=lf Step 2: git commit -a -m (...) Step 3: git rm --cached -r . Step 4: git reset --hard

Now all your template files have unix line endings, and all future templates will have them, too. This means that line endings in your compiled templates will also be the same on Windows, Linux and Mac OS.

More info: https://help.github.com/articles/dealing-with-line-endings

emealcubo commented 5 years ago

As this issue is still open, I found a really easy solution and I wanted to share it for anyone who could have the same problem. The only thing you need to do to fix this is to use the processContent option with a replace:

processContent: function(src) { return src.replace(/\r\n/g, "\n"); }