Closed colbin8r closed 13 years ago
Actually, after further testing, the error doesn't occur in Chrome. It recognizes the template as a single line. However, I do receive an 'Unexpected token ILLEGAL" error, and the template is still not added to the template namespace.
If you have a template that is strictly one-line, then this template works fine and is usable in Firefox 4.
Example _Template (oneline.jst)
Test Execute this in your console:
Result The result should be 'One-line template.'
That doesn't look right -- newlines in templates should be correctly escaped. Nobodies templates would ever work otherwise.
What versions of Jammit/Rails/Ruby are you running?
Rails: 3.0.4 Ruby: 1.8.7 Jammit: 0.6.0
Can you reproduce the error? Is it possible that this could be browser-specific? How is Jammit escaping newlines?
A tad of research turned up that Javascript needs backslashes at the end of lines to correctly escape line breaks in string literals. Would something along the lines of http://bit.ly/ltzzg6 (but the escaping is backwards as per my note) fix something like that?
Yes ... Jammit should be removing newlines and replacing them with \n
... take a look at jst_test_nested.js
within the test/fixtures/jammed folder.
Is the code that does this at lib/jammit/compressor.rb line 103?
Yep.
I'm fairly new to Ruby on Rails/gem development, but I found that the same line in my source looked like this: https://gist.github.com/988964
You'll need to wait for the updated version of Jammit to be released (hopefully this afternoon), or install off of master.
Thanks! Jammit 0.6.3 works like a charm.
Templates break in Opera 11.11, Chrome 11, and Firefox 4 due to an 'unterminated string literal' error.
I have Jammit configured to use the Underscore template engine and add templates to the App.Templates namespace. Here is a gist that should be able to be used to reproduce the error (if you configure assets.yml like I described above): https://gist.github.com/984934
common.jst = javascript template package delivered by jammit. You can see how it might mark the string as unterminated. application.js = script loaded after templates to test the simple template by loading it into the body (using jQuery) simple.jst = a simple template