def testParser(self): OUT = ('simple', '', {}) self.assertEqual(parse_inline('simple'), OUT) OUT = ('with', 'a value', {}) self.assertEqual(parse_inline('with a value'), OUT) OUT = ('with', 'a value', {'and': 'args'}) self.assertEqual(parse_inline('with a value and=args'), OUT) OUT = ('with', '', {'just': 'args'}) self.assertEqual(parse_inline('with just=args'), OUT) OUT = ( 'with', 'complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top', {}) self.assertEqual( parse_inline( 'with complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top' ), OUT) OUT = ( 'with', 'complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top', { 'and': 'args' }) self.assertEqual( parse_inline( 'with complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top and=args' ), OUT) OUT = (u'with', u'complex value http://www.youtube.com/watch?v=nsBAj6eopzc', { 'and': 'args' }) self.assertEqual( parse_inline( u'with complex value http://www.youtube.com/watch?v=nsBAj6eopzc and=args' ), OUT) OUT = ('with', 'a value', { 'variant': 'variant', 'and': 'args', 'more': 'arg' }) self.assertEqual( parse_inline('with:variant a value and=args more=arg'), OUT) OUT = ('with', '', {'variant': 'avariant'}) self.assertEqual(parse_inline('with:avariant'), OUT)
def testParser(self): OUT = ('simple', '', {}) self.assertEqual(parse_inline('simple'), OUT) OUT = ('with', 'a value', {}) self.assertEqual(parse_inline('with a value'), OUT) OUT = ('with', 'a value', {'and': 'args'}) self.assertEqual(parse_inline('with a value and=args'), OUT) OUT = ('with', '', {'just': 'args'}) self.assertEqual(parse_inline('with just=args'), OUT) OUT = ('with', 'complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top', {}) self.assertEqual(parse_inline('with complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top'), OUT) OUT = ('with', 'complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top', {'and': 'args'}) self.assertEqual(parse_inline('with complex value http://www.youtube.com/watch?v=nsBAj6eopzc&hd=1&feature=hd#top and=args'), OUT) OUT = (u'with', u'complex value http://www.youtube.com/watch?v=nsBAj6eopzc', {'and': 'args'}) self.assertEqual(parse_inline(u'with complex value http://www.youtube.com/watch?v=nsBAj6eopzc and=args'), OUT) OUT = ('with', 'a value', {'variant': 'variant', 'and': 'args', 'more': 'arg'}) self.assertEqual(parse_inline('with:variant a value and=args more=arg'), OUT) OUT = ('with', '', {'variant': 'avariant'}) self.assertEqual(parse_inline('with:avariant'), OUT)
def render(matchobj): try: text = matchobj.group(1) name, value, inline_kwargs = parse_inline(text) try: cls = self._registry[name] except KeyError: raise InlineNotRegisteredError('"%s" was not found as a registered inline' % name) inline = cls(value, context=context, template_dir=template_dir, **inline_kwargs) return str(inline.render()) # Silence any InlineUnrenderableErrors unless INLINE_DEBUG is True except InlineUnrenderableError: debug = getattr(settings, "INLINE_DEBUG", False) if debug: raise else: return ""
def render(matchobj): try: text = matchobj.group(1) name, value, inline_kwargs = parse_inline(text) try: cls = self._registry[name] except KeyError: raise InlineNotRegisteredError( '"%s" was not found as a registered inline' % name) inline = cls(value, context=context, template_dir=template_dir, **inline_kwargs) return str(inline.render()) # Silence any InlineUnrenderableErrors unless INLINE_DEBUG is True except InlineUnrenderableError: debug = getattr(settings, "INLINE_DEBUG", False) if debug: raise else: return ""