terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
17.17k stars 425 forks source link

[variables substitution] Allow substitution inside map keys #2181

Open Melandel opened 2 weeks ago

Melandel commented 2 weeks ago

Hello 🌱

At the time of writing this issue

Given this d2 description text:

vars: {
  x: "Data"
}

cls: "SomeClass" {
  shape: class
}
cls."Process(Input input)": ${x}Output
cls."Process(${x}Input input)": ${x}Output

This link shows that variable substitution inside a key of the map cls is not effective: image

Feature Request

I would like the same source code to generate this image instead (substituing the variable x containing the value Data: image

Would this be a fair request to make?

alixander commented 4 days ago

I think is specific to class shapes, because all other keys can have label affect their final render text.

If we allow substitutions in map keys, it becomes too confusing to reference (e.g. point a connection to it).

I'm not sure what to do here other than introduce a new keyword specific to class shape, which is last resort. Will put this on backburner until I can think of something better or someone else runs into it.