Compare commits
No commits in common. "master" and "v2.0.1" have entirely different histories.
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,20 +1,6 @@
|
|||||||
.nogit/
|
node_modules/
|
||||||
|
|
||||||
# artifacts
|
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
test/testresult/
|
||||||
# installs
|
.nogit/
|
||||||
node_modules/
|
|
||||||
|
|
||||||
# caches
|
|
||||||
.yarn/
|
|
||||||
.cache/
|
|
||||||
.rpt2_cache
|
|
||||||
|
|
||||||
# builds
|
|
||||||
dist/
|
|
||||||
dist_*/
|
|
||||||
|
|
||||||
# custom
|
|
||||||
|
142
.gitlab-ci.yml
Normal file
142
.gitlab-ci.yml
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- security
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
- metadata
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
snyk:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install legacy
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g typedoc typescript
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
windowsCompatibility:
|
||||||
|
image: stefanscherer/node-windows:10-build-tools
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npm install & npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- windows
|
||||||
|
allow_failure: true
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"command": "npm test",
|
|
||||||
"name": "Run npm test",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node-terminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"json.schemas": [
|
|
||||||
{
|
|
||||||
"fileMatch": ["/npmextra.json"],
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"npmci": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for npmci"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for gitzone",
|
|
||||||
"properties": {
|
|
||||||
"projectType": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
47
README.md
Normal file
47
README.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# smarthbs
|
||||||
|
|
||||||
|
handlebars with better fs support
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/smarthbs)
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs)
|
||||||
|
[](https://github.com/pushrocks/smarthbs)
|
||||||
|
[](https://pushrocks.gitlab.io/smarthbs/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smarthbs)
|
||||||
|
[](https://david-dm.org/pushrocks/smarthbs)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smarthbs/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smarthbs)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> 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.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import * as smarthbs from 'smarthbs';
|
||||||
|
|
||||||
|
// read all .hbs files in a directory and any child directories and use relative path as partial string identifier
|
||||||
|
smarthbs.registerPartialDir(testPartialDir);
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
```
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
50
changelog.md
50
changelog.md
@ -1,50 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## 2025-01-25 - 3.0.4 - fix(metadata)
|
|
||||||
Removed CI configuration file .gitlab-ci.yml and updated project metadata
|
|
||||||
|
|
||||||
- Deleted the .gitlab-ci.yml file to potentially switch or update CI/CD configurations.
|
|
||||||
- Updated the `description` and `keywords` in package.json and npmextra.json for better project documentation and SEO.
|
|
||||||
|
|
||||||
## 2024-04-01 to 2024-05-29 - 3.0.3 - maintenance
|
|
||||||
Maintenance updates and minor configuration changes.
|
|
||||||
|
|
||||||
- Updated the project description.
|
|
||||||
- Updated TypeScript configuration (`tsconfig`).
|
|
||||||
- Modified `npmextra.json` file for `githost`.
|
|
||||||
|
|
||||||
## 2023-06-25 to 2023-07-10 - 3.0.3 - organization
|
|
||||||
Organizational changes and fixes in core components.
|
|
||||||
|
|
||||||
- Transitioned to a new organization scheme.
|
|
||||||
|
|
||||||
## 2023-03-06 to 2023-06-25 - 3.0.1 to 3.0.2 - fixes
|
|
||||||
Core updates and critical fixes.
|
|
||||||
|
|
||||||
- Updated core components with fixes.
|
|
||||||
|
|
||||||
## 2022-07-24 - 2.0.9 - breaking change
|
|
||||||
Significant shifts in module support.
|
|
||||||
|
|
||||||
- **BREAKING CHANGE**: Switched to ECMAScript Module (ESM) format.
|
|
||||||
|
|
||||||
## 2018-08-27 - 1.0.16 - breaking change
|
|
||||||
Major updates in project scope.
|
|
||||||
|
|
||||||
- **BREAKING CHANGE**: Updated project scope to `@pushrocks`.
|
|
||||||
|
|
||||||
## 2017-05-26 - 1.0.15 - functionality
|
|
||||||
Enhancements in processing capabilities.
|
|
||||||
|
|
||||||
- Added post-processing functionality.
|
|
||||||
|
|
||||||
## 2017-05-12 - 1.0.13 - documentation improvements
|
|
||||||
Enhanced documentation.
|
|
||||||
|
|
||||||
- Added new documentation materials.
|
|
||||||
|
|
||||||
## 2017-05-01 - 1.0.8 - variable handling
|
|
||||||
Improvements in variable utilization.
|
|
||||||
|
|
||||||
- Introduced extended variable checking capabilities.
|
|
||||||
|
|
47
docs/index.md
Normal file
47
docs/index.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# smarthbs
|
||||||
|
|
||||||
|
handlebars with better fs support
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/smarthbs)
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs)
|
||||||
|
[](https://github.com/pushrocks/smarthbs)
|
||||||
|
[](https://pushrocks.gitlab.io/smarthbs/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smarthbs/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smarthbs)
|
||||||
|
[](https://david-dm.org/pushrocks/smarthbs)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smarthbs/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smarthbs)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> 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.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import * as smarthbs from 'smarthbs';
|
||||||
|
|
||||||
|
// read all .hbs files in a directory and any child directories and use relative path as partial string identifier
|
||||||
|
smarthbs.registerPartialDir(testPartialDir);
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
```
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
@ -2,33 +2,5 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"projectType": "npm",
|
|
||||||
"module": {
|
|
||||||
"githost": "code.foss.global",
|
|
||||||
"gitscope": "push.rocks",
|
|
||||||
"gitrepo": "smarthbs",
|
|
||||||
"description": "Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.",
|
|
||||||
"npmPackagename": "@push.rocks/smarthbs",
|
|
||||||
"license": "MIT",
|
|
||||||
"keywords": [
|
|
||||||
"handlebars",
|
|
||||||
"template engine",
|
|
||||||
"file system",
|
|
||||||
"partials",
|
|
||||||
"template compilation",
|
|
||||||
"smarthbs",
|
|
||||||
"smartfile integration",
|
|
||||||
"template variables analysis",
|
|
||||||
"dynamic content",
|
|
||||||
"code generation",
|
|
||||||
"typescript",
|
|
||||||
"project management"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
1423
package-lock.json
generated
Normal file
1423
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
66
package.json
66
package.json
@ -1,65 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smarthbs",
|
"name": "@pushrocks/smarthbs",
|
||||||
"version": "3.0.4",
|
"version": "2.0.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.",
|
"description": "handlebars with better fs support",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --allowimplicitany)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/smarthbs.git"
|
"url": "git+ssh://git@gitlab.com/pkunz/smarthbs.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"handlebars",
|
"handlebars"
|
||||||
"template engine",
|
|
||||||
"file system",
|
|
||||||
"partials",
|
|
||||||
"template compilation",
|
|
||||||
"smarthbs",
|
|
||||||
"smartfile integration",
|
|
||||||
"template variables analysis",
|
|
||||||
"dynamic content",
|
|
||||||
"code generation",
|
|
||||||
"typescript",
|
|
||||||
"project management"
|
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pkunz/smarthbs/issues"
|
"url": "https://gitlab.com/pkunz/smarthbs/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smarthbs",
|
"homepage": "https://gitlab.com/pkunz/smarthbs#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^10.0.17",
|
"@pushrocks/smartfile": "^6.0.12",
|
||||||
"@pushrocks/smartpath": "^5.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@pushrocks/smartpromise": "^4.0.2",
|
"@types/lodash": "^4.14.121",
|
||||||
"handlebars": "^4.7.7"
|
"handlebars": "^4.1.0",
|
||||||
|
"lodash": "^4.17.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@gitzone/tsbuild": "^2.1.8",
|
||||||
"@gitzone/tsrun": "^1.2.42",
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
"@pushrocks/tapbundle": "^5.0.8",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^20.3.1"
|
"@types/node": "^11.9.4"
|
||||||
},
|
}
|
||||||
"files": [
|
|
||||||
"ts/**/*",
|
|
||||||
"ts_web/**/*",
|
|
||||||
"dist/**/*",
|
|
||||||
"dist_*/**/*",
|
|
||||||
"dist_ts/**/*",
|
|
||||||
"dist_ts_web/**/*",
|
|
||||||
"assets/**/*",
|
|
||||||
"cli.js",
|
|
||||||
"npmextra.json",
|
|
||||||
"readme.md"
|
|
||||||
],
|
|
||||||
"browserslist": [
|
|
||||||
"last 1 chrome versions"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
4457
pnpm-lock.yaml
generated
4457
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
|
|
188
readme.md
188
readme.md
@ -1,188 +0,0 @@
|
|||||||
# @push.rocks/smarthbs
|
|
||||||
|
|
||||||
A library that enhances handlebars with better file system support, templates compilation, and partials registration.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
To install `@push.rocks/smarthbs`, run the following command in your terminal:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install @push.rocks/smarthbs --save
|
|
||||||
```
|
|
||||||
|
|
||||||
This will add `@push.rocks/smarthbs` as a dependency to your project, allowing you to leverage its enhanced Handlebars templating capabilities.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The `@push.rocks/smarthbs` library extends Handlebars functionality by introducing better file system interaction, template compilation, and an easier way to manage partials. The following sections walk you through the various features and how you can utilize them for creating dynamic and organized templates.
|
|
||||||
|
|
||||||
### Getting Started
|
|
||||||
|
|
||||||
First, import the `@push.rocks/smarthbs` module using ECMAScript Module (ESM) syntax in a TypeScript file:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import * as smarthbs from '@push.rocks/smarthbs';
|
|
||||||
```
|
|
||||||
|
|
||||||
### Managing Partials
|
|
||||||
|
|
||||||
Handlebars' partials allow for embedding templates within other templates, making it simple to manage reusable pieces of template code. With `@push.rocks/smarthbs`, you can efficiently register an entire directory of partials.
|
|
||||||
|
|
||||||
#### Registering a Directory of Partials
|
|
||||||
|
|
||||||
To register all `.hbs` files in a directory, including those in subdirectories, as partials:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
await smarthbs.registerPartialDir('./path/to/partials');
|
|
||||||
```
|
|
||||||
|
|
||||||
Each `.hbs` file in the specified directory becomes available as a partial. Partials are identified by their paths relative to the specified directory.
|
|
||||||
|
|
||||||
### Compiling Templates
|
|
||||||
|
|
||||||
Compiling directories of Handlebars templates is seamless with `@push.rocks/smarthbs`. This feature reads templates from a source directory, compiles them using a specified data context, and writes the rendered output to a destination directory.
|
|
||||||
|
|
||||||
#### Compile a Directory
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
await smarthbs.compileDirectory('./source/templates', './destination/html', 'data.json');
|
|
||||||
```
|
|
||||||
|
|
||||||
Here, every `.hbs` file in `./source/templates` is compiled with data from `data.json`. The rendered outputs are saved as `.html` files in `./destination/html`.
|
|
||||||
|
|
||||||
### Working with Variables
|
|
||||||
|
|
||||||
When handling complex templates, you might want to analyze which variables are used, verify their satisfaction, and ensure data completeness.
|
|
||||||
|
|
||||||
#### Finding Variables in Templates
|
|
||||||
|
|
||||||
To extract all variables used within a Handlebars template string:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const templateVariables = await smarthbs.findVarsInHbsString("Your template {{example}} here.");
|
|
||||||
console.log(templateVariables); // Outputs an array of variable names: ['example']
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Ensuring Variables Satisfaction
|
|
||||||
|
|
||||||
To check if a given data object satisfies all required variables in a template:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const missingVars = await smarthbs.checkVarsSatisfaction("Your template {{example}} here.", { anotherVar: "some value" });
|
|
||||||
if(missingVars.length) {
|
|
||||||
console.error('Missing variables:', missingVars);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This function ensures the provided data object contains all variables used in the template. Otherwise, it returns an array with the names of the missing variables.
|
|
||||||
|
|
||||||
### Rendering Templates
|
|
||||||
|
|
||||||
You can use `@push.rocks/smarthbs` to compile Handlebars templates directly from strings or files:
|
|
||||||
|
|
||||||
#### From a String
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const stringTemplate = await smarthbs.getTemplateForString("Hello, {{name}}!");
|
|
||||||
const renderedString = stringTemplate({ name: "World" });
|
|
||||||
console.log(renderedString); // "Hello, World!"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### From a File
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const fileTemplate = await smarthbs.getTemplateForFile('./path/to/template.hbs');
|
|
||||||
const renderedFileString = fileTemplate({ key: "value" });
|
|
||||||
console.log(renderedFileString); // Outputs the processed template with provided data
|
|
||||||
```
|
|
||||||
|
|
||||||
### Ensuring Safe Syntax
|
|
||||||
|
|
||||||
If your Handlebars templates go through multiple processing stages, you might need to protect and restore the syntax:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const processedString = await smarthbs.postprocess("This is {-{safe}-} syntax.");
|
|
||||||
console.log(processedString); // Restores to "This is {{safe}} syntax."
|
|
||||||
```
|
|
||||||
|
|
||||||
This approach allows you to keep placeholders intact during various stages, converting `{-{ ... }-}` syntax back to `{{ ... }}`.
|
|
||||||
|
|
||||||
### Advanced Features and Helpers
|
|
||||||
|
|
||||||
#### Custom Helpers
|
|
||||||
|
|
||||||
Extend Handlebars with custom helpers to introduce new functionalities or debug existing templates. For instance:
|
|
||||||
|
|
||||||
- **Analyze Helper**: Displays partials and their details.
|
|
||||||
- **Log Registered Partials**: Logs all registered partials, aiding in debugging.
|
|
||||||
- **Runtime Compilation**: Compile templates dynamically using the `__compile` helper.
|
|
||||||
|
|
||||||
### Example: Building an HTML Page
|
|
||||||
|
|
||||||
Suppose you are building a simple HTML page. First, define a partial for the header and a general layout:
|
|
||||||
|
|
||||||
Create a new header partial:
|
|
||||||
|
|
||||||
```hbs
|
|
||||||
<!-- ./partials/header.hbs -->
|
|
||||||
<header>
|
|
||||||
<h1>{{title}}</h1>
|
|
||||||
</header>
|
|
||||||
```
|
|
||||||
|
|
||||||
Define a base layout that includes the header and a body:
|
|
||||||
|
|
||||||
```hbs
|
|
||||||
<!-- ./layouts/main.hbs -->
|
|
||||||
{{> header title=pageTitle}}
|
|
||||||
<section>
|
|
||||||
<h2>{{subtitle}}</h2>
|
|
||||||
<p>{{content}}</p>
|
|
||||||
</section>
|
|
||||||
```
|
|
||||||
|
|
||||||
In your script, register partials and compile the layout:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import * as smarthbs from '@push.rocks/smarthbs';
|
|
||||||
|
|
||||||
// Register partials
|
|
||||||
await smarthbs.registerPartialDir('./partials');
|
|
||||||
|
|
||||||
// Prepare data for compilation
|
|
||||||
const data = {
|
|
||||||
pageTitle: "My Awesome Page",
|
|
||||||
subtitle: "Welcome to the world of dynamic templates!",
|
|
||||||
content: "Handlebars makes creating reusable templates easy."
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compile and render the layout
|
|
||||||
const mainTemplate = await smarthbs.getTemplateForFile('./layouts/main.hbs');
|
|
||||||
const renderedHtml = mainTemplate(data);
|
|
||||||
|
|
||||||
console.log(renderedHtml);
|
|
||||||
// Outputs the full HTML replacing variables in the layout with data
|
|
||||||
```
|
|
||||||
|
|
||||||
### Conclusion
|
|
||||||
|
|
||||||
The `@push.rocks/smarthbs` library enhances the already powerful Handlebars templating engine with capabilities that are crucial for modern development workflows, especially those involving complex template management and dynamic content generation. Whether managing large-scale projects with numerous reusable components or simply wanting a better way to handle templates and partials, this tool provides a robust solution to enhance your projects and improve productivity.
|
|
||||||
|
|
||||||
## 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.
|
|
30
test/test.ts
30
test/test.ts
@ -1,28 +1,24 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smarthbs from '../ts/index.js';
|
import * as smarthbs from '../ts/index';
|
||||||
|
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
let testHbsDir = path.join(__dirname, 'hbs_testfiles');
|
||||||
|
let testPartialDir = path.join(testHbsDir, 'partials');
|
||||||
let hbs_testfilesDir = path.join(dirname, 'hbs_testfiles');
|
let testResultDir = path.join(__dirname, 'testresult');
|
||||||
let testPartialDir = path.join(hbs_testfilesDir, 'partials');
|
|
||||||
let testResultDir = path.join(dirname, 'testresult');
|
|
||||||
|
|
||||||
tap.test('smarthbs -> should create partials', async () => {
|
tap.test('smarthbs -> should create partials', async () => {
|
||||||
await smarthbs.registerPartialDir(testPartialDir);
|
await smarthbs.registerPartialDir(testPartialDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('smarthbs -> should compile a directory', async () => {
|
tap.test('smarthbs -> should compile a directory', async () => {
|
||||||
smarthbs.compileDirectory(hbs_testfilesDir, testResultDir, 'data.json');
|
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('', async () => {
|
tap.test('', async () => {
|
||||||
let templateString = '{{{firstVar}}} {{secondVar}}';
|
let templateString = '{{{firstVar}}} {{secondVar}}';
|
||||||
let templateVars = await smarthbs.findVarsInHbsString(templateString);
|
let templateVars = await smarthbs.findVarsInHbsString(templateString);
|
||||||
expect(templateVars).toContain('firstVar');
|
expect(templateVars).to.include('firstVar');
|
||||||
expect(templateVars).toContain('secondVar');
|
expect(templateVars).to.include('secondVar');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('', async () => {
|
tap.test('', async () => {
|
||||||
@ -33,14 +29,12 @@ tap.test('', async () => {
|
|||||||
secondVar: 'hello',
|
secondVar: 'hello',
|
||||||
fourthVar: {
|
fourthVar: {
|
||||||
otherKey: {
|
otherKey: {
|
||||||
nextKey: 'wow',
|
nextKey: 'wow'
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
expect(missingVars).toContain('thirdVar');
|
expect(missingVars).to.contain('thirdVar', 'fourthVar.someKey');
|
||||||
expect(missingVars).toContain('fourthVar.someKey');
|
expect(missingVars).to.not.contain('secondVar', 'fourthVar.otherKey.nextKey');
|
||||||
expect(missingVars).not.toContain('secondVar');
|
|
||||||
expect(missingVars).not.toContain('fourthVar.otherKey.nextKey');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<head></head>analyzed
|
|
@ -1 +0,0 @@
|
|||||||
A second hbs file!
|
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
|
||||||
*/
|
|
||||||
export const commitinfo = {
|
|
||||||
name: '@push.rocks/smarthbs',
|
|
||||||
version: '3.0.4',
|
|
||||||
description: 'Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.'
|
|
||||||
}
|
|
14
ts/index.ts
14
ts/index.ts
@ -1,10 +1,10 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
export type TTemplateStringType = 'filePath' | 'code';
|
export type TTemplateStringType = 'filePath' | 'code';
|
||||||
|
|
||||||
export let handlebars = plugins.handlebars;
|
export let handlebars = plugins.handlebars;
|
||||||
export * from './smarthbs.compile.js';
|
export * from './smarthbs.compile';
|
||||||
import './smarthbs.helpers.js';
|
import './smarthbs.helpers';
|
||||||
export * from './smarthbs.partials.js';
|
export * from './smarthbs.partials';
|
||||||
export * from './smarthbs.template.js';
|
export * from './smarthbs.template';
|
||||||
export * from './smarthbs.variables.js';
|
export * from './smarthbs.variables';
|
||||||
export * from './smarthbs.postprocess.js';
|
export * from './smarthbs.postprocess';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compiles a directory and outputs it
|
* compiles a directory and outputs it
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper:
|
* Helper:
|
||||||
* Allows you to analyze a context
|
* Allows you to analyze a context
|
||||||
*/
|
*/
|
||||||
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
|
plugins.handlebars.registerHelper('__analyze', analyzeContext => {
|
||||||
if (typeof analyzeContext === 'string') {
|
if (typeof analyzeContext === 'string') {
|
||||||
if (plugins.handlebars.partials[analyzeContext]) {
|
if (plugins.handlebars.partials[analyzeContext]) {
|
||||||
console.log(`The analyzed partial ${analyzeContext} looks like this`);
|
console.log(`The analyzed partial ${analyzeContext} looks like this`);
|
||||||
@ -20,7 +20,7 @@ plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
|
|||||||
* Helper:
|
* Helper:
|
||||||
* logs all registered partials to console
|
* logs all registered partials to console
|
||||||
*/
|
*/
|
||||||
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
|
plugins.handlebars.registerHelper('__allPartialsLog', analyzeContext => {
|
||||||
console.log(plugins.handlebars.partials);
|
console.log(plugins.handlebars.partials);
|
||||||
return 'analyzed';
|
return 'analyzed';
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registers a directory of partials to make them available within handlebars compilation
|
* registers a directory of partials to make them available within handlebars compilation
|
||||||
*/
|
*/
|
||||||
export let registerPartialDir = (dirPathArg: string): Promise<any> => {
|
export let registerPartialDir = (dirPathArg: string): Promise<any> => {
|
||||||
let done = plugins.smartpromise.defer();
|
let done = plugins.smartpromise.defer();
|
||||||
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then((hbsFileArrayArg) => {
|
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
|
||||||
for (let hbsFilePath of hbsFileArrayArg) {
|
for (let hbsFilePath of hbsFileArrayArg) {
|
||||||
let parsedPath = plugins.path.parse(hbsFilePath);
|
let parsedPath = plugins.path.parse(hbsFilePath);
|
||||||
let hbsFileString = plugins.smartfile.fs.toStringSync(
|
let hbsFileString = plugins.smartfile.fs.toStringSync(
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
// node native
|
import * as handlebars from 'handlebars';
|
||||||
|
import * as lodash from 'lodash';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export { path };
|
|
||||||
|
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export { smartpath, smartfile, smartpromise };
|
export { handlebars, lodash, path, smartfile, smartpromise };
|
||||||
|
|
||||||
// third party
|
|
||||||
import handlebars from 'handlebars';
|
|
||||||
|
|
||||||
export { handlebars };
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
let safeSyntaxBeginRegex = /{-{/g;
|
let safeSyntaxBeginRegex = /{-{/g;
|
||||||
let safeSyntaxEndRegex = /}-}/g;
|
let safeSyntaxEndRegex = /}-}/g;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a template for a file on disk
|
* get a template for a file on disk
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// This file contains code that makes it easy to search handlebar templates for variables.
|
// This file contains code that makes it easy to search handlebar templates for variables.
|
||||||
// Why? To get a clue if you are missing some.
|
// Why? To get a clue if you are missing some.
|
||||||
|
|
||||||
import * as plugins from './smarthbs.plugins.js';
|
import * as plugins from './smarthbs.plugins';
|
||||||
|
|
||||||
// the curly regex objects
|
// the curly regex objects
|
||||||
let tripleCurlyRegex = /{{{\s*[\w\.]+\s*}}}/g;
|
let tripleCurlyRegex = /{{{\s*[\w\.]+\s*}}}/g;
|
||||||
@ -18,23 +18,20 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
|
|||||||
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex);
|
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex);
|
||||||
if (tripleCurlyMatches) {
|
if (tripleCurlyMatches) {
|
||||||
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]');
|
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]');
|
||||||
varNameArray = varNameArray.concat(tripleCurlyMatches);
|
varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches);
|
||||||
}
|
}
|
||||||
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex);
|
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex);
|
||||||
if (doubleCurlyMatches) {
|
if (doubleCurlyMatches) {
|
||||||
varNameArray = varNameArray.concat(doubleCurlyMatches);
|
varNameArray = plugins.lodash.concat(varNameArray, doubleCurlyMatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we are clean from curly brackets
|
// make sure we are clean from curly brackets
|
||||||
varNameArray = varNameArray.map((x) => {
|
varNameArray = varNameArray.map(x => {
|
||||||
return x.match(nameInCurlsRegex)[0];
|
return x.match(nameInCurlsRegex)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
// make sure are uniq
|
// make sure are uniq
|
||||||
function uniqueArray(input: string[]): string[] {
|
varNameArray = plugins.lodash.uniq(varNameArray);
|
||||||
return Array.from(new Set(input));
|
|
||||||
}
|
|
||||||
varNameArray = uniqueArray(varNameArray);
|
|
||||||
return varNameArray;
|
return varNameArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"useDefineForClassFields": false,
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"verbatimModuleSyntax": true
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user