Skip to content

Conversation

@machshev
Copy link
Collaborator

We want to be able to generate reports that contain the same data but switch the CSS theme depending on the website they are embedded within.

Approach

HTMX is a nice way of doing this without having to write an maintain JS. It allows declarative HTML to make requests to a server replace the contents of an element with the returned content.

Typically to implement something like this, we would have some JS make a request to a backend server which returns some data and then serialise the data and render it client side. With the HTMX approach, events can be defined to trigger a request to a server which returns pre-rendered HTML which is substituted in place. This is an interesting approach as it keeps the state server side, avoiding issues related to synchronising state. In practice this approach can be faster as well, given that server side the operations required to calculate the data are often more resource hungry than the rendering... an there isn't necessarily that much difference between the effort to render HTML fragments verses JSON.

In our case there will be no back-end rendering as we are just presenting static HTML. So the main use of HTMX is it's ability to fetch HTML fragments and insert it into the DOM.

Implementation

The intention is to create an HTMX wrapper page that is the actual index.html and then use it to embed the content of the individual report pages. The CSS can go in the wrapper, which means other wrappers can embed the same report with a different CSS script.

This higher level wrapper can be used to generate all the reports with
one function. The benefit of this is that the CLI no longer needs to know
what lower level functions are required to generate the whole set of
reports. Making it easier to ensure that the admin command report
generation doesn't diverge from the in flow report generation.

Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
Reduce the block report to an HTML fragment that is loaded with the
wrapper using AJAX requests. Update the summary report links to use a
bootstrap button class (which is nicer than the blue URLs anyway?), and
use HTMX to replace the `#report-content` div with the block report.

The `hx-push-url="true"` is important to make sure the back button on
the browser works as expected.

Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
@machshev machshev marked this pull request as ready for review December 16, 2025 16:35
@machshev
Copy link
Collaborator Author

Minimal visual difference:
image

The only known visual difference is the URL links being replaced with bootstrap buttons. Providing a nicer presentation by default and still giving feedback on mouse over.

Script to download the js and css dependencies that the HTML reports
depend on. This means that the reports can be viewed offline and removes
unnecessary dependency on CDN.

Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
Add a static file renderer to go alongside the jinja2 renderer for the
static dependencies that do no need templating. This essentially creates
a copy of the files in the output directory.

Now we have the css/js dependencies locally generated we can update the
report template to use them.

Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
Copy link

@martin-velay martin-velay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
@machshev machshev added this pull request to the merge queue Dec 19, 2025
Merged via the queue into lowRISC:master with commit d6fc380 Dec 19, 2025
6 checks passed
@machshev machshev deleted the htmx_wrapper branch December 19, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants