Go to file
Sir Robert Burbridge 1b922b5155 Basic structure in place. 2023-11-15 10:55:55 -05:00
docs Improve test, add docs. 2023-04-09 11:22:30 -04:00
src Basic structure in place. 2023-11-15 10:55:55 -05:00
test Basic structure in place. 2023-11-15 10:55:55 -05:00
.eslintrc.cjs Basic structure in place. 2023-11-15 10:55:55 -05:00
.gitignore Initial commit 2023-03-30 23:04:35 +00:00
.vimrc Core commit for loom with hast. 2023-11-15 09:47:20 -05:00
README.md Core commit for loom with hast. 2023-11-15 09:47:20 -05:00
bitbucket-pipelines.yml Core commit for loom with hast. 2023-11-15 09:47:20 -05:00
index.mjs Basic structure in place. 2023-11-15 10:55:55 -05:00
jest.config.js Core commit for loom with hast. 2023-11-15 09:47:20 -05:00
package-lock.json Basic structure in place. 2023-11-15 10:55:55 -05:00
package.json Basic structure in place. 2023-11-15 10:55:55 -05:00

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.