Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/chjj/liquor
- Owner: chjj
- License: mit
- Created: 2011-05-08T12:54:42.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2014-02-02T06:22:39.000Z (almost 11 years ago)
- Last Synced: 2024-10-20T01:14:59.165Z (24 days ago)
- Language: JavaScript
- Homepage:
- Size: 150 KB
- Stars: 19
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.