0.1.14 • Published 3 months ago

@flownet/lib-render-templates-dir v0.1.14

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 months ago

@flownet/lib-render-templates-dir

The @flownet/lib-render-templates-dir library is a utility project. It's developed around the principles of ease of use and efficiency in rendering multiple Nunjucks template files. The code is written in JavaScript and uses the Node.js platform.

The main purpose of this code is to render a directory of Nunjucks template files (*.njk extension) into regular HTML or other relevant formats. It accepts a directory of templates, an output directory and a context object, which specifies the data to be used in rendering the templates.

Functionality

  • The code first checks the existence of both the template directory and output directory. If the given directories don’t exist, it throws an error message.
  • The program then lists all template files in the given directory, considering any file pattern, primarily paying attention to files with the .njk extension.
  • For each template file, the program compiles it with the specified context and renders it into a normal HTML or other applicable file format.
  • Concurrent to this, the code checks for the precondition of overwriting existing files. If the rendered file is already present in the output directory, and overwriting isn't permitted, the program skips to the next file.
  • It then proceeds to write the rendered file to the output directory, creating any necessary directories in the output path.

For added functionality, the script also supports copying non-matching files directly to the output directory. If copyUnmatchedAlso is set to true, the code identifies files that were not matched as templates and copies them to the output directory, again respecting the overwrite policy.

In summary, this library provides end-users with an efficient way to render a directory of Nunjucks templates into another format such as HTML or copy non-matching files to an alternative directory. It also respects overwrite permissions to prevent unsolicited loss of pre-existing data.