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

jext

v0.4.3

Published

Javascript ex DOM templater

Downloads

146

Readme

JEXT - Javascript ex DOM templater

JEXT is tool for using html templates as JS files with DOM rendered elements and special helper to manipulate real time data updates.

Installing

To install JEXT you have to just run npm in your project dir:

npm install jext ---save-dev

Usage

Sample usage with bin tool

You have test.html example template. To build it just use jext bin tool:

./bin/jext examples/simple.jext > templates.js

Now merge jext.js lib with generated template

cat ./jext.js templates.js > bundle.js

Well you can do same as above with one command:

./bin/jext examples/simple.jext -b > bundle.js

Finally require in browser just created the bundle.js file. You got jext variable defined with template pool manipulation helpers and templates variable with your template.

Now just get rendered DOM and append to any element. The key of template same as file name without extension.

var t = templates.get('simple');
document.body.appendChild(t.dom());

Wanna update some parameters? Easy:

t.update({welcome_text: 'JEXT works!'});

Now you can see rendered test template on your screen.

Usage with webpack or whatever

First install loader for webpack. Instruction read here: (https://www.npmjs.com/package/jext-loader).

Install stuff:

npm install jext
npm install jext-loader

Somewhere in your code write to render

# First require dependencies
var jext = require('jext');
var simple_tpl = require('examples/simple.jext');

# Make pool of templates, really only one now
var pool = jext.pool(simple_tpl);

# Fetch template and render
var t = pool.get('simple')
document.body.appendChild(t.dom());
t.update({welcome_text: 'JEXT works!'});

Build your project and enjoy!

Template markup

You can use only simple constructs in your html template.

Variables

Just use {{ var_name }} in attribute or inside element to make it works.

<div title="{{ title }}">{{ body }}</div>

Iteration

When making iteration inside template JEXT switching context inside iterated object. So only possible to access object variables of current iterated item.

  {
    "rows": [
      {"value": 1},
      {"value": 2}
    ]
  }
<div for="rows">
  The value is: {{ value }}
</div>

You know what will be as result? :)

Condition

Condition switches context as iteration. Its same easy to use.

  {
    "first": false,
    "second": {
      "value": 2
    }
  }
  <div if="first">
    First block wont appear here
  </div>
  <div if="second">
    In context of second condition: {{ value }}
  </div>

Template pool methods

get(template, data)

Return template object from pool of available templates using the template key.

  • template - name of template. If your template name as mytemplate.jext it must be mytemplate (without extension).
  • data - optional. Pass data to render your template as object.

release(template, instance)

It releases generate template from DOM tree

  • template - name of template.
  • instance - generated Node of this template.

Template object methods

When you get template from created pool, it has several methods to manipulate it.

dom()

The method returns generated DOM tree for current template as DocumentFragment (see document.createDocumentFragment).

update(data)

  • data - object to update and rerender current loaded template's DOM.

remove()

This method removes rendered element from DOM tree.

Loaders for JEXT

Webpack: (https://www.npmjs.com/package/jext-loader).