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

lazy/triple globs docs #184

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ _bespoke() {
sh_c d2 ./static/bespoke-d2/wcc.d2 ./static/img/generated/wcc.pptx

sh_c d2 ./static/bespoke-d2/imports-nested.d2 ./static/img/generated/imports-nested.pdf

sh_c d2 ./static/bespoke-d2/triple-glob.d2 ./static/img/generated/triple-glob.pdf
}

main() {
Expand Down
60 changes: 52 additions & 8 deletions docs/tour/globs.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Globs

:::caution Alpha
Globs are an alpha feature in 0.6.0. It is likely to change in behavior in followup minor
releases. In particular, the current plan is for globs to be lazy evaluated, so that it
can be used to set defaults, as opposed to the current implementation where it is
evaluated as it appears.
:::

:::note Etymology
> The glob command, short for global, originates in the earliest versions of Bell Labs' Unix... to expand wildcard characters in unquoted arguments ...

Expand All @@ -29,6 +22,26 @@ iphone 12 mini

<div style={{width: 600}} className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/globs-intro.svg2')}}></div>

## Globs apply backwards and forwards

In the following example, the instructions are as follows:
1. Create a shape `a`.
2. Apply a glob rule. This immediately applies to existing shapes, i.e., `a`.
3. Create a shape `b`. Existing glob rules are re-evaluated, and applied if they meet the
criteria. This does, so it applies to `b`.
4. Same with `c`.

```d2
a

* -> y

b
c
```

<div style={{width: 600}} className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/globs-lazy.svg2')}}></div>

## Globs are case insensitive

```d2
Expand Down Expand Up @@ -194,7 +207,7 @@ catapult: {
<div style={{width: 600}} className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/globs-filter-2.svg2')}}></div>

:::info
We are working on adding more filters.
We are working on adding more filters, as well as the "not-filter", `!&`.
:::

## Nested globs
Expand Down Expand Up @@ -225,3 +238,34 @@ conversation 2: {
```

<div style={{width: 600}} className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/globs-nested.svg2')}}></div>

## Global globs

Triple globs apply globally to the whole diagram. The difference between a double glob and
a triple glob is that a triple glob will apply to nested `layers` (see the section on
[composition](/tour/composition) for more on `layers`), as well as persist across imports.

```d2
***.style.fill: yellow
**.shape: circle
*.style.multiple: true

x: {
y
}

layers: {
next: {
a
}
}
```

<embed src={require('@site/static/img/generated/triple-glob.pdf').default} width="100%" height="800"
type="application/pdf" />

:::info Imports
If you import a file, the globs declared inside it are usually not carried over. Triple
globs are the exception -- since they are global, importing a file with triple glob will
carry that glob as well.
:::
13 changes: 13 additions & 0 deletions static/bespoke-d2/triple-glob.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
***.style.fill: yellow
**.shape: circle
*.style.multiple: true

x: {
y
}

layers: {
next: {
a
}
}
6 changes: 6 additions & 0 deletions static/d2/globs-lazy.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a

* -> y

b
c
Binary file modified static/img/generated/cat.pdf
Binary file not shown.
Binary file modified static/img/generated/cult.pptx
Binary file not shown.
170 changes: 170 additions & 0 deletions static/img/generated/globs-lazy.svg2

Large diffs are not rendered by default.

Binary file modified static/img/generated/imports-nested.pdf
Binary file not shown.
Binary file modified static/img/generated/lotr.pdf
Binary file not shown.
Binary file modified static/img/generated/tiktok.pdf
Binary file not shown.
Binary file added static/img/generated/triple-glob.pdf
Binary file not shown.
304 changes: 152 additions & 152 deletions static/img/generated/vars-config.svg2

Large diffs are not rendered by default.

Binary file modified static/img/generated/wcc.pptx
Binary file not shown.
Loading