MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / main

Function main

assets/generate-language-tiles.py:208–264  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206
207
208def main():
209 preview_path = None
210 if "--preview" in sys.argv:
211 preview_path = sys.argv[sys.argv.index("--preview") + 1]
212
213 out = Outliner()
214 label_baseline = round(GLYPH_TOP + GLYPH_BOX + LABEL_GAP + out.cap_height(LABEL_SIZE, LABEL_WT), 2)
215
216 out_dir = os.path.join(os.path.dirname(__file__), "languages")
217 os.makedirs(out_dir, exist_ok=True)
218
219 bodies = {}
220 for slug, label, source in LANGS:
221 if source[0] == "si":
222 glyph = si_glyph(source[1])
223 elif source[0] == "devicon":
224 glyph = devicon_glyph(source[1], source[2])
225 else:
226 glyph = custom_glyph(source[1], out)
227 label_d = out.centered(label, LABEL_SIZE, LABEL_WT, TILE / 2, label_baseline)
228 body = (
229 f'<rect x="0.5" y="0.5" width="{TILE - 1}" height="{TILE - 1}" rx="8" fill="{PAPER}" stroke="{HAIRLINE}"/>\n'
230 f" {glyph}\n"
231 f' <path fill="{INK}" d="{label_d}"/>'
232 )
233 bodies[slug] = body
234 svg = (
235 f'<svg xmlns="http://www.w3.org/2000/svg" width="{TILE}" height="{TILE}" '
236 f'viewBox="0 0 {TILE} {TILE}" role="img" aria-label="{label}">\n'
237 f" <title>{label}</title>\n"
238 f" {body}\n"
239 f"</svg>\n"
240 )
241 path = os.path.join(out_dir, f"{slug}.svg")
242 with open(path, "w") as fh:
243 fh.write(svg)
244 print(f"wrote {os.path.relpath(path, os.path.dirname(__file__))} ({len(svg)}b) {label}")
245
246 if preview_path:
247 cols, pad = 7, 8
248 rows = -(-len(LANGS) // cols)
249 w = cols * (TILE + pad) + pad
250 h = rows * (TILE + pad) + pad
251 cells = []
252 for i, (slug, _, _) in enumerate(LANGS):
253 tx = pad + (i % cols) * (TILE + pad)
254 ty = pad + (i // cols) * (TILE + pad)
255 cells.append(f'<g transform="translate({tx},{ty})">{bodies[slug]}</g>')
256 light = "".join(cells)
257 with open(preview_path, "w") as fh:
258 fh.write(
259 f'<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="{h * 2}" viewBox="0 0 {w} {h * 2}">'
260 f'<rect width="{w}" height="{h}" fill="#ffffff"/>{light}'
261 f'<g transform="translate(0,{h})"><rect width="{w}" height="{h}" fill="#0d1117"/>{light}</g>'
262 f"</svg>\n"
263 )
264 print(f"wrote preview {preview_path} (top: light bg, bottom: dark bg)")
265

Callers 1

Calls 8

cap_heightMethod · 0.95
centeredMethod · 0.95
OutlinerClass · 0.85
si_glyphFunction · 0.85
devicon_glyphFunction · 0.85
custom_glyphFunction · 0.85
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected