Commit e75ff5c
Add per-connector / per-cable tweak with name placeholder (port of upstream PR wireviz#357)
Connectors and cables can now carry their own ``tweak:`` block with the
same ``override`` / ``append`` shape as the global one. The harness
folds per-node tweaks into the global tweak at instantiation, with an
optional placeholder substring rewritten to the node's actual
designator — making it practical to author a single tweak template and
apply it to many components.
Example:
tweak:
placeholder: "@@"
connectors:
X1:
pinlabels: [A, B]
tweak:
append:
- "@@_extra [color=red, style=dashed];"
renders X1's per-node tweak as ``X1_extra [color=red, style=dashed];``
in the .gv source. The same connector definition reused for X2 would
produce ``X2_extra ...``.
Placeholder semantics:
* Per-node ``tweak.placeholder`` overrides the global ``tweak.placeholder``.
* An empty string at the per-node level explicitly opts out of
substitution for that node.
* ``None`` (the default) falls back to the global placeholder.
* When neither is set, no substitution happens — bare strings are
appended/overridden as-written.
Implementation:
* DataClasses.py — ``Tweak`` gains ``placeholder: Optional[str] = None``.
``Connector`` and ``Cable`` gain ``tweak: Optional[Tweak] = None``,
with ``__post_init__`` coercing a dict literal into a Tweak instance.
* Harness.py — new ``Harness._extend_tweak(node)`` method, called from
``add_connector()`` and ``add_cable()``, performs the placeholder
substitution and merges into ``self.tweak``. Raises ``ValueError`` if
two nodes contribute conflicting overrides for the same key.
* docs/syntax.md — documents per-connector / per-cable tweak fields and
the new placeholder semantics.
Adapted from wireviz#357 (originally by
@kvid, targeting upstream ``dev``). Renamed ``extend_tweak`` to
``_extend_tweak`` to mark it private; otherwise faithful to the
original logic. ``make_list`` is already in master's wv_bom so no
helper backport needed.
Verified:
* Smoke test with placeholder ``@@`` and per-connector + per-cable
``append:`` blocks produces ``X1_extra``, ``W1_label``,
``cable W1`` in the rendered .gv (the @@'s are substituted).
* build_examples.py: deterministic outputs (.gv, .bom.tsv) byte-
identical to baseline (no existing example uses the new syntax, so
no new substitutions fire).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3d925b2 commit e75ff5c
3 files changed
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
| 154 | + | |
| 155 | + | |
151 | 156 | | |
152 | 157 | | |
153 | 158 | | |
| |||
457 | 462 | | |
458 | 463 | | |
459 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
460 | 471 | | |
461 | 472 | | |
462 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| 179 | + | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
| |||
335 | 339 | | |
336 | 340 | | |
337 | 341 | | |
| 342 | + | |
338 | 343 | | |
339 | 344 | | |
340 | 345 | | |
341 | 346 | | |
| 347 | + | |
| 348 | + | |
342 | 349 | | |
343 | 350 | | |
344 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
90 | 131 | | |
91 | 132 | | |
92 | 133 | | |
| |||
0 commit comments