Shemnei / punktf

⚡ A cross-platform multi-target dotfiles manager

Home Page:https://shemnei.github.io/punktf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] - Rework templating syntax

michidk opened this issue · comments

The templating syntax is quite nice and really safe (meaning there is no way it would conflict with escaping some other language). However, it is also quite tedious to write and read. Here is my proposal to change the syntax:

Current Syntax

IF Example:

{{@if {{WSL}} == "yes"}}
alias explorer='explorer.exe'
{{@fi}}

I know that the current syntax is heavily inspired by handlebars, though I don't quite remember why we introduced the @ sign, which seems a bit unnecessary to me.

Proposed Syntax

I think we can borrow again from a well-established templating system (that itself is inspired by Jinja and Django): https://github.com/Keats/tera

{% if WSL == "yes" %}
alias explorer='explorer.exe'
{% endif %}

More examples: https://tera.netlify.app/docs/#control-structures

We could also consider using Tera for this. This would remove a lot of documentation and maintenance work from the project and give us lot's more features like for loops etc.

Current Syntax

I also do not remember why we chose @ but i guess it was to make parsing it somewhat easier.

Proposed Syntax

I wanted to get ride of your custom templating for some time now, as it is not the most robust and feature rich implementation.

I thought about adding support for multiple templating languages, which then could be chosen during runtime by:

  • Setting the template variable on the dotfile entry in the profile (e.g. template: terra)
  • Setting the correct file extension on the template file (e.g. test.txt => test.txt.terra). This extension would then get removed during the deployment.

The only problem with that is, that we need to find a way to let those template engines access the system environment (maybe some of them have already build in functions for that).

I would not overengineer it, I think supporting only terra (for now) is fine.