update tsconfig

This commit is contained in:
Philipp Kunz 2024-04-14 17:41:26 +02:00
parent 1ba2fcbf65
commit d98323eb82
4 changed files with 136 additions and 40 deletions

View File

@ -9,12 +9,23 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smarthbs",
"description": "handlebars with better fs support",
"description": "A library that enhances handlebars with better file system support, templates compilation, and partials registration.",
"npmPackagename": "@push.rocks/smarthbs",
"license": "MIT"
"license": "MIT",
"keywords": [
"handlebars",
"template engine",
"file system",
"partials",
"template compilation",
"smartfile integration",
"template variables analysis",
"code generation",
"dynamic content"
]
}
},
"tsdocs": {
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -2,7 +2,7 @@
"name": "@push.rocks/smarthbs",
"version": "3.0.3",
"private": false,
"description": "handlebars with better fs support",
"description": "A library that enhances handlebars with better file system support, templates compilation, and partials registration.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -15,7 +15,15 @@
"url": "git+ssh://git@gitlab.com/pkunz/smarthbs.git"
},
"keywords": [
"handlebars"
"handlebars",
"template engine",
"file system",
"partials",
"template compilation",
"smartfile integration",
"template variables analysis",
"code generation",
"dynamic content"
],
"author": "Lossless GmbH",
"license": "MIT",

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

146
readme.md
View File

@ -1,52 +1,128 @@
# @pushrocks/smarthbs
# @push.rocks/smarthbs
handlebars with better fs support
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarthbs)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarthbs)
* [github.com (source mirror)](https://github.com/pushrocks/smarthbs)
* [docs (typedoc)](https://pushrocks.gitlab.io/smarthbs/)
## Install
To install `@push.rocks/smarthbs`, run the following command in your terminal:
## Status for master
```bash
npm install @push.rocks/smarthbs --save
```
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smarthbs/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smarthbs/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smarthbs)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smarthbs)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smarthbs)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smarthbs)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smarthbs)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
This will add `@push.rocks/smarthbs` to your project's dependencies.
## Usage
> Note: Why did we decide against a class based architecture?
> Easy: handlebars.js is already pretty determined how things are handled internally, namely a global partial template registry
> It doesn't make sense to then introduce a scoped partial template approach.
The `@push.rocks/smarthbs` package enhances Handlebars with improved filesystem support, making it easy to manage partials and compile directories with template files. Below is a comprehensive guide to utilizing its capabilities in your project.
```javascript
import * as smarthbs from 'smarthbs';
### Getting Started
// read all .hbs files in a directory and any child directories and use relative path as partial string identifier
smarthbs.registerPartialDir(testPartialDir);
First, ensure you've imported `@push.rocks/smarthbs` using ECMAScript Module (ESM) syntax in TypeScript:
// read all .hbs files in a particular directory and level, output them to a destination and specify a .json file to read any referenced data
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
```typescript
import * as smarthbs from '@push.rocks/smarthbs';
```
### Registering Partials
## Contribution
In Handlebars, *partials* are reusable templates that can be included within other templates. `@push.rocks/smarthbs` simplifies the process of registering all partials from a directory, enabling a more organized template structure.
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
To register all `.hbs` files from a directory (and its subdirectories) as partials:
For further information read the linked docs at the top of this readme.
```typescript
await smarthbs.registerPartialDir(pathToPartialsDirectory);
```
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
**Example:**
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
```typescript
await smarthbs.registerPartialDir('./views/partials');
```
This automatically registers each `.hbs` file in the directory as a partial that can be referenced by its path relative to the specified directory.
### Compiling Templates
`@push.rocks/smarthbs` allows you to compile an entire directory of Handlebars template files, outputting the rendered HTML to a specified directory. You can also provide a `.json` file containing data to be used by all templates during compilation.
**Example:**
```typescript
await smarthbs.compileDirectory(sourceDirectory, destinationDirectory, 'data.json');
```
This reads all `.hbs` files in `sourceDirectory`, compiles them using the data from `data.json`, and writes the resulting HTML to `destinationDirectory`.
### Finding Variables in Templates
When working with complex templates, it might be useful to programmatically find all variables used within a template:
```typescript
let varsInTemplate = await smarthbs.findVarsInHbsString(templateString);
console.log(varsInTemplate); // Outputs an array of variable names used in the template
```
### Checking Variables Satisfaction
To ensure that the data provided to a template includes all necessary variables, you can compare a template against a data object:
```typescript
let missingVars = await smarthbs.checkVarsSatisfaction(templateString, dataObject);
if(missingVars.length > 0) {
console.error('Some required variables are missing:', missingVars);
}
```
This function returns an array of missing variable names, allowing you to validate data completeness before rendering.
### Templates and Strings
You can also get templates directly from strings or files on disk, which can then be rendered with context data:
```typescript
// From a string
let templateFromString = await smarthbs.getTemplateForString("Hello {{name}}!");
let resultString = templateFromString({ name: "World" });
console.log(resultString); // Outputs: Hello World!
// From a file
let templateFromFile = await smarthbs.getTemplateForFile("./templates/greeting.hbs");
let resultFileString = templateFromFile({ name: "File World" });
console.log(resultFileString); // Outputs the rendered content of greeting.hbs with provided data
```
### Post-processing: Safe Syntax
In scenarios where Handlebars syntax needs to be preserved during an intermediate step:
```typescript
let safeString = await smarthbs.postprocess(yourTemplateString);
```
This method converts safe syntax markers (e.g., `{-{` and `}-}`) back into standard Handlebars syntax (`{{` and `}}`), useful if your templates go through multiple processing steps.
### Advanced Usage and Helpers
`@push.rocks/smarthbs` also supports advanced use cases and custom helpers. For example, registering a helper to log all available partials or to perform runtime template compilation based on dynamic data.
### Conclusion
`@push.rocks/smarthbs` provides a robust set of features to enhance your Handlebars templating, making it easier to manage and render complex templates with external data sources and organized partials. Whether you're building web applications, generating email templates, or any task involving templating, `@push.rocks/smarthbs` can simplify and streamline your workflow.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.