How can I build a tag file for Django templates, in order to jump to file definitions of extends
and include
template tags?
Here's the script PROJECT/.git/hooks/ctags-html
I've tried so far
#!/bin/sh
set -e
PATH="/usr/local/bin:$PATH"
dir="`git rev-parse --git-dir`"
trap 'rm -f "$dir/$$.tags-html"' EXIT
git ls-files | \
# DOC: ctags --list-kinds-full | grep -i html
ctags -R --fields=+l --languages=html \
--regex-html='/extends \"([a-zA-Z0-9_-]+\.html)\"/\1/t,templates/' \
--html-kinds=+at \
-f"$dir/$$.tags-html" $(python -c "import os, sys; print(' '.join('{}'.format(d) for d in sys.path if os.path.isdir(d)))")
mv "$dir/$$.tags-html" "$dir/tags-html"
In short, the script does:
- Find my git repo files
- call ctags with html parser on all git repo files + other files from related python packages.
- generate tags for anchor
<a>
elements and template tag{% extends "" %}
When I call ./git/hooks/ctags.html
, a .git/tags-html
file is generated
…
base.html /home/dori/.virtualenvs/env/lib/python3.7/site-packages/wagtail/project_template/home/templates/home/home_page.html /^{% templatetag openblock %} extends "base.html" {% templatetag closeblock %}$/;" t language:HTML
base.html /home/dori/.virtualenvs/env/lib/python3.7/site-packages/wagtail/project_template/project_name/templates/404.html /^{% templatetag openblock %} extends "base.html" {% templatetag closeblock %}$/;" t language:HTML
base.html /home/dori/.virtualenvs/env/lib/python3.7/site-packages/wagtail/project_template/search/templates/search/search.html /^{% templatetag openblock %} extends "base.html" {% templatetag closeblock %}$/;" t language:HTML
But then, when opening a template file with vim
{% extends "base.html" %}
{% load i18n wagtailcore_tags wagtailimages_tags static %}
{% load debugger_tags %}
{% block body_class %}template-blogpage{% endblock %}
When I set the cursor on base.html
and press CTRL-]
to go to the definition, I only get E426: tag not found: base
.