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

Can you use hashes in templates? #184

Open
quintrino opened this issue Sep 6, 2024 · 1 comment
Open

Can you use hashes in templates? #184

quintrino opened this issue Sep 6, 2024 · 1 comment
Labels

Comments

@quintrino
Copy link

Environment

  • Mac OSX
  • dotter 0.13.2

The question

I currently use freshrc and am converting to dotter.

Probably a simple question, but I haven't had much luck finding an answer. Is there a way to have a hash/dictionary in a template?

I currently have this file which has aliases stored as a hash in ruby erb, which then generates one version for zsh (which uses aliases) and one version for fish (which uses abbr)

I'm wondering if there's a way in a template to do something similar to this pseudo-code.

aliases = {
    git: {
        g: 'git',
        gs: 'git status'
    },
    navigation: {
        bp: 'bat --plain',
        rmf: 'rm -rf',
        md: 'mkdir -p'
    }
}

for set in aliases {
    for alias, command in set {
        if (abbr_language == true) 
            "abbr {alias} {command}"
        else
            "alias {alias} {command}"
        \if
    }
}
@SuperCuber
Copy link
Owner

Should be possible. To do nested tables like that in TOML, you should do something like

[mypackage.variables.aliases.git]
g = "git"
gs = "git status"
[mypackage.variables.aliases.navigation]
bp = "bat --plain`
...

Although I'm not sure why you're breaking it into sets in the first place - you could probably just have all under aliases

In the rc file, according to this handlebars documentation: https://handlebarsjs.com/guide/builtin-helpers.html#each
You could use something like

{{#each aliases}}
abbr {{@key}} {{this}}
{{/each}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants