Commit 10b55850 by Timothée Peignier

make actually work for real, and with python3 support

parent 83ef69f4
......@@ -10,33 +10,22 @@ from pipeline.utils import guess_type
from pipeline.templatetags.compressed import CompressedMixin
def package_css():
return ""
class PipelineExtension(CompressedMixin, Extension):
tags = set(['compressed_css', 'compressed_js'])
def parse(self, parser):
package_name = None
stream = parser.stream
tag = stream.next()
if stream.current.test('string'):
if stream.look().test('string'):
token = stream.next()
package_name = token.value
else:
package_name = parser.parse_expression().value
tag = next(parser.stream)
package_name = parser.parse_expression()
if not package_name:
raise TemplateSyntaxError("Bad package name")
raise TemplateSyntaxError("Bad package name", tag.lineno)
args = [package_name]
if tag.value == "compressed_css":
return nodes.CallBlock(self.call_method('package_css', args), [], [], [])
return nodes.CallBlock(self.call_method('package_css', args), [], [], []).set_lineno(tag.lineno)
if tag.value == "compressed_js":
return nodes.CallBlock(self.call_method('package_js', args), [], [], [])
return nodes.CallBlock(self.call_method('package_js', args), [], [], []).set_lineno(tag.lineno)
return []
......
......@@ -14,5 +14,15 @@ class ExtensionTest(TestCase):
PackageLoader('pipeline', 'templates'))
def test_no_package(self):
template = self.env.from_string(u"""{% compressed_css 'unknow' %}""")
self.assertEqual(u'', template.render(context))
template = self.env.from_string(u"""{% compressed_css "unknow" %}""")
self.assertEqual(u'', template.render())
template = self.env.from_string(u"""{% compressed_js "unknow" %}""")
self.assertEqual(u'', template.render())
def test_package_css(self):
template = self.env.from_string(u"""{% compressed_css "screen" %}""")
self.assertEqual(u'<link href="/static/screen.css" rel="stylesheet" type="text/css" />', template.render())
def test_package_js(self):
template = self.env.from_string(u"""{% compressed_js "scripts" %}""")
self.assertEqual(u'<script type="text/css" src="/static/scripts.css" charset="utf-8"></script>', template.render())
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