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

Trulla Templates

...it's like Handlebars or Mustache templates, but statically typed!

Status: Stable

C# Source Generator: NuGet Badge

F# Type Provider: NuGet Badge

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

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 internals

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