SchlenkR / Trulla

Type Safe Text Templates - usable as type provider (F#) or source generator (C#)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo

Trulla Templates is like Handlebars or Mustache templates, but statically typed and safe!

NuGet Badge - C# Source Generator

NuGet Badge - F# Type Provider

npm version - Node CLI

The Trulla Approcah

  • Provide a text template with:
    • template parameters
    • iterations
    • conditionals
  • A model type is infered from a given template.
  • An instance of the model is provided by the user for rendering the final template.

Examples and Usage

Node via CLI

Go to the Node CLI Documentation

C# usage via Source Generators

Go to the C# Documentation

F# usage via Type Providers**

Go to the F# Documentation

General Template Syntax

Have a look at the tests for more samples!

for loops (with separator)

  • This will render 'abc' for given chars = ["a"; "b"; "c"]:
{{for c in chars}}{{c}}{{end}}
  • With a given separator between items, this will render 'a;b;c' for given chars = ["a"; "b"; "c"]:
{{for x in numbers|;}}{{x.id}}{{end}}

if/else

  • This will print "Order is active." or "Order is closed." depending on the value of order.isActive:
  • The else part is optional.
Order is {{if order.isActive}}active{{else}}closed{{end}}.

How it works internally

Trulla is implemented in F#. It basically contains everything a "real" language has, like

  • a parser
  • an untyped AST
  • type inference with a solver
  • a typed AST
  • code generation

If you want to know more, have a look at the (Internals)[./src/docs/Internals.md].

About

Type Safe Text Templates - usable as type provider (F#) or source generator (C#)

License:Apache License 2.0


Languages

Language:F# 99.5%Language:C# 0.2%Language:TypeScript 0.1%Language:Dockerfile 0.1%Language:PowerShell 0.0%Language:Mustache 0.0%Language:JavaScript 0.0%