Giter Site home page Giter Site logo

pre's Introduction

                 _
  ___  _ _  ___ | |
 | 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

pre's People

Contributors

secretgeek avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.