2023-11-15 06:47:20 -08:00
|
|
|
# @thefarce/loom
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
## What is this?
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
Loom is a tool for weaving form data with content data in nodejs. It does
|
|
|
|
this by using elements of the Unified.js toolkit for parsing text into
|
|
|
|
abstract syntax trees (AST).
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
The fundamental idea of Loom is that presentation and content are orthogonal
|
|
|
|
dimensions of data. A communication has values in these two dimensions
|
|
|
|
integrated into a coherent whole.
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
## When should I use this?
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
When you want to blend form (such as HTML) with content (such as JSON) into
|
|
|
|
a single document. Unlike other systems, Loom does not require writing to
|
|
|
|
or reading from files.
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
## Installation
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
`$` `npm install @thefarce/loom`
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
## Usage Example
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
For more thorough usage examples, see the `examples` directory and refer to
|
|
|
|
the [documentation](./docs/usage.md).
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
```js
|
|
|
|
import {
|
2023-11-29 08:20:51 -08:00
|
|
|
interpolateTree,
|
|
|
|
transform,
|
2023-11-15 06:47:20 -08:00
|
|
|
} from '@thefarce/loom'
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
const initial = htmlToAst('<p>Hello, {name}!</p>'),
|
|
|
|
|
2023-11-29 08:20:51 -08:00
|
|
|
const transformed = interpolateTree(
|
2023-11-16 11:37:55 -08:00
|
|
|
transform(initial, ...transformers),
|
|
|
|
{ name: 'Othello' },
|
2023-11-15 06:47:20 -08:00
|
|
|
);
|
2023-11-16 11:37:55 -08:00
|
|
|
|
|
|
|
console.log(astToHtml(transformed));
|
2023-03-31 07:03:45 -07:00
|
|
|
```
|
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
Running this script produces the following output:
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
```html
|
|
|
|
<p>Hello, Othello!</p>
|
2023-03-31 07:03:45 -07:00
|
|
|
```
|
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
## API
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
### interpolate(ast, data)
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
### transform(ast, plugins)
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
See the [transformations documentation](./docs/transformations.md) for more
|
|
|
|
information.
|
2023-11-15 11:52:05 -08:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
Transform the AST according to plugins.
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 11:52:05 -08:00
|
|
|
## Glossary
|
|
|
|
|
|
|
|
### ast
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
The AST to be transformed. This can be any AST that conforms to the
|
2023-11-29 08:20:51 -08:00
|
|
|
Unified.js specification.
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-15 11:52:05 -08:00
|
|
|
## Contributing to Loom
|
2023-04-02 16:49:38 -07:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
Contributions to Loom are welcome.
|
2023-04-02 16:49:38 -07:00
|
|
|
|
2023-11-15 06:47:20 -08:00
|
|
|
### VIM
|
2023-03-31 07:03:45 -07:00
|
|
|
|
2023-11-16 11:37:55 -08:00
|
|
|
This project contains a `.vimrc` file to help with development and
|
|
|
|
maintainance. See that file for more information and instructions for use.
|
2023-03-31 07:03:45 -07:00
|
|
|
|