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

tempreites

v0.1.8

Published

Semantic string templates direto da roça for the browser and server.

Downloads

11

Readme

DEMO

Comparison with Mustache

Tempreites

Crude string templating without any syntax, just semantic HTML.

Usage

Get this as a string,

<div id="austrianeconomics">
  <h1 class="title"></h1>
  <ul id="theories">
    <li>
      <span class="author"></span>
      <span>
        <a class="theory" 
           data-bind-here="href"
           data-bind-there="url">
        </a>
      </span>
    </li>
  </ul>
</div>

attach data to it,

var data = {
  title: 'Austrian economists and their theories',
  theories: [
    { author: 'Menger', theory: 'Subjective value', url: '/subj' },
    { author: 'Hayek', theory: 'Austrian Business Cycle Theory', url: '/abct' },
    { author: 'Kirzner', theory: 'Sheer ignorance and entrepreneurship', url: '/entre' },
  ]
}

tempreites.render(template, data)

get this back:

<div id="austrianeconomics">
  <h1 class="title"></h1>
  <ul id="theories">
    <li>
      <span class="author">Menger</span>
      <span>
        <a class="theory" 
           data-bind-here="href"
           data-bind-there="url"
           href="/subj">
          Subjective value
        </a>
      </span>
    </li>
    <li>
      <span class="author">Hayek</span>
      <span>
        <a class="theory" 
           data-bind-here="href"
           data-bind-there="url"
           href="/abct">
          Austrian Business Cycle Theory
        </a>
      </span>
    </li>
    <li>
      <span class="author">Kirzner</span>
      <span>
        <a class="theory" 
           data-bind-here="href"
           data-bind-there="url"
           href="/entre">
          Sheer ignorance and entrepreneurship
        </a>
      </span>
    </li>
  </ul>
</div>

Features

  • Semantic data binding - No need for <%=foo%> or {{foo}} assignments
  • Collection rendering - No need for hand-written loops
  • Valid HTML templates - Write templates as a part of the HTML, in plain HTML
  • View logic in JavaScript - No crippled micro-template language, just plain JavaScript functions

TODOs:

  • Basic optmization
  • Read some data- attr to see in which element arrays of data will duplicate

Installation

npm install tempreites

Or download the file and include it anywhere.


Documentation

Considering a data object like this:

var data = {
  name: 'Miyamoto',
  link: '/miyamoto',
  completeName: {
    first: 'Shigeru'
    last: 'Miyamoto'
  },
  sons: [{ name: 'Mario', show: true }, { name: 'Luigi', show: false }]
  show: true
}
Tempreites.render(template, data)

Binding values

Use a class or an id at the target element with the value of the key in your data object.

<h1 class="name"></h1>

Nested objects

Use a class or an id at some element with the value of the parent key in your data object, then use a class or id with the child key anywhere inside the parent element.

<div id="name">
  <h1>
    <span class="last"></span>, <span class="first"></span></h1>
  </h1>
</div>

Nested lists

Use a class or an id at the element immediattely before the element you want to be repeated with the list values, then use a class or id with the child key anywhere inside it.

<div id="sons">
  <p class="name"></p>
</div>

Binding values to attributes

Use the data-bind attribute with the special syntax "javascriptObjectAttrName - > htmlElementAttrNameToBindTo". If you want to bind to more than one attr, write the other bindings at the same data-bind, separated by a |:

<header>
  <h1 id="name"></h1>
  <img data-bind="url -> src | name -> alt">
</header>

Conditional showing of elements

Use the data-show-if attr naming a key at the data object which will be tested for deciding if the element will be shown or not.

<div id="miyamoto" data-show-if="show">
  <ul class="sons">
    <li class="name" data-show-if="show"></li>
  </ul>
</div>

Pre-compiling templates

Call the compile function to get a pre-compiled template to which you can just pass the data later.

var tpr = Tempreites.compile('<div class="u"></div>')
tpr.render({u: 'a'})
tpr.render({u: 'b'})

Inspired by Plates and Transparency, but simplified and more useful.


Written with regular expressions, como se fazia antigamente lá na roça.