An open API service indexing awesome lists of open source software.

https://github.com/cdrubin/pash-lua

templated text document manipulator - think generic tool that can also be a static site generator
https://github.com/cdrubin/pash-lua

lua static-site-generator template

Last synced: 2 months ago
JSON representation

templated text document manipulator - think generic tool that can also be a static site generator

Awesome Lists containing this project

README

        

pash
====

*pash* is a text processor that allows lua to be executed in
the context of page generation. Developed as a static website
generator that uses [templet](https://colberg.org/lua-templet) for templating.

*pash* adds execution of `_context.pash` to the environment
when processing the contents of a directory (and child directories inherit
the environment of their parents).

Files and directories that begin with `_` or `.` are ignored.

She understands two kinds of tags inside source files :

Code
----
Starting a line with the **|** character indicates that what follows is lua code
``` lua
| for i = 1,5 do


| end
```

Value
-----
When the **${...}** is encountered in a source file the results of the code within elipses is inserted into the source
``` lua
| for i = 1,5 do %]

  • Item ${ i }

  • | end
    ```

    There is one built-in function provided:

    ``` lua
    ${ include( '_snippet/menu.html' ) }
    ```

    *pash* could certainly process any filetype but we usually have her
    chew on HTML, CSS and JS template files.

    A common need when using pash as a static site generator
    is the use of a _layout_ inside which to embed the
    content of a page. Specifying a layout can be done in a `_context.pash`
    file so that all pages in that directory and any of its child directories
    use a particular layout. Specifying the layout template can of course
    also be done inside the page itself.

    ```lua
    page.layout = '_layout/site.html'
    ```

    **avoid** doing something like the following :
    ```lua
    page = { layout = '_layout/site.html' }
    ```
    because you will be clobbering the page table contents created elsewhere.

    When specifying a layout the page is rendered to the variable `page.content`.

    So with a layout like this :

    ```
    _layouts/
    site.html
    _snippets/
    menu.html
    _context.pash
    index.html
    ```

    we could have :
    ```
    --- _context.pash
    page.layout = '_layout/site.html'


    --- _layout/site.html


    ${ page.title }


    ${ page.content }



    --- index.html
    | page.title = 'The truth about Pashlicks'

    Pashlicks loves her sisters Josie and Marmite
    ```

    to produce an index.html file containing :
    ```html


    The truth about Pashlicks

    Pashlicks loves her sisters Josie and Marmite

    ```

    Every page has some *special* variables availabe in its environment:

    ```lua
    page.file -- filename of file being processed
    page.directory -- directory of the file being processed
    page.path -- path to file from root of site
    page.level -- level in the tree at which this page sits

    site.tree -- tree of site

    pash -- a lua table available for user data and functions
    ```

    Calling pash should be as simple as :

    ```bash
    ./pash.script
    ```

    or use the [APE](https://justine.lol/ape.html) binary distribution thanks to [cosmopolitan libc](https://justine.lol/cosmopolitan/index.html):

    ```
    ./pash.com
    ```
    (which happens to be a .zip file that contains the dependencies)

    To create a new package:

    ```bash
    cp lua.com.original pash.com
    zip pash.com main.lua inspect.lua templet.lua markdown.lua json.lua
    ./pash.com
    ```