Mustache-like extension to HTML syntax, designed for use with React and transpiled into JSX.
To use Restache in your project, you'll need to integrate the ESBuild plugin:
go get github.com/tetsuo/restache
For example, to list fruits, create fruits.stache
:
<ul>
{#items}
<li>{name}</li>
{/items}
</ul>
import (
"github.com/evanw/esbuild/pkg/api"
"github.com/tetsuo/restache"
)
func main() {
api.Build(api.BuildOptions{
EntryPoints: []string{"main.mjs"},
Bundle: true,
Plugins: []api.Plugin{restache.Plugin()},
Outfile: "out.js",
})
}
import Fruits from './fruits.stache'
import { createRoot } from 'react-dom/client'
const root = createRoot(document.getElementById('root'))
root.render(Fruits({ items: [{ name: 'Apple', key: 'apple' }] }))
Run your build process, and .stache
files will be transpiled into JSX automatically.
A more complete usage example is available in the tetsuo/dashboard repository.
Use {variableName}
to interpolate variables.
{?isVisible}...{/isVisible}
renders content when the condition is true.
{^isHidden}...{/isHidden}
renders content when the condition is false.
{#list}...{/list}
iterates over a list.
Define components using custom tags, which are resolved based on naming conventions and mappings.
Restache resolves component tags by:
- PascalCasing: Converting tag names to PascalCase.
- Prefix Mapping: Using configured prefixes to locate components.
- Tag Mappings: Directly mapping tag names to component paths.
These mappings are configured via the ESBuild plugin options.