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

jsmart

v4.0.0

Published

jSmart is javascript templating engine based on PHP Smarty Template Engine.

Downloads

2,378

Readme

jSmart - Smarty template engine in JavaScript

Build Status npm version David npm npm

jSmart is a port of the Smarty Template Engine to Javascript, a JavaScript template library that supports the template syntax and all the features (functions, variable modifiers, etc.) of the well-known PHP template engine Smarty.

jSmart is written entirely in JavaScript, does not have any DOM/browser or third-party JavaScript library dependencies and can be run in a web browser as well as a standalone JavaScript interpreter or CommonJS environments like node.js.

jSmart supports plugin architecture, you can extend it with custom plugins: functions, blocks and variable modifiers, templates inclusion, templates inheritance and overriding, caching, escape HTML.

jSmart has some limited support of the PHP Smarty syntax and allows you to use the same Smarty templates on both server and client side, for both PHP and Javascript.

Play with JsFiddle demo page

Using jSmart with CDN

Always latest version (don't use in production)
https://cdn.jsdelivr.net/npm/jsmart/dist/jsmart.min.js
Current latest version (4.0.0)
https://cdn.jsdelivr.net/npm/[email protected]/dist/jsmart.min.js

jSmart with other tools

  1. Webpack:- https://www.npmjs.com/package/jsmart-loader
  2. Grunt:- https://www.npmjs.com/package/grunt-jsmart
  3. Express Js :- https://www.npmjs.com/package/jsmart-express

How to use jSmart in Node.js

  1. Install jSmart from NPM Registry
$ npm install jsmart --save
  1. Create template, use PHP Smarty syntax. Say demo.tpl
Hello {$name}
  1. Now lets read the template and compile it. jSmart object compiles the template. You can call fetch function as many times with different data you would want to assign to template.
var fs = require('fs'),
  jSmart = require('jsmart'),
  tpl = fs.readFileSync('./demo.tpl', {encoding: 'utf-8'}),
  compiledTemplate = new jSmart(tpl),
  output = compiledTemplate.fetch({name: 'World'});
  // output will be "Hello world"

console.log(output);
  1. Execute the file.
$ node demo.js

How to use jSmart in browser

  1. Include jSmart library Javascript file in your header.
<html>
  <head>
    <script language="javascript" src="jsmart.js"></script>
  </head>
  1. Create template, use PHP Smarty syntax. Put the template's text in <script> with the type="text/x-jsmart-tmpl" so a browser will not try to parse it and mess it up.
  <script id="test_tpl" type="text/x-jsmart-tmpl">
    Hello {$name}
  </script>
  1. Create new object of jSmart class, passing the template's text as it's constructor's argument than call fetch(data), where data is an JavaScript object with variables to assign to the template
<script>
  var content = document.getElementById('test_tpl').innerHTML;
  var compiled = new jSmart(content);
  var output = compiled.fetch({name: 'world'});
  // output will be "Hello world"
</script>

How to use jSmart using Require.js

  1. If you have configured and installed Require.js it easy to load jSmart and use it. Load jSmart.js file in the browser/environment and it already makes use require js to define module, you got to just include it.
define(['jSmart'], function (jSmart) {
  var tplText = 'Hello {$name}';
  var compiled = new jSmart(tplText);
  var output = compiled.fetch({name: 'world'});
  // output is "Hello world"
});
  1. You can also make use Require.js text plugin to load templates.
define(['jSmart', 'text!some/good/template.tpl'], function (jSmart, goodTpl) {
  var compiled = new jSmart(goodTpl);
  var output = compiled.fetch({name: 'world'});
  // output is "Hello world"
});

DOCUMENTATION

https://github.com/umakantp/jsmart/wiki

CONTRIBUTIONS & TESTS

  • Pull request Best is open a issue first. Then send a pull request referencing the issue number. Before sending pull request make sure you add test case for the fix. Make sure all test cases are passing and eslint tests pass.

  • Test cases:- grunt karma

  • ES Lint tests:- grunt eslint

  • Run lint, run test, build, compress, distribution package and update examples in one command:- grunt

LICENSE

MIT

NOTICE

Project originally was created by miroshnikov. Since author was not active on project very frequently. I have forked and planned on pushing further improvements and features on my own fork.