1b922b5155 | ||
---|---|---|
docs | ||
src | ||
test | ||
.eslintrc.cjs | ||
.gitignore | ||
.vimrc | ||
README.md | ||
bitbucket-pipelines.yml | ||
index.mjs | ||
jest.config.js | ||
package-lock.json | ||
package.json |
README.md
@thefarce/loom
What is this?
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).
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.
When should I use this?
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.
Installation
$
npm install @thefarce/loom
Usage Example
For more thorough usage examples, see the examples
directory and refer to
the documentation.
import {
interpolate, // interpolate data into the AST
htmlToAst, // parse HTML to an AST
astToHtml, // render HTML from an AST
transform, // transform an AST according to plugins
} from '@thefarce/loom'
console.log(
renderHtml(
interpolate(
transform(
parseHtml('<p>Hello, {name}!</p>'),
[],
),
{ name: 'Othello' },
)
)
);
Running this script produces the following output:
<p>Hello, Othello!</p>
API
renderHtml(ast)
parseHtml(html)
interpolate(ast, data)
transform(ast, plugins)
Transform the AST according to plugins.
ast
The AST to be transformed. This can be any AST that conforms to the Unified.js specification, especially the hast AST.
plugins
Plugins are pairs of functions.
The selector function
The transformer function
Development
VIM
This project contains a .vimrc
file to help with development and
maintainance. See that file for more information and instructions for use.