1. liquor
Templates, minus the code.
liquor
Package: liquor
Created by: chjj
Last modified: Sun, 19 Jun 2022 12:43:10 GMT
Version: 0.0.5
Downloads: 2,456
Repository: https://github.com/chjj/liquor

Install

npm install liquor
yarn add liquor

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.

 ?:data
  <table>
    <tr>
      @:col
        <td>#{this}</td>
    </tr>
    @:data
      <tr>
        <td>#{this.color}</td>
        <td>#{this.animal}</td>
      </tr>
  </table>

!:data
  <div>
    ?:error
      <p>Sorry, there was a problem: #{error}.</p>
      <p>Please, try again!</p>
    !:error
      <p>Sorry, no error message.</p>
  </div>

Is essentially shorthand for:

 `if (typeof data !== 'undefined' && data) {`
  <table>
    <tr>
      `each(col, function() {`
        <td>#{this}</td>
      `})`
    </tr>
    `each(data, function() {`
      <tr>
        <td>#{this.color}</td>
        <td>#{this.animal}</td>
      </tr>
    `})`
  </table>
`} else {`
  <div>
    `if (typeof error !== 'undefined' && error) {`
      <p>Sorry, there was a problem: #{error}.</p>
      <p>Please, try again!</p>
    `} else {`
      <p>Sorry, no error message.</p>
    `}`
  </div>
`}`
 `/* liquor also exposes an "each" helper function */`
`/* it is the same one used internally for @ statements */`
`if (messages)
  each(messages, function(message, key) {`
    <p>#{key}: #{message.content}</p>
  `})`

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.

 `if ($.messages) {` <p>#{JSON.stringify(messages)}</p> `}`

License

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code