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

content-generator

v0.0.6

Published

Easy template generator to manage and save templates by key and languagecode.

Downloads

3

Readme

Content-Generator

Content-Generator is a module to handle different contents in a mongo-db.

Connection to MongoDB

This module use the mongodb-handler as sub-modul. To connect mongo-db please set follow ENV variables:

  • MDBHANDLER_CONSTRING: Defines the connectionstring to the database. Default is: 'mongodb://localhost:27017/mdbtest';

The module will store and handle all templates in collection CM_Templates. You can define your own Collection-Name with follow ENV Variable:

  • CTM_COLLECTION: Defines the name of the collection

Template Engine

This module use the great template engine where powered by mozilla.

You find the API Description here

PDF generator

  • HTML_PDF_OPTIONS: Defines the options for HTML-PDF

Usage Templatemanagement

Global Properties

This Template Manager is based in combination with the variables key and lang. All variables free to declare as string.

  • key: Defines the global key of a template
  • lang: Defines the language in combination to the key properties.

Create a template

To Create a new template use the function createTemplate:

const ctg = require('content-generator');

const obj = { html: '<div>Test</div>', lang: 'en_GB', subject: 'Test', key: 'TESTTEMPLATE' };

ctg.createTemplate(obj, (err) => {
  if (err) {
    throw err;
  }
});

Update a template

To update a template use the funciton updateTemplate:

const ctg = require('content-generator');

const obj = { html: '<div>Test</div>', lang: 'en_GB', subject: 'Test', key: 'TESTTEMPLATE' };

ctg.updateTemplate(obj, (err) => {
  if (err) {
    throw err;
  }
});

Delete a template

To delete a template use the function deleteTemplate:

const ctg = require('content-generator');

const obj = { lang: 'en_GB', key: 'TESTTEMPLATE' };

ctg.deleteTemplate(obj, (err) => {
  if (err) {
    throw err;
  }
});

Get a template

To get a template use the function getTemplate:

const ctg = require('content-generator');

const obj = { lang: 'en_GB', key: 'TESTTEMPLATE' };

ctg.getTemplate(obj, (err, template) => {
  if (err) {
    throw err;
  }

  console.log(template);
});

Get a Templateslist by key

To get a templatelist by key use the function getTemplatesByKey:

const ctg = require('content-generator');

ctg.getTemplate('TESTTEMPLATE', (err, templates) => {
  if (err) {
    throw err;
  }

  console.log(templates);
});

Get all templates from system

To get all templates from the system use the function getTemplatesList:

const ctg = require('content-generator');

ctg.getTemplatesList((err, templates) => {
  if (err) {
    throw err;
  }

  console.log(templates);
});

Usage Content Generator

Generate a html Content

This module will merge the variables from a JSON Object into the html-content:

JSON:

{
  name: {
    firstname: "Martin",
    lastname: "Wiesmüller"
  },
  address: {
    line1: "Werbas Innotec GmbH",
    line2: "Max-Eyth-Str. 42, 71088 Holzgerlingen"
  }
}

HTML:

<div>Name: {{ name.firstname }}</div>
<div>Lastname: {{ name.lastname }}</div>
<br>
<div>Adressline 1: {{ address.line1 }}</div>
<div>Adressline 2: {{ address.line2 }}</div>

TO =>

<div>Name: Martin</div>
<div>Lastname: Wiesmüller</div>
<br>
<div>Adressline 1: Werbas Innotec GmbH"</div>
<div>Adressline 2: Max-Eyth-Str. 42, 71088 Holzgerlingen</div>

Usage in Syntax:

const ctg = require('content-generator');

ctg.generateHtml(json, 'TESTTEMPLATE', 'en_GB', (err, res) => {
  if (err) {
    throw err;
  }

  // Output the html Content
  console.log(res.html);

  // Output the content as plain text
  console.log(res.plain);
});

Generate a PDF stream

To generate a PDF Stream use the function generatePdf:

const ctg = require('content-generator');

ctg.generatePdf(json, 'TESTTEMPLATE', 'en_GB', (err, res) => {
  if (err) {
    throw err;
  }

  // Output the html Content
  console.log(res.html);

  // Output the content as plain text
  console.log(res.plain);

  // Output the content as pdf stream
  res.stream.pipe(fs.createWriteStream('./foo.pdf'));
});