Skip to content

Commit

Permalink
Merge pull request #15 from ykshatroff/issue-14-add-v-props
Browse files Browse the repository at this point in the history
Issue #14: add uniform support for v-* / :* Vue attributes
  • Loading branch information
nonamenix authored May 3, 2017
2 parents 3f8f0d4 + 8446d81 commit 7758b6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2
31 changes: 8 additions & 23 deletions babelvueextractor/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,18 @@
DOUBLE_WAY_BINDING_END = '}}'
COMMENT_START = '<!--'
COMMENT_END = '-->'
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,
))


Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions babelvueextractor/tests/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
<div :html="gettext('Sometext')"></div>
""")
result = extract_vue(template, DEFAULT_KEYWORDS.keys(), [], TEST_OPTIONS)
self.assertListEqual(list(result), [(2, u'gettext', u'Sometext', [])])

0 comments on commit 7758b6e

Please sign in to comment.