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

Fallback value #2

Closed
97-109-107 opened this issue Apr 17, 2016 · 5 comments
Closed

Fallback value #2

97-109-107 opened this issue Apr 17, 2016 · 5 comments

Comments

@97-109-107
Copy link

Is there a way to have something like

special:    "{{ color15 | color4 }}"

which would mean the the var special would be assigned the value of color15 if it's defind, if not, it would grab the value of color4?

My question stems from the not knowing what where to find documentation on how defaults.yaml is parsed. Is that just pystache? Any pointers?

btw. Thanks for sharing your work!

@fullsalvo
Copy link
Contributor

Pystache/Mustache doesn't offer the described syntax (it tries to use as little programming logic as possible) but any variable not defined in a variable set falls back to whatever is in defaults.yaml for that variable. Given your example, I think the easiest approach would be to create a third variable defined as color4 in defaults and color15 the specific set.

Recently I've been working to expand the documentation on the behaviors of whizkers, so hopefully the way it works will become more clear in the future.

The README in example is useful to explain some convenient uses of mustache to make variable assignment somewhat simpler.

@97-109-107
Copy link
Author

Thanks for the prompt reply. Indeed the readme in the example folder helped me a long way before I stumbled into this.

I'm not sure if I can exactly put your suggestion into action in my setup.

Let say that the variable sets have either 8 or 16 colors defined. I would like to switch between them without needing to know if the set has 8 or 16. If it has 8, then the second half of color variables in Xcolors need to be a duplicate of the first 8 - this is where the I thought the fallback would come in handy. My situation is the exact opposite - I have color4 defined in the set and a missing color15.

Thanks

@fullsalvo
Copy link
Contributor

Assuming you have your colors set up as they are outlined in the example folder readme, the easiest strategy I foresee to accomplish that specific goal is to make a variable set resembling the following:

b_black:         "{` {{ colors }}['black']['normal'] `}"
b_red:           "{` {{ colors }}['red']['normal'] `}"
b_green:         "{` {{ colors }}['green']['normal'] `}"
b_yellow:        "{` {{ colors }}['yellow']['normal'] `}"
b_blue:          "{` {{ colors }}['blue']['normal'] `}"
b_magenta:       "{` {{ colors }}['magenta']['normal'] `}"
b_cyan:          "{` {{ colors }}['cyan']['normal'] `}"
b_white:         "{` {{ colors }}['white']['normal'] `}"

While I know this isn't as favourable as having a "true" fallback, as of right now, this is probably the best way to approach what you've described. I hope this helps.

@metakirby5
Copy link
Owner

metakirby5 commented Apr 18, 2016

@fullsalvo is correct, and there are no plans to support anything outside of standard Mustache and YAML syntax, outside of two exceptions: Mustache directives within YAML strings and the special {``...``} eval directive. However, I have a solution that may work for your use case:

black:           "{` {{ colors }}['black'].get('bold') or {{ colors }}['black']['normal'] `}"

black should take on the value of your bold black color when it is defined, and the normal black color when it is not. It makes the assumption that your colors are stored as in the example. Let me know if this works for you.

@97-109-107
Copy link
Author

That's exaclty the syntax I was looking for, but couldn't figure it out. Thanks for you help.

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