Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between Mac OSX/Windows #38

Open
johannesnagl opened this issue Jan 7, 2014 · 6 comments
Open

Difference between Mac OSX/Windows #38

johannesnagl opened this issue Jan 7, 2014 · 6 comments

Comments

@johannesnagl
Copy link

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
Copy link
Member

shama commented Jan 7, 2014

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 shama closed this as completed Jan 7, 2014
@johannesnagl
Copy link
Author

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

@shama shama reopened this Jan 7, 2014
@NessDan
Copy link

NessDan commented Sep 9, 2014

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
Copy link
Author

@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
Copy link

@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
Copy link

emealcubo commented May 23, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants