-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs/howto: conditionally include list elements
This adds a guide that demonstrates how to include elements in a list conditionally. Closes cue-lang/docs-and-content#117 Preview-Path: /docs/howto/conditionally-include-list-elements/ Signed-off-by: Jonathan Matthews <[email protected]> Change-Id: I4eea7a9294a189f8a7c160eb16f06736f7afa74a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1197391 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
- Loading branch information
1 parent
8a12333
commit b5df5d4
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
content/docs/howto/conditionally-include-list-elements/en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Conditionally including elements in a list | ||
authors: [jpluscplusm] | ||
toc_hide: true | ||
tags: [commented cue] | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to include elements in a list based on some testable condition. | ||
|
||
{{{with code "en" "cc"}}} | ||
exec cue export | ||
cmp stdout out | ||
-- example.cue -- | ||
package example | ||
|
||
#a: "yes" | ||
|
||
A: [ | ||
1, | ||
2, | ||
|
||
// Include a single element using this form: | ||
if #a == "yes" { | ||
3 | ||
}, | ||
|
||
// Include multiple elements using this form, | ||
// which only tests the condition once: | ||
if #a == "yes" for e in [ | ||
4, | ||
5, | ||
6, | ||
] {e}, | ||
] | ||
-- out -- | ||
{ | ||
"A": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6 | ||
] | ||
} | ||
{{{end}}} |
18 changes: 18 additions & 0 deletions
18
content/docs/howto/conditionally-include-list-elements/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"conditionally-include-list-elements": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "7HIdQ5DAaafYiGotXzpD2y8Dvs1Xs3PlUfim+NB9dW4=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
content/docs/howto/conditionally-include-list-elements/page.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "conditionally-include-list-elements": page: _ |
48 changes: 48 additions & 0 deletions
48
hugo/content/en/docs/howto/conditionally-include-list-elements/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: Conditionally including elements in a list | ||
authors: [jpluscplusm] | ||
toc_hide: true | ||
tags: [commented cue] | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to include elements in a list based on some testable condition. | ||
|
||
{{< code-tabs >}} | ||
{{< code-tab name="example.cue" language="cue" area="top-left" >}} | ||
package example | ||
|
||
#a: "yes" | ||
|
||
A: [ | ||
1, | ||
2, | ||
|
||
// Include a single element using this form: | ||
if #a == "yes" { | ||
3 | ||
}, | ||
|
||
// Include multiple elements using this form, | ||
// which only tests the condition once: | ||
if #a == "yes" for e in [ | ||
4, | ||
5, | ||
6, | ||
] {e}, | ||
] | ||
{{< /code-tab >}} | ||
{{< code-tab name="TERMINAL" language="" area="top-right" type="terminal" codetocopy="Y3VlIGV4cG9ydA==" >}} | ||
$ cue export | ||
{ | ||
"A": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6 | ||
] | ||
} | ||
{{< /code-tab >}} | ||
{{< /code-tabs >}} |