Skip to content

complate's core library for rendering HTML via JSX

Notifications You must be signed in to change notification settings

tmehnert/complate-stream

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

complate-stream

complate's core library for rendering HTML

package version build status Greenkeeper badge

How It Works

At the core of complate-stream lies generateHTML, an implementation of the signature expected by JSX (as pioneered by React). When invoked, that function returns an "element generator"; a function serving as placeholder for the HTML element to be generated:

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 <h1> and <p> before the <body> and <html> 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:

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 lang="en"><body id="top"><h1>hello world</h1><p>lorem ipsum</p></body></html>

About

complate's core library for rendering HTML via JSX

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.5%
  • Shell 0.5%