diff --git a/CHANGELOG.md b/CHANGELOG.md index 4435bb4..f5f6d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Version History === +### 1.2.2 +* add uniform support for `v-*` and `:*` attributes + ### 1.2.1 * add support for :text attributes * some refactoring diff --git a/VERSION b/VERSION index cb174d5..d2d61a7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.1 \ No newline at end of file +1.2.2 \ No newline at end of file diff --git a/babelvueextractor/lexer.py b/babelvueextractor/lexer.py index 3a6f2e8..a25634c 100644 --- a/babelvueextractor/lexer.py +++ b/babelvueextractor/lexer.py @@ -34,23 +34,18 @@ DOUBLE_WAY_BINDING_END = '}}' COMMENT_START = '' -HTML_ATTRIBUTE_END = '"' -TEXT_DIRECTIVE_START = 'v-text="' -HTML_DIRECTIVE_START = 'v-html="' -COLON_TEXT_DIRECTIVE_START = '\x3atext="' # 0x3a = ":" +V_DIRECTIVE_PREFIX = 'v-' +COLON_DIRECTIVE_PREFIX = '\x3a' # 0x3a = ":" -tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|(?:%s|%s|%s).*?%s)' % ( +tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|(?:%s|%s).+?=".*?")' % ( re.escape(CONST_START), re.escape(CONST_END), re.escape(RAW_HTML_TAG_START), re.escape(RAW_HTML_TAG_END), re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), re.escape(COMMENT_START), re.escape(COMMENT_END), re.escape(DOUBLE_WAY_BINDING_START), re.escape(DOUBLE_WAY_BINDING_END), - re.escape(TEXT_DIRECTIVE_START), - re.escape(HTML_DIRECTIVE_START), - re.escape(COLON_TEXT_DIRECTIVE_START), - - re.escape(HTML_ATTRIBUTE_END), + V_DIRECTIVE_PREFIX, + COLON_DIRECTIVE_PREFIX, )) @@ -136,20 +131,10 @@ def create_token(self, token_string, in_tag): _end = len(VARIABLE_TAG_END) token_type = TOKEN_VAR - elif token_string.startswith(TEXT_DIRECTIVE_START): - _start = len(TEXT_DIRECTIVE_START) - _end = len(HTML_ATTRIBUTE_END) - token_type = TOKEN_DIRECTIVE - - elif token_string.startswith(HTML_DIRECTIVE_START): - _start = len(HTML_DIRECTIVE_START) - _end = len(HTML_ATTRIBUTE_END) - token_type = TOKEN_DIRECTIVE - - elif token_string.startswith(COLON_TEXT_DIRECTIVE_START): + elif token_string.endswith('"'): token_type = TOKEN_DIRECTIVE - _start = len(COLON_TEXT_DIRECTIVE_START) - _end = len(HTML_ATTRIBUTE_END) + # eg. v-text="attr" => ['v-text=', 'attr', ''] + content = token_string.split('"')[1] if _start is not None: content = token_string[_start:-_end].strip() diff --git a/babelvueextractor/tests/test_extractor.py b/babelvueextractor/tests/test_extractor.py index 33f882c..5147b25 100644 --- a/babelvueextractor/tests/test_extractor.py +++ b/babelvueextractor/tests/test_extractor.py @@ -147,3 +147,9 @@ def test_html_directives(self): result = extract_vue(template, DEFAULT_KEYWORDS.keys(), [], TEST_OPTIONS) self.assertListEqual(list(result), [(2, u'gettext', u'Sometext', [])]) + def test_colon_directives(self): + template = FileMock(""" +
+ """) + result = extract_vue(template, DEFAULT_KEYWORDS.keys(), [], TEST_OPTIONS) + self.assertListEqual(list(result), [(2, u'gettext', u'Sometext', [])])