|
spudplate
Template scaffolding compiler for spudlang .spud files
|
Creates a file at <path>, or appends to one already created in the same run. The two forms differ in where the content comes from: a file already in the bundle (from) or an inline expression (content).
| Clause | Effect |
|---|---|
append | Append to the file rather than overwriting; the file must already have been created in this run |
from | Read the source file from the bundle. {ident} substitution applies unless verbatim |
content | Use the value of an inline expression. Full {expr} interpolation applies |
verbatim | With from, suppress all substitution |
mode | Set file permissions, masked to 0o0777 |
when | Skip creation if the condition is false |
as | Bind the resolved path; useful for conditional append |
Writes a file with content from an inline expression. The expression is evaluated to a string at run time. {expr} interpolation works inside string literals as described in Types and expressions.
content requires a string value. Mixing a non-string into a + expression is rejected by the validator: convert through interpolation first.
Reads a file from the bundle and writes it to <path>. {ident} substitution is applied to file contents at run time (only bare identifiers, not full expressions).
To copy bytes verbatim (no substitution at all), add verbatim:
The interpreter auto-detects binary content: a source file whose bytes are not valid UTF-8 is treated as verbatim regardless of the keyword, so binary assets such as PNGs or favicons just work.
append adds to a file rather than overwriting. The file must have been created earlier in the same run; appending to a file that does not yet exist is a runtime error.
Common idiom: build up a sectioned README from optional pieces.
The as readme alias makes the conditional appends terse and avoids repeating the path expression.
as <name> on a file binds the resolved file path. The most common reason to use it is conditional append. The conditional-alias rule applies: if the binding file carries a when, every reference must be guarded by an equivalent condition.
mode takes an octal literal. The value is masked to 0o0777.
A file with no mode clause inherits the system default for newly created files.
| If you want to... | Use |
|---|---|
| Insert a complete file from the bundle | file ... from |
| Generate a small file from a string expression | file ... content |
| Embed runtime values into the body of a templated file | file ... from (uses {ident}) |
| Use full expression evaluation inside the file body | file ... content (uses {expr}) |
For mostly-static text with a few placeholders, from is the cleaner choice. For dynamically composed content, content is.
<path> and <source>.content vs from.