Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/complate/complate-stream
complate's core library for rendering HTML via JSX
https://github.com/complate/complate-stream
Last synced: about 2 months ago
JSON representation
complate's core library for rendering HTML via JSX
- Host: GitHub
- URL: https://github.com/complate/complate-stream
- Owner: complate
- Created: 2017-05-28T08:46:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-08T13:47:51.000Z (about 3 years ago)
- Last Synced: 2024-10-29T21:39:37.518Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://complate.org
- Size: 121 KB
- Stars: 6
- Watchers: 2
- Forks: 7
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
complate-stream
===============[complate](https://complate.org)'s core library for rendering HTML
[![package version](https://img.shields.io/npm/v/complate-stream.svg?style=flat)](https://www.npmjs.com/package/complate-stream)
[![build status](https://travis-ci.org/complate/complate-stream.svg?branch=master)](https://travis-ci.org/complate/complate-stream)
[![Greenkeeper badge](https://badges.greenkeeper.io/complate/complate-stream.svg)](https://greenkeeper.io)How It Works
------------At the core of complate-stream lies `generateHTML`, an implementation of the
signature expected by [JSX](https://facebook.github.io/jsx/) (as
[pioneered by React](https://reactjs.org/docs/jsx-in-depth.html)). When invoked,
that function returns an "element generator"; a function serving as placeholder
for the HTML element to be generated:```javascript
generateHTML("html", { lang: "en" },
generateHTML("body", { id: "top" },
generateHTML("h1", null, "hello world"),
generateHTML("p", null, "lorem ipsum")));
```This indirection is necessary primarily to ensure proper order and nesting, as
function arguments are evaluated before the surrounding invocation – otherwise
the code above would emit `` and `
` before the `
` and ``
elements.Thus the example above returns a hierarchy of element generators, encapsulated
by a single element generator at the root, which upon invocation writes HTML to
the `stream` object being passed in:```javascript
let element = generateHTML(…);
element(stream, …);
```(`stream` is expected to support the methods `#write`, `#writeln` and `#flush`;
see `BufferedStream` for a sample implementation).With our example, this should result in the following string being emitted:
```html
hello world
lorem ipsum
```