Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

squirrelly

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

squirrelly

A simple yet powerful ExpressJS template engine that works out-of-the-box

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
decreased by-13.92%
Maintainers
1
Weekly downloads
 
Created
Source

squirrelly 🐿️

Build Status dependencies Status npm version npm downloads GitHub commit activity Codacy Badge JavaScript Style Guide

Squirrelly is an easy-to-use ExpressJS Template engine that includes basic conditional statements, passing in options to HTML, and even passing in options to inline JavaScript for advanced conditionals!

Why to use Squirrelly

  • It's super easy to use, with double-bracket syntax similar to Mustache.js, Handlebars.js, and Swig
  • It was made for Express; there's no need to pipe or do weird input stuff... it just works
  • Unlike many other template engines, it doesn't make a JS file to access the DOM--instead, it just returns correct HTML to the __express function

Basic Usage

  1. Download squirrelly (npm install squirrelly --save)
  2. Create an index.sqrl file (that's explained below, but basically you just put options between double brackets)
  3. Create your JS file. An example is shown below

const express = require('express')//Require express
const app = express()

app.set('views', 'tests/views') //specify views directory (where your sqrl files are)
app.engine('sqrl', require('squirrelly').__express);//Set the template engine to squirrelly, and make it use .sqrl files. If you don't do this, you'll have to use the file extension .squirrelly
app.set('view engine', 'sqrl'); (use squirrelly as a template engine)


app.get('/', function (req, res) {//When a request is made to the server
  res.render('index', { title: 'Hey', message: 'Hello there!', birthday: 'today', truth: true, untruth: false})//Render index.sqrl, with options
})

app.listen(3000, function () {//Start the server
  console.log('Should be rendering on port 3000...')
})

  1. Watch the magic happen!

Syntax

To use squirrelly, instead of creating an HTML file, create a .sqrl file. (This will only work if you inlude the following code:

app.engine('sqrl', require('squirrelly').__express);

Otherwise, you can name your files with the .squirrelly extension. Inside these files, to pass in an option, just put it inside of double brackets. For example, if the options passed to the squirrelly file are { title: 'why you should use squirrelly', reason: 'it's awesome'}, your .sqrl file could look like this:

<!DOCTYPE html>
<html>
  <head>
    <title>{{title}}</title> //Evaluates to <title>why you should use squirrelly</title>
  </head>
  <body>
    <p>Because {{reason}}</p> //Evaluates to <p>Because it's awesome</p>
  </body>
</html>

Right now, squirrelly only has basic functionality with conditionals (though it's under active development.) But remember, squirrelly can parse anything, even content of script tags. We recommend using squirrelly inside script tags for advanced logic. A very basic example is shown below:

<script>
var userInfo = {{{userInfo}}};
if (userInfo !== null && userInfo !== undefined) {
document.getElementById("userInfo").innerHTML = {{{userInfo}}};
}
</script>

Conditionals

Conditionals have the same simplicity as just regularly passing in options. Currently, Squirrelly just supports true and false conditionals, but more options are expected to come very soon.

A basic Squirrelly conditional follows the following syntax:

{(conditional statement){
	HTML that displays if the conditional passes
}*}

To test if an option is true, pass in the desired option without anything else.

{(truth){
    <p>truth = true!</p>
}*}

To test if an option is false, pass in the option with an exclamation point in front of it.

{(!untruth){
    <p>untruth = false!</p>
}*}

Contributing

Squirrelly is still under very active development, and all contributors are welcome. Feel free to fork, clone, and mess around! Then, contact me, create an issue, or send a pull request at Squirrelly's Github Repo.

Beginners are welcome! We welcome all contributors, no matter what skill level.

Keywords

FAQs

Package last updated on 07 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc