Hacker News new | past | comments | ask | show | jobs | submit login

I usually use T4 for such tasks. https://en.wikipedia.org/wiki/Text_Template_Transformation_T...

Unlike macros, T4 includes a fully-featured programming language (C#), with all the goodies like collections, cryptography, globalization, etc..




Yeah, T4 is awesome.

And for those readers here who don't like C# for good or bad reasons, you can pretty much do the same with other languages.

Eg Ruby has ERB, usualy used for html templating but you can use it for anything. Make a command line tool that loads a a something.ext.erb file, runs it, and writes a something.ext file and you just made yourself a super powerful preprocessor that you already know how to use.

Many languages have this (eg EJS in JavaScript, PHP itself in PHP (use output buffering), EEx in Elixir, etc). I'd use this over a "learn yet another language" preprocessor language anytime.


Liquid and Jinja2 (both descendants of Django templating language) are also both used outside the web context now. For example, Conda package specs (called "recipes") are written in YAML, but are processed with Jinja2 first.


You still need to learn a new language though (the jinja2 language)


Does it work on .NET core?


You can use Razor engine, IMO they’re very comparable: https://github.com/toddams/RazorLight




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: