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

ejs-multifiles

v1.0.6

Published

Embedded JavaScript that accepts multiple file output.

Downloads

4

Readme

ejs-multifiles

Render multiple files from one EJS template.

Index

Installation

npm install ejs-multifiles

The Github project is found at https://github.com/allnulled/ejs-multifiles.

The NPM package is found at https://www.npmjs.com/package/ejs-multifiles.

Syntax

The syntax to follow is the same as ejs but intercepting the file-splitter-syntax.

For example:

<%
const user = "Carl";
const age = 33;
%>
<## index.js ##>
console.log("Hello, <%-user%>!");
console.log("I know you are <%-age%>");

<## package.json ##>
{}

<## mkdir src ##>

Carpeta para ficheros fuente.

<## mkdir test ##>

Carpeta para ficheros de test.

<## mkdir dist ##>

Carpeta para ficheros de distribución.

As you can see, we define in default.txt file (the default file of every template) some variables.

Later, we use them to render that data from index.js.

After that, we render another file. It does not use any data, though.

You see? With EJS you can only render 1 file, and the logic of that file is born and ended at the same file. However, with ejs-multifiles you can break this pattern, and enjoy templates logic across multiple files.

Usage

The test verses as follows:

const fs = require("fs");
const emf = require("ejs-multifiles");
const contents = fs.readFileSync(__dirname + "/examples/project1.emf").toString();

const main = async function() {
    try {
        await emf.render(contents, {}, { basedir: __dirname + "/examples/project1" });
        await emf.renderFile(__dirname + "/examples/project2.emf", {}, {});
    } catch (error) {
        console.log(error);
    }
};

main();

In it, we demonstrate the 2 ways of using this library:

  • by render function
  • by renderFile function

Both return a Promise as any asynchronous function.

The first function, render, receives:

  • template, the text.
  • parameters, the parameters.
  • configurations, the configurations of the templates.

The second function, renderFile, receives:

  • file, the file to render.
  • parameters, the parameters.
  • configurations, the configurations of the templates.

In order to distinguish this kind of template files, I set the extension emf to every template file. However, this is not mandatory in any way.

Command-line utility

This is how it works, pretty easy:

emf file1.emf file2.emf file3.emf

The rendered file can produce undetermined number of files by itself. So this acts as a uncompresser of files and projects with its limitations, but moreover enabling variables and code.