Commit 4143c788 by Timothée Peignier

ensure we give a proper name to template even if there is only one template

parent a44d5a99
......@@ -94,6 +94,8 @@ class Compressor(object):
"""Find out the name of a JS template"""
if not base:
path = os.path.basename(path)
if path == base:
base = os.path.dirname(path)
name = re.sub(r"^%s\/?(.*)%s$" % (
re.escape(base), re.escape(settings.PIPELINE_TEMPLATE_EXT)
), r"\1", path)
......
<div class="photo">
<img src="<%= src %>" />
<div class="caption">
<%= caption %> by <%= author %>
</div>
</div>
\ No newline at end of file
<div class="video">
<video src="<%= src %>" />
<div class="caption">
<%= description %>
</div>
</div>
\ No newline at end of file
......@@ -65,6 +65,15 @@ class CompressorTest(TestCase):
name = self.compressor.template_name('templates/photo_edit.jst', '')
self.assertEquals(name, 'photo_edit')
def test_compile_templates(self):
templates = self.compressor.compile_templates(['templates/photo/list.jst'])
self.assertEquals(templates, """window.JST = window.JST || {};\nwindow.JST['list'] = _.template('<div class="photo"> <img src="<%= src %>" /> <div class="caption"> <%= caption %> </div></div>');\n""")
templates = self.compressor.compile_templates([
'templates/video/detail.jst',
'templates/photo/detail.jst'
])
self.assertEqual(templates, """window.JST = window.JST || {};\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""")
def test_embeddable(self):
self.assertFalse(self.compressor.embeddable('images/sprite.png', None))
self.assertFalse(self.compressor.embeddable('images/arrow.png', 'datauri'))
......
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