Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottrobin/2f0c6690421eadecc82c4b2cbc1182cc to your computer and use it in GitHub Desktop.
Save nottrobin/2f0c6690421eadecc82c4b2cbc1182cc to your computer and use it in GitHub Desktop.
Convert Django templates' `{% include with ... %}` syntax to Jinja2's `{% with ... %}{% include %}{% endwith %}`
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\",\n \$10=\"\$11\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\",\n \$10=\"\$11\",\n \$12=\"\$13\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\",\n \$10=\"\$11\",\n \$12=\"\$13\",\n \$14=\"\$15\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\",\n \$10=\"\$11\",\n \$12=\"\$13\",\n \$14=\"\$15\",\n \$16=\"17\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment