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

Use Jinja-like attribute substitution syntax #254

merged 4 commits into from Apr 28, 2018


None yet
1 participant

ubruhin commented Apr 22, 2018

See motivation for this change in LibrePCB/librepcb-rfcs#14.

This PR changes the attribute substitution syntax from e.g. #NAME to {{NAME}}, which corresponds to the Jinja2 syntax.

Beside the disadvantage of the more verbose syntax (3 characters more), it has several advantages:

  • Escaping is very unlikely necessary (# may sometimes be used as raw character, but {{ probably not).
  • End of key is manually specified by }}, so it's always clear where the substitution ends. In the old syntax it was not possible to only substitute for example "FOO" in #FOObar. To work around that limitation, we defined || as a manual end, which looked very strange (#FOO||bar).
  • Fallbacks can be written very elegant. For example {{ FOO or BAR or 'foobar' }} evaluates to the value of FOO if it's non-empty. If it's empty, it evaluates to the value of BAR. If this is also empty, it evaluates to the literal "foobar". In the old syntax this was written as #FOO|BAR, while the fallback to literals was not supported. Note: This is actually not a Jinja2 feature, but part of the Python language.
  • If we need more functionality some time in future, Jinja2 provides much more functionality which we may support too. For example filters may be helpful in some use-cases.

Maybe this sounds a bit over engineered at this time, but I think it's better to switch now (before the first release) to a more powerful, future-oriented syntax. After publishing the first release of LibrePCB it would be a pain to change the attribute substitution syntax...

Btw, if you wonder what the fallback feature is useful for, in the Multiple Key Substitution documentation there is a real-world use case explained.

How the most important attributes NAME and VALUE now look in the symbol and footprint editors:



ubruhin added some commits Apr 19, 2018

Use Jinja-like syntax for attributes
- Old syntax: #KEY
- New syntax: {{KEY}}
Update submodule "demo-workspace"
Use Jinja-like syntax for attributes

@ubruhin ubruhin added this to the 0.1 milestone Apr 22, 2018

@ubruhin ubruhin self-assigned this Apr 22, 2018

@ubruhin ubruhin merged commit 70a745f into master Apr 28, 2018

4 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@ubruhin ubruhin deleted the attributes_jinja_syntax branch Apr 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment