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

timplate

v0.0.2

Published

just another template engine, probably sucky

Downloads

3

Readme

#Timplate

Tiny and fast templating engine, with a code small enough that anyone can hack at it. Works in all environments, browser, node, through globals, amd, or whatever.

Whyyyyyyyyyy

Hold on, I know there is approximately a million templating engines. Most of them would probably beat this one in terms of features. But after I used a whole damn lot of them (a lot), I couldn't find any that satisfied my own personal brand of logic. Furthermore, you do things because you can, for fun and profit.

Install

npm install timplate

Main Usage

	var timplate = require('timplate');

precompile:

	var template = timplate('Well, I say, {{greeting}}, {{subject}}!')

run:

	var content = template({greeting:'hello',subject:'world'})
	console.log(content);

Outputting a variable

just use a variable surrounded by opening and closing tags

	hello {{whatAreYouSayingHelloTo}}!

will render as (assuming whatAreYouSayingHelloTo = "world")

	hello world!

If you want unescaped (raw) output, use "!"

hello to you {{notADangerousString}} you
will render as (assuming notADangerousString = "")
hello to you & you

whereas
hello to you {{!notADangerousString}} you
will render as (assuming notADangerousString = "")
hello to you & you


Tokens

They are all explained below, but here they are, in summary

* If: '?'
* Else, If Else: '?:'
* Iterator: '#'
* End Loop, End If: '/'
* Raw (unescaped) text: '!'
* Log to console:'l'
* Start Block:'>'
* Print Block:'>>'

IF/Else

equalities require only one "=" You are free to use more, but one is enough. For example, the following paragraph

	you need {{?something=true}}only one "="{{?:}}a lot of "="{{/?}}.

renders as (assuming something==true):

	you need only one "=".

By default, if is denoted by "?" and else/elseif by "?:".

	the number of rabbits is {{? rabbits=3}}three{{?:rabbits=2}}two{{?:}}one or zero{{/?}}.

renders as (assuming rabbits==2):

	the number of rabbits is two.

If blocks end with "/", and you can append anything after the sign. It is practical to follow your nested if statements.

	this if block {{? matters=false}}doesn't matter{{?:}}matters{{/?}}

renders the same as

	this if block {{? matters=false}}doesn't matter{{?:}}matters{{/?matters}}

renders the same as

	this if block {{? matters=false}}doesn't matter{{?:}}matters{{/end of if matters block}}

renders as (assuming matters == false)

	this if block doesn't matter

LOOPS/ITERATIONS

Iterate by using #

	I really like {{# p in people}}{{p}}, {{/#}}
	renders as (assuming people = ['John','Jane','Ali']):
	I really like John, Jane, Ali,

You can get the key by doing that:

	I really like{{# p,i in people}}{{?i=people.length-1}}and{{/if}} {{p}}{{?i!=people.length-1}}, {{/if}}{{/#}}

renders as (assuming people = ['John','Jane','Ali']):

	I really like John, Jane, and Ali

There are some helper functions so you can do that:

	I really like {{# p,i in people}}{{?_last}} and{{?:_first}} my dear{{/if}} {{p}}{{?_middle}}, {{/if}}{{/#}}

renders as (assuming people = ['John','Jane','Ali']):

	I really like my dear John, Jane, and Ali

(of course, _first, _last and _middle operators work on arrays only, and only when you use the "x,y" notation.)

Like if/else blocks, loop closings take an optional string at the end

Blocks

	1 - also, you can render blocks
	{{> nameOfBlock}}
	2 - you can write whatever you want in a block
	{{/>}}
	3 - and blocks can be rendered later. you can also always append to them
	{{> nameOfBlock}}
	4 - As long as the same block name is specified, you can continue to add to it
	{{/>}}

	then output it:

	{{>> nameOfBlock}}

will render as:

	1 - also, you can render blocks

	3 - and blocks can be rendered later. you can also always append to them

	then output it:

	2 - you can write whatever you want in a block

	4 - As long as the same block name is specified, you can continue to add to it

the syntax is simple, just ">" followed by some block name of your choosing.

Others

You can log to console:

	{{l 'hello world'}} 

will render as

	console.log('hello world')

Variables that don't exist get silently removed

Hummm...I think that's it.


Options

Tags

Don't like the {{tags}}? You can change them by using timplate.tagStart(new_tag) and timplate.tagEnd(new_tag)

Globals

Anything that you make available to the timplate.globals object will be available in all templates

timplate.extend

Just a convenience function for when you don't have jquery.extend or zepto.extend at hand. No deep copy though

Customizing template handling

The template returned has a property called "functionString". You can use that to whip up a different templates handling system, or to print them to a file to be used in the browser. There's an example in 'example/writeToFile.js';

If you want to do your own handling, this is the template signature:

	function(locals){
		var context = {escape: timplate.escape, line: 1, buffer : {ret:''}, locals: timplate.extend({},timplate.globals,locals)};
		return func.call(context);
	};

Credit

Most of the original code comes from: https://github.com/cho45/micro-template.js

License

MIT