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

dynamic-inset

v0.2.2

Published

A node.js render for the Dynamic Inset specification.

Downloads

4

Readme

#Dynamic Inset Renderer for Node.js ##Server-side inset.json rendering

Based on the dynamic inset renderer, this library implements the most basic aspects of the inset.json spec.

###Installation

npm install dynamic-inset

###Requirements Dynamic insets require a discoverable inset.json file (that conforms to the inset.json spec). The inset should have either additional discoverable assets, or in-line data and/or templates to use to create the rendered inset.

The default renderer for insets is hogan, but the advanced example in this documentation shows how the rendering engine can be swapped out for another mustache renderer, or a different templating syntax entirely.

###Usage

//include the module
var inset = require('dynamic-inset');

//request the inset
inset.render("http://dynamic-inset-assets.herokuapp.com/inset/inset.json", function(err, results){
  //do something with the inset
  console.log(results.compiled_inset);
});

The result of results.compiled_inset is a fully-rendered string of html code, ready to be inserted into a document. The results object is a collection of the responses to each step of the async processing on the various parts of the inset processing steps:

###results.compiled_inset

<h1>First Inset</h1>
<p>The content of this inset is from a json file. and the template is from a mustache file.</p>
<ul>
  <li>dog</li>
  <li>cat</li>
  <li>goat</li>
</ul>

###The complete results object

{
  inset_file: {
    status: 'OK',
    type: 'InsetDynamic',
    platforms: [ 'desktop' ],
    serverside: { data: [Object], template: [Object] },
    sharing: false
  },
  inset_template: '<h1>{{title}}</h1>\n<p>{{importantstuff}}</p>\n{{#list.length}}\n<ul>\n{{#list}}<li>{{.}}</li>{{/list}}\n</ul>{{/list.length}}\n',
  inset_data: {
    title: 'First Inset',
    list: [ 'dog', 'cat', 'goat' ],
    importantstuff: 'The content of this inset is from a json file. and the template is from a mustache file.'
  },
  compiled_inset: '<h1>First Inset</h1>\n<p>The content of this inset is from a json file. and the template is from a mustache file.</p>\n<ul>\n<li>dog</li><li>cat</li><li>goat</li>\n</ul>\n' },
  status:'OK'
}

###Alternate usage The inset object's url property can be set manually before execution, as a convenience.

//include the module
var inset = require('dynamic-inset');

//set the url
inset.url = 'http://dynamic-inset-assets.herokuapp.com/inset/inset.json';

//render, using only a function as a param
inset.render(function(err, results){
  console.log(results.compiled_inset);
});

###Inline inset usage A string of an inset can be passed to the renderer to render directly.

var insetString = JSON.stringify({
  "status": "OK",
  "type": "InsetDynamic",
  "platforms": ["desktop"],
  "serverside": {
    "data": {
      "data":{"title":"hello"}
    },
    "template": {
      "template": "<h1>{{title}}</h1>"
    }
  }
});

inset.render(insetString, function(err, results){
  console.log(results.compiled_inset);
});

###Status Insets can be remotely disabled via the status property in the specification. The inset.json file's status is bubbled up to the top-level of the object for easy discovery and testing.

//set the url
inset.url = 'http://dynamic-inset-assets.herokuapp.com/inset/inset.json';

inset.render(function(err, results){
  if(results.status == 'OK') {
    //process the inset because it is ok
  } else {
    //ignore the inset, as it has been disabled remotely.
  }
});

###Advanced use-cases Individual functions can be overloaded with alternatives. In this example, hogan is swapped out for the standard mustache renderer.

var inset = require('dynamic-inset')
  , mustache = require('mustache');

//overload the compile function with an alternate renderer
inset.compile = function(callback, results) {
  callback(null, mustache.render(results.inset_template, results.inset_data);
}

//request the inset
inset.render("http://dynamic-inset-assets.herokuapp.com/inset/inset.json", function(err, results){
  //output will be rendered with mustache, instead of hogan
  console.log(results.compiled_inset);
});