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

Support "!=" in built-in template processor #358

Closed
xenoterracide opened this issue Jul 17, 2021 · 5 comments
Closed

Support "!=" in built-in template processor #358

xenoterracide opened this issue Jul 17, 2021 · 5 comments

Comments

@xenoterracide
Copy link

xenoterracide commented Jul 17, 2021

maybe a bug, maybe a PEBCAK (I apologize if it is), I have this code, but for some reason the output of yadm alt doesn't include the contents of the developer.sh

{% if yadm.user != "root" %}
  {% include "../extra/developer.sh" %}
{% endif %}

https://github.com/xenoterracide/dotfiles/blob/2002b498c5bfad7c93b959dcbbf7e75fdb69d4a2/.config/yadm/alt/.zshrc%23%23template%2Ce.zsh#L34

@erijo
Copy link
Collaborator

erijo commented Jul 17, 2021

Does it work if you instead use == and put the include in an else clause?

@xenoterracide
Copy link
Author

yes and no, this doesn't, it treats the include as just text, but if I remove the indentation it works. changing that may be another ticket... though the way I'd like it to behave is include that code prepended with that indentation. I don't think I should need the else for this though.

{% if yadm.user == "root" %}
{% else %}
  {% include "../extra/developer.zsh" %}
{% endif %}

@erijo
Copy link
Collaborator

erijo commented Jul 18, 2021

Yes, {% must be first on the line and only == is supported. For more advanced templates you could perhaps use ninja instead?

@xenoterracide
Copy link
Author

maybe, but only having == is unintuitive. If that's all that can be supported perhaps it's possible to throw an error? I honestly haven't considered my config to be particularly complicated, honestly this is the only conditional I have.

@TheLocehiliosan TheLocehiliosan changed the title include inside of if block not evaluated Support "!=" in built-in template processor Nov 29, 2021
@github-actions
Copy link

This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jan 29, 2022
erijo added a commit to erijo/yadm that referenced this issue Oct 27, 2024
The awk script now performs all processing in the BEGIN block using an
implementation that is capable of handling nested if statements. This fixes
issue yadm-dev#436. Includes are now handled in the same way as the main file which
means that recursive includes and if statements in includes works as
expected. This fixes yadm-dev#406.

All variables are handled in the same way now so it's now possible to use env
variables in if statements. This fixes yadm-dev#488.

Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now
e.g. possible to check if a variable is set (yadm-dev#477) by doing:

{% if yadm.class != ""%}
Class is set to {{ yadm.class }}
{% endif %}

Possible breaking change: An error will be issued if a non-existent yadm or env
variable is referenced in an if statement or in a variable substitution.
erijo added a commit to erijo/yadm that referenced this issue Oct 27, 2024
The awk script now performs all processing in the BEGIN block using an
implementation that is capable of handling if statements which contain nested
if statments (fixes yadm-dev#436). To make nested ifs look better, if, else and endif
lines can now have optional whitespace before {%.

Includes are now handled in the same way as the main file which means that
included files can both include other files and have if statements in addition
to variables (fixes yadm-dev#406). Include lines can now also have optional whitespace
before {%.

All variables are handled in the same way now so it's now possible to use env
variables in if statements (fixes yadm-dev#488).

Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now
e.g. possible to check if a variable is set (yadm-dev#477) by doing:

{% if yadm.class != ""%}
Class is set to {{ yadm.class }}
{% endif %}

Possible breaking change: An error will be issued if a non-existent yadm or env
variable is referenced in an if statement or in a variable substitution.
erijo added a commit that referenced this issue Nov 6, 2024
* Support nested ifs in default template (#436)
* Support include and ifs in default template includes (#406)
* Support environment variables in ifs in default template (#488)
* Support != in default template (#358, #477)
erijo added a commit that referenced this issue Nov 8, 2024
 * Support nested ifs in default template (#436)
 * Support include and ifs in default template includes (#406)
 * Support environment variables in ifs in default template (#488)
 * Support != in default template (#358, #477)
 * Fix multiple classes in default template on macOS (#437)
@erijo erijo closed this as completed in 8ba9823 Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants