Text Substitution In Neu

When duplicating text-based template files (txt, html, xml, etc), you can get Neu to perform some substitutions - filling in blanks in the document with dynamic values.

The dynamic values can come from three main places:

  • information about the command that Neu is performing, such as the name of the template it's duplicating, and where it is putting it
  • environment variables that were passed to Neu by the operating system
  • commands that return calculated values such as the current date and time

Information About The Current Command

You substitute a variable into a Neu template using the following syntax:

{{ var }}

where var is the name of the variable.

Neu current supports the following variables:

  • name: the name of the template that is being duplicated
  • template: the path to the original template that is being duplicated
  • path: the path to the new file that is being created from the template

Environment Variables

A few environment variables are passed to Neu by the operating system when it is launched. It makes these values available for use in substitutions:

Some of the more useful environment variable values:

  • USER: the unix login name of the user
  • HOME: the home directory of the user
  • PATH: the value of the unix PATH environment variable
  • LOGNAME: the name that the user logged in as
  • SHELL: the default shell for the user

Note that this isn't the complete environment that you'd expect to see if you opened a terminal window, it's just the subset that Neu receives.

See this Apple technical note for more details on how add your own values to this set.

Commands

Commands are inserted into a template with the syntax

{% command %}

Currently Neu supports just one command.

Command: now

This command inserts the current date/time.

The date_format filter (see the discussion on filters below) allows you to specify the exact format that you want, like so:

{% now | date_format: "dd MMM yyyy 'at' HH:mm:ss" %}

Filters

Filters can be combined with a variable or command, to modify it's output, using the syntax {{ name | filter }} or {% command | filter %}.

Currently Neu supports the following filters:

  • uppercase: turn the content into upper case
  • lowercase: turn the content into lower case
  • capitalized: capitalise each word of the content
  • date_format: format a date (the formatting system used is detailed here

Examples

Some examples of how to use substitution can be found in the default templates that Neu makes for you.

More Information

The substitution support in Neu is currently based on Matt Gemmell's MGTemplateEngine.

You can find some more detailed documentation on it here:

Note that in my documentation above I refer to a "command", which is what Matt calls a "marker".


Back to the Neu home page...