Categorygithub.com/lucat1/randr
modulepackage
0.0.8
Repository: https://github.com/lucat1/randr.git
Documentation: pkg.go.dev

# README

Randr

Randr is a golang library to render HTML templates for server-side rendering, highly inspired by react, preact/htm and lit-element. It is still a proof-of-concept, but should perform way better compared to html/template because it compiles expressions to static code in golang, which means it also has 0 runtime overhead(similarly to quicktemplate).

Built with randr:

Installation

To install the compiler and the library it is suggested to use the standard go get command:

  $ go get -u github.com/lucat1/randr/rcc # get the compiler
  $ go get -u github.com/lucat1/randr # get the library (inside a project root)

Usage

To compile a file or a folder of files you should use the rcc(randr code compiler) tool as follows: (supposing $GOPATH/bin is available inside your $PATH)

  $ rcc <input> <output>

<input> can be either a file or a folder

<output> is the output location, and supports currenly only the [name] placeholder

Here's an example:

  $ rcc src "dist/[name].randr.go"

# Packages

No description provided by the author
No description provided by the author

# Functions

HTML is a dummy function to enable auto-completion when writing randr components, but it is never actually called during runtime since `randr` is an entirely pre-compiled library.
Inherit inherits all the available data from the ancestor context but *resets the props*.
MustRender renders a component into a string with the given props NOTE: Only used internally to render a component into a string ignoring the context, in cases when it's useless, such as when rendering a custom element from a computed template literal.
Render renders a component into a string with the given props.
RenderWithData renders a component into a string with the given props and initial context data.

# Structs

BasicProps is a struct used in many components which only care about their HTML children represented as a rendered string of valid HTML code.
Context is the rendering context in which the component is executed(and rendered).

# Type aliases

Component is a struct representing any component which receives the rendering context and returns a string with valid HTML code inside.
ContextKey is the unique key which must be implemented by any context providing/consuming library.