Demo of the awesome power of macros in a Clojurescript.
Boring ways to serve static content:
Use a static site generator to make HTML pages on the backend or on a local device for upload.
Make a react-style front-end SPA thingey, and have it use an AJAX call to get data from JSON or something and render client-side.
Ridiculous way to serve static content:
- Make a react-style font-end SPA thingey and just write the static content straight into the code, rather than have to use an AJAX call. (I've actually done this...)
AWESOME way to serve static content:
- Take #3, but instead of writing the static content into the code, use a macro to fetch the static content from a much more readable and rational format, and then pass it to the front-end code. Because you have a lisp! And lisps can do that stuff!
A second cool thingey
This repo now demonstrates how to achieve client-side templating in SPA using the same technique. Using the selmer and hickory libraries in a macro, we take a template and a json, apply the template to generate a html string, then parse that html string to get a hiccup representation, which can then be sent to the clojurescript side in the compilation stage. Voila, pure front-end templating with no AJAX calls.
(Strange behavior: for some reason selmer's read-file function can't find the template html file on the classpath, but slurp can.)