Skip to content

Respect keywords #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
*.egg
*.egg-info
14 changes: 14 additions & 0 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ def test_nested_extract(self):
self.assertEqual(string[1], '_') # Function name
self.assertEqual(string[2], "Test String") # Translatable string

def test_custom_keyword_extract(self):
template = StringIO("""
{{ _C("Test String") }}
{{ something }}
{% block something %}{% end %}
""")
strings = list(extract_tornado(template, ('_C', ), None, {}))
self.assertEqual(len(strings), 1)

# Ensure that the string is correct
string, = strings
self.assertEqual(string[0], 2) # Line number
self.assertEqual(string[1], '_C') # Custom function name
self.assertEqual(string[2], "Test String") # Translatable string

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tornadobabel/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def extract_tornado(fileobj, keywords, comment_tags, options):

for node in walk(template.file):
if isinstance(node, _Expression):
for lineno, func, message in extract_from_node(node):
for lineno, func, message in extract_from_node(node, keywords):
# TODO: Implement the comment feature, right now an empty
# iterable is returned
yield lineno, func, message, []