posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.9k stars 71 forks source link

refactor: improve internals of using google_font() helper #457

Open rich-iannone opened 2 months ago

rich-iannone commented 2 months ago

Copied from https://github.com/posit-dev/great-tables/pull/423#discussion_r1765357257

For pairing Thursday, let's go over alternative paths this could go through. Currently, CellStyle as an interface has a _to_html_style() method, that gets used on render.

Here, it looks like the new behavior to support is this:

Currently, the path used for this is:

However, this means that if you use tab_style multiple times with google font, etc.., the additional css gets appended multiple times. Moreover, if the person modifies additional_css, they can remove the necessary import.

A second issue is that this exact code is pasted into the opt_table_font() method. We likely don't want to put custom handling for specific CellStyle types (with specific attributes) into these methods.

Repeating code twice isn't necessarily an issue though, so it could be that we map out paths for these kinds of activities, merge, and punt the work to a new issue