Templates

The template language for Essential uses StringTemplate groups definitons. Main documentation of how to use StringTemplate in the main docs: http://stringtemplate.org

Credits to Terence Parr for his superb library.

Quick Sample

group TextOutput;

genProject(project) ::= <<
Project $project.Name$
	Description = $project.Description$
	$project.Milestones:genMilestone(); separator="\n"$
End Project
>>

genMilestone() ::= <<
	Milestone $it.Name$
		Date = $it.Date$
	End Milestone
>>

Modifiers

Each attribute substitution can be transformed by two kind of modifiers: separators and formats.

Separator

A separator indicates how collection atttibutes will be rendered. E.g.

items = ["Alfa", "Beta", "Gamma"]

$items; separator="; "$

Renders to: Alfa; Beta; Gamma

Format

Simple formatting can be indicated using the format modiffier. The following ones are predefined:

item = "Alfa"

Destination: $item; format="camelcase"$.

Renders to: Destination: alfa.

ModifierSemantics
format="pascalcase"Pascal case formating. E.g. myGreenHouse renders to → MyGreenHouse
format="camelcase"Camel case formating. E.g. MyGreenHouse renders to → myGreenHouse
format="lowercase"Lower case formatting. E.g. MyGreenHouse renders to → mygreenhouse
format="uppercase"Upper case formatting. E.g. MyGreenHouse renders to → MYGREENHOUSE
format="lispcase"Lisp case formatting. E.g.MyGreenHouse renders to → 'my-green-house'
format="cobolcase"COBOL case formatting. E.g.'MyGreenHouse' renders to → 'MY-GREEN-HOUSE'
format="underscore_case"Underscore case formatting. E.g.'MyGreenHouse' renders to → 'my_green_house'. Used in some naming styleguides for dababases. A format by example can be applied in this case to control capitalization of first word and tail words, and also first letter of echa word: Some additional samples:
Format 'Underscore_case' renders to → 'My_green_house' Note: first char of first word in uppercase.
Format 'Underscore_Case' renders to → 'My_Green_House' Note: first char in uppercase for all words.
Format 'UNDERSCORE_Case' renders to → 'MY_Green_House' Note: first word in upper case, for the rest: first char uppercase, rest lowercase.
format="ltrim"Left trim. E.g.' Hello ' renders to → 'Hello '
format="rtrim"Right trim. E.g.' Hello ' renders to → ' Hello'
format="trim"Trim. E.g.' Hello ' renders to → 'Hello'
format="lpad(n,char)"Left padding n positions with char as fill character. E.g.lpad(6,'.') of '123' renders to → ...123
format="rpad(n,char)"Right padding n positions with char as fill character. E.g.rpad(8,'-') of 'abc' renders to → abc------
format="custom:#.##"Custom extra formating accepted if recognized by the .NET string.Format() function. E.g. Format: {0:#.##} for number 12.345 renders to → 12.34
More samples about formatting: