Skip to content

Instantly share code, notes, and snippets.

@seven-phases-max
Last active August 29, 2015 13:56
Show Gist options
  • Save seven-phases-max/9172905 to your computer and use it in GitHub Desktop.
Save seven-phases-max/9172905 to your computer and use it in GitHub Desktop.
#usage {
.set(result-1, 1 lt 2, "true", "false");
.set(result-2, 3 eq 3, "true-only");
.set(result-3, 4 ne 4, "hidden");
.set(result-4, iscolor(blue), "true", "false");
.set(result-5, iscolor(55), "true", "false");
.set(result-6, isnumber(red), "hidden");
.set(result-7, isnumber(77), "true-only");
// etc.
}
// ............................................................
// implementation:
.set(@property, @condition, @true-value, @false-value: none) {
.-cond(@condition);
.true() {@{property}: @true-value}
.false() {@{property}: @false-value}
}
.-cond(true) {.true}
.-cond(@a, eq, @b) when (@a = @b) {.true}
.-cond(@a, gt, @b) when (@a > @b) {.true}
.-cond(@a, ge, @b) when (@a >= @b) {.true}
.-cond(@a, lt, @b) when (@a < @b) {.true}
.-cond(@a, le, @b) when (@a <= @b) {.true}
.-cond(@a, ne, @b) when not(@a = @b) {.true}
.-cond(...) when (default())
and not(@false-value = none) {.false}
.-cond(@condition) when (length(@condition) = 3) {
.-cond(
extract(@condition, 1),
extract(@condition, 2),
extract(@condition, 3)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment