We're on Rails (3.0.3 / 1.9) using Jammit for static compression and all the other front-end goodies it provides. I'm trying to work Javscript templates in to replace some ugly front-end code, but it looks like the default JST compiler can't handle Windows line breaks:
assets.yml file:
embed_assets: on
javascripts:
plugins:
- app/views/**/*.jst
When I have _topicPreview.jst all on one line it compiles fine:
<div class='TopicPreview <%= typeName %>'><div class='Title'> <%= summary %> </div><div class='Meta'> <span class='LastUpdate'> <%= updatedAt %> </span> <span class='PostCount'> | <%= postsCount %> Posts | </span> <span class='LikeCount'> <%= likesCount %> Likes </span> </div></div>
The page loads and I have the JST._topicPreview([JSON version of topic]) method available. Beautiful.
Half the appeal of JST is the readability / maintainability though, so I would like my JST to have proper formatting. As soon as I add line breaks into the JST file the page throws Uncaught SyntaxError: Unexpected Token ILLEGAL
in window.JST['_topicPreview'] = template('...[the escaped JST file]...')
In the code trace I can see that it parses and escapes single quotes, so I was surprised it couldn't handle the line breaks.
Has anyone else encountered this problem? Is there a cleaner fix than hacking some extra string replaces into the template generation code?
Meta: I'm pretty new to javascript templates, but should they have their own StackOverflow tag?
Edit
Looks like this is a known issue with a pending fix to be merged into the gem.
Fix has been added to the gem. Windows developers rejoice.