npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jspl

v0.0.5

Published

JSP-Like (JSPL) is a simple template engine based on the library: underscore. It's compliant with Express. And the syntax is similar to JSP.

Downloads

16

Readme

JSPL Build Status

JSP Like Template Engine for ExpressJS and NodeJS (based on underscore, support include, cache...)

Features

  • JSP Like language to build template.
  • Layout
  • Cache (production)
  • Include HTML fragment
  • Web component capability
  • Variables: array, string
  • For loop
  • Dynamic expression evaluation

see: Example section

Getting started

  1. Install JSPL
$npm install jspl -save
  1. Enable JSPL in Express 4
// Edit app.js, let's JSPL bind to the express app.
var app = express();

// Disable jade by removing or commenting
// app.set('view engine', 'jade');

// view engine setup
app.set('views', path.join(__dirname, 'views'));

// Disable cache for debug. or set to true: to enable cache in production.
app.set('view cache', false);

// Bind JSPL to express. 
var jspl = require('jspl');
jspl.bind(app);

// Default extension is .html
jspl.setExtension('.jspl');

Sample

An example of application is available under: sample/express/ it shows the template engine in action with express.

Example of code: (GIST)

Condition: if

File: views/index.html

<% if(user){ %> 
  <%= user.profile.firstName %></p>
<% } %>

File: app.js

router.get('/', function(req, res) 
{
  res.render('index', {user: {profile: {firstName: 'Mike'} } });
});

Display variable content

File: views/index.html

<h1>Hello <%= name %></h1>

File: app.js

app.get('/', function(req, res)
{
  res.render('index', {name: 'John'});
})

Result:

<h1>Hello John</h1>

For loop

File: views/index.html

<h1>Hello</h1>
<ol>
  <% _.each(people, function(name) { %>
   
   <li><%= name %></li>
   
  <% }); %>
</ol>

File: app.js

app.get('/', function(req, res)
{
  res.render('index', {people: ['moe', 'curly', 'larry']});
})

Result:

<h1>Hello</h1>
<ol>
  <li>moe</li>
  <li>curly</li>
  <li>larry</li>
</ol>

Template

<jspl:template file="templateName" />
  • templateName : Location of the included view without extension. The extension .html will be added automatically.
  • <jspl: /> : Indicate a tag
  • template : Name of the tag
  • file : Template file location

For example: view.html

<jspl:template file="layout" />

layout.html must include the place where the view is inserted.

<jspl:doLayout>

@see: sample/express

Include fragment

<jspl:include file="chunk" attr1="value1" attr2="value2" />
  • viewName : Location of the included view without extension. The extension .html will be added automatically.
  • <jspl: /> : Indicate a tag
  • include : Tag name
  • file : File name (mandatory)
  • parameters : Optional parameters.

The file chunk is located under the view directory.

Example:

views/index.html

<jspl:include file="web_component" planet="venus" system="solar"/></html>

views/web_component.html

<h1><%= planet %></h1><h2><%= system %></h2>

Output

<html><h1>venus</h1>\n<h2>solar</h2>\n</html>

Testing

This template engine build is animate by a complete regression test suite.

Notes

The simple template language is very close to JSP. It's based on underscore.

This project does not provide any advanced JSP tag. underscore. Compliant with Express. Add the tag include for HTML fragment.

Motivation

I do not like Jade or whatever short HTML template engine. I understand why it's a good solution for basic website. But Jade do not mix well with complex HTML + Javascript Framework like AngularJS. Also, I think software developer should generally minimize the number of transformation that must be done to produce an output. And I have a pretty bad experience with EJS. For example EJS fails badly if you try to run a simple if condition.

Roadmap

  • Improve syntax error message
  • Speed optimization