Ticket #14502: noparse.py

File noparse.py, 911 bytes (added by David Gouldin, 14 years ago)
Line 
1from django import template
2
3register = template.Library()
4
5token_formats = {
6 template.TOKEN_TEXT: '%s',
7 template.TOKEN_VAR: '%s%%s%s' % (template.VARIABLE_TAG_START, template.VARIABLE_TAG_END),
8 template.TOKEN_BLOCK: '%s%%s%s' % (template.BLOCK_TAG_START, template.BLOCK_TAG_END),
9 template.TOKEN_COMMENT: '%s%%s%s' % (template.COMMENT_TAG_START, template.COMMENT_TAG_END),
10}
11
12@register.tag
13def noparse(parser, token):
14 token_num = 0
15 token = parser.tokens[token_num]
16 while (not (token.token_type == template.TOKEN_BLOCK and token.contents == 'endnoparse')):
17 token.contents = token_formats[token.token_type] % token.contents
18 token.token_type = template.TOKEN_TEXT
19 token_num += 1
20 token = parser.tokens[token_num]
21 del parser.tokens[token_num]
22 return NoParseNode()
23
24class NoParseNode(template.Node):
25 def render(self, context):
26 return ''
Back to Top