def render(self, context): #Check if in debug mode if self.debug_mode(context) or not settings.LABJS_ENABLED: return self.nodelist.render(context) # Check if we should allow labks to perform for IE6/7 # As it seems to have some issues in some cases. request = context.get('request', None) if request and not settings.LABJS_IE7IE6_ENABLED: agent = request.META.get('HTTP_USER_AGENT', '').lower() if "msie 7" in agent or "msie 6" in agent: return self.nodelist.render(context) if self.debug_mode(context) or not settings.LABJS_ENABLED: return self.nodelist.render(context) # call compressor output method and handle exceptions rendered_output = Labjs(content=self.nodelist.render(context),context=context).render_output() return rendered_output
def test_render_output_script_contains_src(self): lab = Labjs('<script src="/static/script.js"></script>') self.assertIn('/static/script.js', lab.render_output())
def test_render_output_inline_contains_script(self): lab = Labjs('<script>document.write("Hello world");</script>') self.assertIn('document.write("Hello world");', lab.render_output())
def test_split_contents_script(self): lab = Labjs('<script src="/static/script.js"></script>') self.assertEqual( lab.split_contents(), [{'data': '/static/script.js', 'type': 'script'}] )
def test_split_contents_inline(self): lab = Labjs('<script>document.write("Hello world");</script>') self.assertEqual( lab.split_contents(), [{'data': 'document.write("Hello world");', 'type': 'inline'}] )
def test_split_contents_non_js_content(self): lab = Labjs('<p class="test">I am not JS</p>') self.assertFalse(lab.split_contents())
def test_split_contents_empty_content(self): lab = Labjs('') self.assertFalse(lab.split_contents())