Introducing Textrude - using Scriban to generate code from data

Textrude Interactive prototyping GUI

Textrude features

  • turns CSV, JSON or YAML input into an understandable and accessible data model
  • operates on that model via Scriban templates which support both in-line text boilerplate and logical constructs
  • adds environment variables and user-supplied definitions to the data-model to make it easier to stamp generated code with build information
  • solves the “trailing comma” problem using Scriban’s for.last variable
  • allows a single template to combine multiple models and to produce multiple output files (for example, generate a .h header file and .cpp source file from the same template)
  • contains its own dependency-checking mechanism that allows you to avoid rebuilding output files unless the input has changed.
  • is provided as both a cross-platform CLI executable
  • comes with a GUI prototyping tool that shows you what the output will look like in real-time as you edit input.
  • exposes a number of useful functions that make it easy to apply naming-conventions to output code
  • is free and open-source

A quick example

Id,Text
disk error, hard-disk is faulty — save your work at once!
keyboard stuck, press F1 to reboot
faulty touchscreen, please recalibrate the display
/* Built 18 Jan 2021 on machine BUILDSERVER_5 */public static class SystemErrors
{

public const string DiskError =
“hard-disk is faulty — save your work at once!”;

public const string KeyboardStuck =
“press F1 to reboot”;

public const string FaultyTouchscreen =
“please recalibrate the display”;

/* Built {{date.now}} on {{env.COMPUTERNAME}} */
public static class SystemErrors
{
{{for row in model}}
public const string {{row.Id | humanizr.pascalize}} =
“{{row.Text | string.strip}}”;
{{end}}
}
  • There’s no need to do anything to process the CSV file; it’s automatically turned into a data model for you. Columns in the spreadsheet appear as properties which you can “dot into” and the model itself is just an enumerable array of rows
  • Double-braces are used to mark Scriban code blocks with boilerplate text interspersed
  • Contextual information such the time and environment information is made available automatically
  • Built-in helpers such as the Humanizer “pascalize” method can be used to provide the desired casing. Scriban uses the “pipe” operator to chain function calls

TextrudeInteractive for quick prototyping

Download

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store