Coding 2024-09-28

By Max Woerner Chase

As I hinted in the summary yesterday, I ended up thinking about how to write component-y code with Protocols instead of ABCs. Let's see what I've got...

The default assumption for how to render the content of the main tag is "something involving Jinja", so the protocol needs to feature a method that takes an Environment and returns str | None. It also needs properties that produce str (tag name), Mapping[str, str] (attribute values), and a Modifiable instance (the super class of both Block and Element; I am making compromises with the design because "roll a compatible version of Enum that avoids using inheritance is Not Worth It).

My thinking is that I should make all of the processing for this into something that is available as a filter. That way the templates for a block can just use the filter to render the elements. Perhaps it would make sense for the value from the method to be Template | None? I'm going back and forth on this right now. The ultimate entry point for all of this is a filter call in the top-level template, and I'd like to be able to have that template enforce the tag used for the return from that filter. So, the filter looks something like def component(environment, value, require_tag=None): Or maybe this is written as a macro in a template. Possibly the requiring tag stuff is a filter and everything else is a macro. That feels like something that works acceptably...

I'm not up for thinking too much more about this right now, so I'll let it go for the moment and take things easy.

Good night.