Skip to content
Splamy edited this page Nov 4, 2017 · 1 revision

t4rust

Special Directives

Special options can be set in template directives with the following syntax:

<#@ directive_name property="value" property2="value" ... #>

template debug=(true|false)

Used to enable debug output within the template:

<#@ template debug="true" #>
Change this file, and the next `cargo build` will notice.
My Name is: <#= self.name #>.

will show how the template is parsed and translated:

 Rest: "\nChange this file, and the next `cargo build` will notice.\nMy Name is: <#= self.name #>."
 take text: "\nChange this file, and the next `cargo build` will notice.\nMy Name is: " Rest: Ok("<#= self.name #>.")
 take text: ""
 expression start take code: " self.name " code end Rest: "."

 Rest: ""

Template ok!
Generated Code:
f.write_str(r#"
Change this file, and the next `cargo build` will notice.
My Name is: "#)?;
write!(f, "{}",  self.name )?;
f.write_str(r#"."#)?;

template cleanws=(true|false)

Used to remove lines which only have leading spaces and code blocks:

<#@ template cleanws="true" #>
My template
<# for i in 0..3 { #>
looks nice
<# } #>

will become

cleanws="true" cleanws="false"
My template
looks nice
looks nice
looks nice
My template

looks nice

looks nice

looks nice
Clone this wiki locally