A slot is a small promise that the page makes to content it has not seen yet.
Let indentation describe the document
I enjoy writing a document when its source makes the hierarchy obvious. A heading belongs inside a section; a paragraph follows it; attributes describe the node beside them. Repeated closing tags add visual work to that description. Indentation already tells me where the structure begins and ends.
<a href="https://livescript.net/">LiveScript</a> gives me concise function calls, destructuring, implicit object notation, and indentation-based blocks. My helpers use those features to build document nodes. The result has the feel I like in Pug or Jade, while remaining code that I can compose with my own functions.
I do not need to design another parser for the HTML authoring layer. The host language already supplies variables, loops, conditionals, and function boundaries. I choose a small vocabulary—elements, attributes, literals, fragments, slots—and let those pieces do useful work together.
{ create-document, attrs, literal } = dependency 'net.html.Document'
{ escape-text } = dependency 'net.html.Text'
doc = create-document!
{ article, h2, p } = doc
introduction = (post) ->
{ title, intro } = post
article do
attrs class: 'reading-introduction'
h2 literal escape-text title
p literal escape-text intro
The example constructs a node tree. The renderer emits the opening and closing tags, including the special treatment of void elements. The author sees the structure once. Destructuring also keeps the content names readable: title and intro are the local concepts, so I do not repeat the object's name on every line.
A literal is a deliberate boundary. In this implementation it writes the text it is given; it is not an automatic escaping layer. The example escapes external text before constructing the literal. Author-controlled prose can intentionally include markup. Keeping that distinction explicit is more useful than letting a convenient helper conceal it.
CSS uses the same compositional vocabulary
Styles benefit from the same treatment. A CSS rule is a selector and a declaration object. Shared declarations are ordinary objects. A component can combine them and supply the small differences that give it its own role. Property names are converted to CSS spelling when the stylesheet is emitted.
That creates a Stylus-like rhythm without making the stylesheet a hand-maintained output artifact. I write the source in LiveScript, combine declaration sets, and generate CSS. The browser receives normal stylesheets and normal custom properties. It does not need to know which authoring language produced them.
{ css, css-var } = dependency 'net.html.Css'
{ surface } = dependency 'net.design.astro.Rules'
note-styles = (doc) ->
doc.style do
css '.note', surface,
padding: css-var 'space-md'
color: css-var 'text-secondary'
css '.note:focus-within',
borderColor: css-var 'accent-primary'
Build-time slots make composition flexible
A component often produces more than the node that appears in the middle of the page. It may contribute a stylesheet, metadata, or a script. Passing all those contributions through every intermediate function would make the visible structure harder to follow.
The document object therefore has named slots. A component can append content to a slot while the page skeleton declares where that slot is rendered. The producer knows the slot's public name; the skeleton owns its position in the final document. The document renderer resolves that arrangement during the build.
This is a useful form of delayed composition. I can describe the page skeleton clearly, let its components register their contributions, and emit the completed document when the pieces are known. For static output I use render-fragment, so CGI response headers do not accidentally become visible text inside a saved HTML file.
{ create-document, attrs, slot } = dependency 'net.html.Document'
doc = create-document!
{ html, head, body, link } = doc
doc.append-in-slot 'styles', link ...attrs do
rel: 'stylesheet'
href: 'shared.css'
page = html do
head slot 'styles'
body slot 'content'
doc.render-fragment page
Runtime slots keep the agreement alive
A running page faces a related problem at a different moment. Its initial resources are already loaded, but an article arriving later might need a code theme or a shared icon library. I want the article to declare that requirement where it is authored, rather than requiring the landing page to predict every future dependency.
This resource-slot idea is not borrowed from the hypermedia projects discussed in the companion reader article. It is my contract for carrying resource requirements across a fragment boundary. The producer names a resource and its destination; the page provides that destination; the runtime resolves the declaration when the fragment arrives. Keeping this provenance explicit also keeps the implementation boundaries clear: iframe navigation moves a document, while slots carry shared resource declarations into the live page.
The runtime has named boundaries in the document. Incoming fragments carry declarations with a slot name, a resource key, and an insertion preference. The loader checks the key, finds the boundaries, constructs the resource node, and places it at the chosen edge. Append is the normal preference; prepend is available when the author needs an earlier position.
These are two separate operations with a shared idea. The document builder resolves slots while producing HTML. The browser inserts resources into declared slots while receiving HTML. The insertion preference is declared statically and executed when the fragment arrives.
dependencies:
- key: public-code-theme-v1
slot: styles
position: append
href: assets/code-theme.css
This is an illustrative article declaration; the named stylesheet would need to exist in the site's assets. Its key is a public identity chosen by the author. Once that key is present, another declaration with the same key can be omitted. The loader does not compare two files and decide whether their contents are equivalent.
That policy makes naming part of the contract. A compatible shared resource can retain its public key. A genuinely different resource needs a distinct identity. Reusing a key for incompatible behavior would ask the loader to resolve a conflict it was deliberately never designed to infer.
Let old articles remain old articles
A long-lived blog accumulates documents. I want a new article to be able to request a new utility without reopening every old article just to teach it that the utility exists. As long as public slot boundaries and resource identities remain compatible, existing fragments can keep their old declarations. The shell and the new fragment carry the new knowledge.
My present use is shared page-level resources. A slot could be named for a utility such as Font Awesome, or a general styles slot can contain a resource keyed for that library. I have not needed article-local slot lifecycles, automatic unloading, or a dependency version solver. The content is static HTML; scripts that need setup own their setup. Inserting a resource node is also distinct from waiting for every asynchronous resource to finish loading.
The attraction is the continuity of the model. Functions compose nodes. Declaration objects compose styles. Slots compose contributions whose producers and final positions are separated. LiveScript makes the authoring pleasant, while the emitted HTML and CSS remain easy to inspect. The syntax looks like a DSL because the underlying operations fit the shape of the work.
