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

dom-template

v0.6.14

Published

Very simple and dynamic client side templating

Downloads

1

Readme

temple

Super simple dynamic templating.

ie8+

installation

npm install dom-template

api

Temple.clone(data)

var Temple = require('temple')
var UserView = Temple.clone({name: 'bob ross'})

You can also do Temple.clone() and then later do Temple.set(model) if you don't want to load the model right away.

Temple.render(dom_node)

var el = query('#user-profile')
UserView.render(el)

Temple.clear()

You can call View.clear() to clear out all listeners, free up memory, and reset the DOM.

interpolation

You can use {property} anywhere in the dom to interpolate data.

<p>{greeting}</p>
var el = query('p')
var model = {greeting: 'hallo welt!'}
var view = Temple.clone(model).render(el)

Result:

<p>hallo welt!</p>

loops

Use the each attribute. Within the element having the each attribute (and the element itself), all properties are scoped to each element in the array.

<div each='users' data-id={id}>
	<p>{name}</p>
	<p>{status}</p>

	<ul each='comments'>
		<li>{this}</li>
	</ul>
</div>

To refer to the element itself within the loop, use this.

conditionals

You can use a ? within interpolations to do conditionals -- useful for assigning classes based on bools.

<p class={anonymous ? hide}>{name}</p>

Everything after the ? is a string that will be interpolated if the boolean is true

dynamic changes

If your data model emits change {property} events, then Temple will automatically update the DOM using your changed data. You never have to re-render the template. Only call render once at the beginning, and then every change to the data will update in the DOM.

configuration

You can customize Temple's entire interface by simply overriding certain properties.

Temple.listen(model, property, render_function)

By default, Temple listens for events on your model using model.on('change property', render). If you wanted to instead listen with, for example, model.bind(property, render), you can do:

Temple.listen = function(model, prop, render) {
	model.bind(prop, render)
}

listen does not need a return value.

Temple.get

By default, Temple uses either of data[property] or data.get(property) to access your data. To use a library where the model attributes are retrieved with model.fetch(property), you can do:

Temple.get = function(model, property) {
	return model.fetch(property)
}

The return value of get should be the retrieved attribute.

Temple.left_delimiter, Temple.right_delimiter

You can change the interpolation pattern from {property} to something else. Pass in the left and right delimiters as strings. For example, to interpolate using #{property} instead:

Temple.left_delimiter = '#{'
Temple.right_delimiter = '}'

Or to use erb-style, `<%= property %>':

Temple.left_delimiter = '<%='
Temple.right_delimiter = '%>'

You don't have to escape any characters like { or [.

Avoiding flashing of interpolation characters

Since Temple is designed to render directly into your dom, we might get a flash of {property} text for interpolated properties on slow connections before the template has loaded data. To avoid this, I recommend setting a template class such as 'temple' to your template elements. Temple will add the class 'temple-rendered' when the data is finished rendering into the element. For example:

<div class='temple'>{prop}</div>

Set .temple to initially be hidden and .temple.temple-rendered to display.

.temple {
	display: none;
}

.temple.temple-rendered {
	display: block;
}

Temple renders and finishes...

<div class='temple temple-rendered'>Hello!</div>

compatible libs

Models that emit change events that you can use alongside Temple include: citizen, model, modella, bamboo.