Skip to content
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

[FEATURE] -improve template context #209

Open
oknozor opened this issue Nov 29, 2022 · 0 comments
Open

[FEATURE] -improve template context #209

oknozor opened this issue Nov 29, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@oknozor
Copy link
Owner

oknozor commented Nov 29, 2022

Is your feature request related to a problem? Please describe.
While the current template system works it feels a bit messy.

The template context is updated using a Hashmap<String, String> , merging values from sub profiles in the global context.

Current templating system

We have a global variable file enabled in bombadil.toml

# File: dotfiles/bombadil.toml
[settings]
vars = [ "vars/vars.toml"  ]

Containing the following variables:

# File: dotfiles/vars/vars.toml
wallpaper = "$HOME/dotfiles/wallpapers/sea.jpg"
terminal = "alacritty"

We can overwrite wallpaper using an additional profile

# File: dotfiles/vars/themes/home.toml
wallpaper = "~/dotfiles/assets/wallpapers/night_sky_34i.jpg"

This works fine as long as we don't shallow a variable twice.
Currently it's hard to predict the final value of a variable when shallowing it multiple time in different profiles.

Describe the solution you'd like
tera allow to pass serde_json::Value in its context.
This would allow to write variable using all the toml semantic in a more structured way.

Example

# dotfiles/vars.toml
[colors]
blue = "#blue"
red = "#red"

[secrets]
passphrase = "some gpg encrypted value" 

[desktop.sway]
bar = "ironbar"
login_manager = "gtk-greet"

# or toml objects
desktop = [
  { i3 = { bar = "polybar", login_manager = "gdm"  } }
]

# ...etc

The following approach as several advantages :

  • enable to write structured variables context for dotfiles template and eliminate some off the mental load currently required to remember which variables file is loaded were etc.
  • Enable better templating experience
    .class {
        {%- if profiles is containing("fancy") -%}
        color: {{red}}
        {%- else -%}
        color: {{black}}
        {%- endif -%}
     }
    
  • We could provide some default context like os, profiles, locale etc.
@oknozor oknozor added the enhancement New feature or request label Nov 29, 2022
@oknozor oknozor self-assigned this Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant