grunt-contrib-jst icon indicating copy to clipboard operation
grunt-contrib-jst copied to clipboard

Difference between Mac OSX/Windows

Open johannesnagl opened this issue 11 years ago • 6 comments

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?

johannesnagl avatar Jan 07 '14 15:01 johannesnagl

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' }.

shama avatar Jan 07 '14 16:01 shama

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>";

johannesnagl avatar Jan 07 '14 17:01 johannesnagl

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.

NessDan avatar Sep 09 '14 14:09 NessDan

@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?

johannesnagl avatar Sep 10 '14 16:09 johannesnagl

@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

catearcher avatar Sep 11 '14 08:09 catearcher

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"); }

emealcubo avatar May 23 '19 12:05 emealcubo