Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/chjj/liquor

A templating engine minus the code.
https://github.com/chjj/liquor

Last synced: 16 days ago
JSON representation

A templating engine minus the code.

Awesome Lists containing this project

README

        

# Liquor

Liquor is a templating engine for node. It's very lightweight. It's essentially
embedded javascript with some shorthand significant whitespace notation
available. This is to discourage use of raw code and make templates look nicer.

## Usage

Backticks are used for evaluation, while `#{}` is used for interpolation.

``` html
?:data


@:col
#{this}

@:data

#{this.color}
#{this.animal}

!:data


?:error

Sorry, there was a problem: #{error}.


Please, try again!


!:error

Sorry, no error message.



```

Is essentially shorthand for:

``` html
`if (typeof data !== 'undefined' && data) {`


`each(col, function() {`
#{this}
`})`

`each(data, function() {`

#{this.color}
#{this.animal}

`})`

`} else {`


`if (typeof error !== 'undefined' && error) {`

Sorry, there was a problem: #{error}.


Please, try again!


`} else {`

Sorry, no error message.


`}`

`}`
```

``` html
`/* liquor also exposes an "each" helper function */`
`/* it is the same one used internally for @ statements */`
`if (messages)
each(messages, function(message, key) {`

#{key}: #{message.content}


`})`
```

If you're worried about the notorious "undefined" problem with variables
expressed in raw evaluation of JS, you can access them as properties on a
variable called `$`, which exists within the context of a template, and holds
all of the locals and helpers:

e.g.

``` html
`if ($.messages) {`

#{JSON.stringify(messages)}

`}`
```

## License
(c) Copyright 2011-2012, Christopher Jeffrey. See LICENSE for more info.