Unrolled code
The wire report delves into the concept of "unrolled code" as demonstrated by the grubby project, a minimal static site generator for git repositories written in Ruby. Grubby generates an HTML page for each file in the repository by running `git ls-tree`, collecting filenames, and then using a primitive templating system with functions like `#fill_template`, `#render_markdown`, and `#write_page` to compose the inner HTML with header and footer files.
The author draws a comparison between grubby's code and that of ERB and Papercraft, which compile templates into optimized Ruby code that emits snippets of HTML into a buffer. Despite the low-level nature of grubby's code, it remains readable, similar to the code generated by ERB and Papercraft. The author also highlights a less readable but faster alternative to this unrolled code approach.
The report further explores Herb, a gem with a set of tools for working with ERB templates. Herb's `initialize` method is lengthy (65 LOC) and its individual lines tend to stretch to the edge of the editor window. Despite the complexity, the code is explicit and straightforward, revealing its logic in a clear manner.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.