Ticket #2721: commentable_block_tags.patch
File commentable_block_tags.patch, 2.9 KB (added by , 18 years ago) |
---|
-
django/template/__init__.py
66 66 TOKEN_TEXT = 0 67 67 TOKEN_VAR = 1 68 68 TOKEN_BLOCK = 2 69 TOKEN_COMMENT = 3 69 70 70 71 # template syntax constants 72 COMMENT_IDENTIFIER = '#' 71 73 FILTER_SEPARATOR = '|' 72 74 FILTER_ARGUMENT_SEPARATOR = ':' 73 75 VARIABLE_ATTRIBUTE_SEPARATOR = '.' … … 163 165 164 166 class Token(object): 165 167 def __init__(self, token_type, contents): 166 "The token_type must be TOKEN_TEXT, TOKEN_VAR or TOKEN_BLOCK"168 "The token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, or TOKEN_COMMENT" 167 169 self.token_type, self.contents = token_type, contents 168 170 169 171 def __str__(self): 170 172 return '<%s token: "%s...">' % \ 171 ({TOKEN_TEXT: 'Text', TOKEN_VAR: 'Var', TOKEN_BLOCK: 'Block' }[self.token_type],173 ({TOKEN_TEXT: 'Text', TOKEN_VAR: 'Var', TOKEN_BLOCK: 'Block', TOKEN_COMMENT: 'Comment'}[self.token_type], 172 174 self.contents[:20].replace('\n', '')) 173 175 174 176 def split_contents(self): … … 190 192 if token_string.startswith(VARIABLE_TAG_START): 191 193 token = Token(TOKEN_VAR, token_string[len(VARIABLE_TAG_START):-len(VARIABLE_TAG_END)].strip()) 192 194 elif token_string.startswith(BLOCK_TAG_START): 193 token = Token(TOKEN_BLOCK, token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip()) 195 token_string = token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip() 196 if token_string.startswith(COMMENT_IDENTIFIER): 197 token = Token(TOKEN_COMMENT, token_string) 198 else: 199 token = Token(TOKEN_BLOCK, token_string) 194 200 else: 195 201 token = Token(TOKEN_TEXT, token_string) 196 202 return token -
tests/regressiontests/templates/tests.py
170 170 # Escaped backslash using known escape char 171 171 'basic-syntax35': (r'{{ var|default_if_none:"foo\now" }}', {"var": None}, r'foo\now'), 172 172 173 ### COMMENTED BLOCK TAGS #################################################### 174 'commented-block-tag01': ("{% #invalidtag %}commented invalid tag", {}, "commented invalid tag"), 175 'commented-block-tag02': ("commented valid tag{% # if %}", {}, "commented valid tag"), 176 'commented-block-tag03': ("{% comment %}hide{% #endcomment %}still hide{% endcomment %}show", {}, "show"), 177 173 178 ### COMMENT TAG ########################################################### 174 179 'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"), 175 180 'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"),