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

temple-wat

v0.2.5

Published

Template engine with unique Extra-Virgin-Single-Pass™ compiler technology

Downloads

4

Readme

Temple template engine

Install dependencies

npm install

Examples

See examples

Build examples:

node ./bin/temple examples/*temple # Dump on stdout
node ./bin/temple examples/*temple > templates.js # Dump into templates.js

Use

Load scripts [temple_utils.js, templates.js]

Or cat templates.js temple_utils.js > res.js and paste it into chrome console

console.log(JSON.stringify(window.templates_pool.info())); # pool is empty
var t = window.templates_pool.get("ss"); # Load empty ss template
console.log(JSON.stringify(window.templates_pool.info())); # pool has one busy ss item
console.log(t[0]); # Look as dom
t[1].A("FiRsT");
console.log(t[0]);
t[1].B([{C: 1, E: "Yahhhoo!"},{C: 2, E: "MMMM",D: [1,1,1,9]}]);
console.log(JSON.stringify(window.templates_pool.info())); # more busy templates
window.templates_pool.build_cache({"ss": 100}); # build 100 elements cache for ss template
console.log(JSON.stringify(window.templates_pool.info())); # fresh new 100 ss items ready for action
console.log(t[0]);

Using instruction for browser env

1. Write temple file

For example, your template file my_template.temple looks like:

<div id="{{id}}">
  {{name}}
</div>

2. Compile

Build temple functions from template:

node path/to/temple/bin/temple my_template.temple > templates.js

3. Include template

Also don't forget include temple_utils.jsto your page, head section must look like:

<script src="temple_utils.js"></script>
<script src="templates.js"></script>

After that you'll have templates variable with all your templates and temple manipulations methods. Templates named by filename, for example you get templates.get('my_template').

4. Fill template by data

For example, you want render simple information:

data = {
  "id": 1,
  "name": "John"
}

Don't forget that json must be valid, you can try validator first. And finnaly pass data to your template:

myTemplate = templates.get('my_template', data);

or

pool = templates.get('my_template')[1];
myTemplate = pool.update(data);

Variable myTemplate its array with [0] DOM template and [1] temple methods for template.

5. Append template to DOM

div = document.getElementById('place-for-append')
div.appendChild(myTemplate[0])

Syntax

Temple templates are valid XML-tree:

<div id="{{id}}">
  {{name}}
</div>

Loops:

You can use forall instruction for render each item of array:

<ul>
  <forall key="items">
    <li>{{value}}</li>
  </forall>
</ul>

Conditional statements:

And use if for simple conditions:

<div>
  <if key="plane">
    Flight number: {{airline}} {{number}}
  </if>
  <if key="train">
    Train number: {{number}}
  </if>
</div>

Partial templates:

Use include to include partial template:

<include name="foo" key="value"/>

where foo is template name, and value is data for rendering;

Methods

.info()

.get(template_name)

myTemplate = templates.get('my_template');

.get(template_name, data)

myTemplate = templates.get('my_template', {data: data});

.update(data)

.build_cache({template_name: num_of_copy})

templates.info().free
templates.build_cache({‘my_template’: 1000})
templates.info().free

.remove()

.root()

Return DOM element

.child_template_name()

Temple provide setters for child template, for template my_template

<ul>
  <forall key="items">
    <li>{{data}}</li>
  </forall>
</ul>

You'll have

myTemplate = templates.get('my_template')[1]
myTemplate.items([{"data": "some data"}, {"data": "some data2"}])