Skip to content
The friendly pre-processor
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
samples
tests
.gitignore
LICENSE
README.md
pre.ps1

README.md

                 _
  ___  _ _  ___ | |
 | p \| r_>/ e_>!_/
 |  _/|_|  \___.<_>
 |_|

PRE! The friendly pre-processor.

MIT License. Leon Bambrick 2014

Commands:

pre $file        

...process a file, replacing "codeblocks" with their result. write the result to the same file, with .pre suffix removed from the name. e.g. pre 'person.cs.pre' will write to 'person.cs' while pre 'person.cs' will overwrite 'person.cs' (as there is no .pre suffix to be replaced)

pre_help

...help on pre

pre_help_detailed

...verbose help on pre, with details about codeblocks.

               _       _    _            _       
   ___  ___  _| | ___ | |_ | | ___  ___ | |__ ___
  / | '/ . \/ . |/ ._>| . \| |/ . \/ | '| / /<_-<
  \_|_.\___/\___|\___.|___/|_|\___/\_|_.|_\_\/__/

A codeblock is a {language:expression:} embedded in a file that pre replaces with the result of its invocation. Currently there are three kinds of codeblocks that can be used: powershell, sql and NimbleText patterns.

powershell codeblocks look like this:

{powershell:
dir c:\
:}

SQL codeblocks look like this, and are executed against the connection from $env:conn

{sql:
select * from sysobjects
:}

NimbleText codeblocks look like this, and are mixed with the data from file named $env:ntdata

{nt:
Hello $0 how are you.
:}

When pre is run, the codeblocks are replaced with the result of their execution. The start and end tags of a code block must be on their own line. So you can't do this:

{sql:select * from sysobjects:} ← this won't work. yet

The start and end tags can be wrapped in whatever is the native multi-line comment for the platform, e.g.

 /* {powershell:
 dir c:\
 :} */

...this works because the start tag only has to be the last thing on the line, and the end tag only has to be the first thing on the line. Any other text on tag start/end lines is assumed to be comments, and is discarded/replaced.

Why? Why!?

You can make living documents. Perhaps you're writing a book in markdown and you want sections to be self updating.

Perhaps you want a light sprinkling of code generation inside your projects.

Getting started...

Dot source the file pre.ps1. i.e, run this:

. .\pre.ps1

...perhaps as part of your $PROFILE.

Thereafter you will have the 3 functions available:

  • pre
  • pre_help
  • pre_help_detailed
You can’t perform that action at this time.