Commit 6baaa5bb by Timothée Peignier

fix newlines escaping

parent 3a1e89ef
...@@ -91,7 +91,7 @@ class Compressor(object): ...@@ -91,7 +91,7 @@ class Compressor(object):
base_path = self.base_path(paths) base_path = self.base_path(paths)
for path in paths: for path in paths:
contents = self.read_file(path) contents = self.read_file(path)
contents = re.sub(r"\r?\n", "\\\\n", contents) contents = re.sub(r"\r?\n", "\\n", contents)
contents = re.sub(r"'", "\\'", contents) contents = re.sub(r"'", "\\'", contents)
name = self.template_name(path, base_path) name = self.template_name(path, base_path)
compiled += "%s['%s'] = %s('%s');\n" % ( compiled += "%s['%s'] = %s('%s');\n" % (
......
...@@ -71,12 +71,12 @@ class CompressorTest(TestCase): ...@@ -71,12 +71,12 @@ class CompressorTest(TestCase):
def test_compile_templates(self): def test_compile_templates(self):
templates = self.compressor.compile_templates(['templates/photo/list.jst']) templates = self.compressor.compile_templates(['templates/photo/list.jst'])
self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST['list'] = template('<div class="photo"> <img src="<%%= src %%>" /> <div class="caption"> <%%= caption %%> </div></div>');\n""" % TEMPLATE_FUNC) self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\n <img src="<%%= src %%>" />\n <div class="caption">\n <%%= caption %%>\n </div>\n</div>\');\n""" % TEMPLATE_FUNC)
templates = self.compressor.compile_templates([ templates = self.compressor.compile_templates([
'templates/video/detail.jst', 'templates/video/detail.jst',
'templates/photo/detail.jst' 'templates/photo/detail.jst'
]) ])
self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST['video_detail'] = template('<div class="video"> <video src="<%%= src %%>" /> <div class="caption"> <%%= description %%> </div></div>');\nwindow.JST[\'photo_detail\'] = template(\'<div class="photo"> <img src="<%%= src %%>" /> <div class="caption"> <%%= caption %%> by <%%= author %%> </div></div>\');\n""" % TEMPLATE_FUNC) self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\n <video src="<%%= src %%>" />\n <div class="caption">\n <%%= description %%>\n </div>\n</div>\');\nwindow.JST[\'photo_detail\'] = template(\'<div class="photo">\n <img src="<%%= src %%>" />\n <div class="caption">\n <%%= caption %%> by <%%= author %%>\n </div>\n</div>\');\n""" % TEMPLATE_FUNC)
def test_embeddable(self): def test_embeddable(self):
self.assertFalse(self.compressor.embeddable('images/sprite.png', None)) self.assertFalse(self.compressor.embeddable('images/sprite.png', None))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment