Skip to content

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

License

Notifications You must be signed in to change notification settings

SchlenkR/Trulla

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎁 Win a PXL-Clock - Watch How on YouTube 🎁

Watch the PXL-JAM video

YouTube

The PXL PAM 2024 is a fun and engaging way to come together and have a joyful time! Watch the video or check out our PXL-JAM repo!


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#)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published