Compare commits

...

24 Commits

Author SHA1 Message Date
d10ec8d81f 2.0.8 2024-10-13 12:12:35 +02:00
ef65d08a54 fix(core): Updated dependencies and optimized code structure 2024-10-13 12:12:35 +02:00
8872a92193 update description 2024-05-29 14:15:06 +02:00
c9a324b9a6 2.0.7 2024-05-28 10:40:39 +02:00
caa1e60cf6 fix(core): update 2024-05-28 10:40:38 +02:00
7402967715 2.0.6 2024-05-28 00:42:20 +02:00
ef6f043a68 fix(core): update 2024-05-28 00:42:20 +02:00
39ca9c52ae 2.0.5 2024-05-28 00:28:34 +02:00
d7c3f035ec fix(core): update 2024-05-28 00:28:33 +02:00
48989c17c7 update tsconfig 2024-04-14 18:04:25 +02:00
46a70d55c5 update npmextra.json: githost 2024-04-01 21:36:58 +02:00
4e44ed81a5 update npmextra.json: githost 2024-04-01 19:59:08 +02:00
313538e48f update npmextra.json: githost 2024-03-30 21:48:07 +01:00
b64a819023 switch to new org scheme 2023-07-10 10:16:59 +02:00
a7281760ac 2.0.4 2023-05-01 14:02:26 +02:00
1c8fef7a07 fix(core): update 2023-05-01 14:02:25 +02:00
71396208ee 2.0.3 2023-05-01 13:03:55 +02:00
1dadeeb05a fix(core): update 2023-05-01 13:03:55 +02:00
0fd7ae74f8 2.0.2 2023-05-01 13:03:33 +02:00
9d6238618f fix(core): update 2023-05-01 13:03:32 +02:00
0dd10351ad 2.0.1 2023-03-30 11:19:13 +02:00
1d2b489830 fix(core): update 2023-03-30 11:19:12 +02:00
446c9d0f59 2.0.0 2023-03-30 11:08:30 +02:00
a689252f4b BREAKING CHANGE(improved the loading of the environment. Can now be used in sync environments.): update 2023-03-30 11:08:29 +02:00
15 changed files with 5558 additions and 17329 deletions

View File

@ -1,140 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

31
changelog.md Normal file
View File

@ -0,0 +1,31 @@
# Changelog
## 2024-10-13 - 2.0.8 - fix(core)
Updated dependencies and optimized code structure
- Upgraded '@git.zone/tsbuild', '@git.zone/tsrun', '@design.estate/dees-element', and '@happy-dom/global-registrator' packages to their latest versions.
- Removed 'why-is-node-running' from devDependencies as it is not used.
- Refactored Smartntml class to separate file for better module organization.
## 2024-05-28 - 2.0.4 to 2.0.7 - fix and maintenance updates
Minor updates and fixes to the core functionality.
- fixed various core updates
- updated description in version 2.0.7
## 2023-05-01 - 2.0.0 to 2.0.4 - updates and fixes
Introduction of new organization schemes and updates.
- switched to new organization scheme
- fixed core updates throughout versions
## 2023-03-30 - 1.0.12 to 2.0.0 - major and breaking changes
Significant version upgrade with breaking changes for environment handling.
- improved loading of the environment allowing use in synchronization environments
- fixed core updates in version 2.0.0
## 2022-05-28 - 1.0.1 to 1.0.12 - initial fixes
Initial series of updates focusing on core functionality improvements.
- fixed core updates consistently across versions

View File

@ -2,17 +2,31 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartntml",
"description": "lit-html for the backend",
"npmPackagename": "@pushrocks/smartntml",
"description": "Provides lit-html rendering capabilities for backend applications.",
"npmPackagename": "@push.rocks/smartntml",
"license": "MIT",
"projectDomain": "push.rocks"
"projectDomain": "push.rocks",
"keywords": [
"backend rendering",
"lit-html",
"template rendering",
"server-side rendering",
"html template",
"web components",
"happy-dom",
"indexeddb",
"typescript"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"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"
}
}

13821
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
{
"name": "@pushrocks/smartntml",
"version": "1.0.12",
"name": "@push.rocks/smartntml",
"version": "2.0.8",
"private": false,
"description": "lit-html for the backend",
"description": "Provides lit-html rendering capabilities for backend applications.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -10,20 +10,22 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsbundle": "^2.0.7",
"@gitzone/tstest": "^1.0.73",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.7.23",
"why-is-node-running": "^2.2.2"
"@git.zone/tsbuild": "^2.1.84",
"@git.zone/tsbundle": "^2.0.7",
"@git.zone/tsrun": "^1.2.49",
"@git.zone/tstest": "^1.0.73",
"@push.rocks/tapbundle": "^5.3.0",
"@types/node": "^22.7.5"
},
"dependencies": {
"@designestate/dees-element": "^2.0.20",
"@happy-dom/global-registrator": "^6.0.4",
"@pushrocks/smartpromise": "^3.1.7"
"@design.estate/dees-element": "^2.0.39",
"@happy-dom/global-registrator": "^15.7.4",
"@push.rocks/smartpromise": "^4.0.3",
"fake-indexeddb": "^6.0.0"
},
"browserslist": [
"last 1 chrome versions"
@ -39,5 +41,21 @@
"cli.js",
"npmextra.json",
"readme.md"
]
],
"keywords": [
"backend rendering",
"lit-html",
"template rendering",
"server-side rendering",
"html template",
"web components",
"happy-dom",
"indexeddb",
"typescript"
],
"homepage": "https://code.foss.global/push.rocks/smartntml",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartntml.git"
}
}

8563
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

143
readme.md
View File

@ -1,39 +1,128 @@
# @pushrocks/smartntml
# @push.rocks/smartntml
lit-html for the backend
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartntml)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartntml)
* [github.com (source mirror)](https://github.com/pushrocks/smartntml)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartntml/)
## Install
## Status for master
To install `@push.rocks/smartntml`, you need Node.js and npm installed on your machine. If you have them ready, open your terminal and run the following command:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartntml/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartntml/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartntml)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartntml)](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/smartntml)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartntml)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartntml)](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)
```bash
npm install @push.rocks/smartntml --save
```
This will add `@push.rocks/smartntml` as a dependency to your project and you're ready to use lit-html in your backend applications.
## Usage
Use TypeScript for best in class intellisense
The core idea behind `@push.rocks/smartntml` is to bring the convenience and developer experience of `lit-html` to server-side rendering. This package leverages the power of `lit-html`'s syntax and data-binding capabilities in a Node.js environment, especially focusing on backend applications that require rendering HTML.
## Contribution
To start using `@push.rocks/smartntml`, you need to familiarize yourself with TypeScript and ESM syntax, as this module is designed to offer the best experience within this ecosystem.
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). :)
### Setting Up Your Project with TypeScript and ESM
For further information read the linked docs at the top of this readme.
First and foremost, ensure your project is set up to use TypeScript and ECMAScript Modules (ESM). Your `tsconfig.json` should have the following settings:
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```json
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
```
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
### Basic Usage
`@push.rocks/smartntml` simplifies the process of creating and rendering templates. The following example demonstrates how to create a template and render it:
1. **Import the necessary modules**
First, import `Smartntml` and any other module you wish to use:
```typescript
import { Smartntml, deesElement } from '@push.rocks/smartntml';
```
`deesElement` is leveraged for its `TemplateResult` type and `html` tag function, allowing us to define our templates with ease.
2. **Create an instance of Smartntml**
```typescript
const smartNTML = new Smartntml();
```
3. **Define a Template**
You can define a template using the `html` function provided by `deesElement`. This function allows you to embed dynamic content in a concise and readable manner.
```typescript
const myTemplate = deesElement.html`
<div>Welcome to Smartntml!</div>
`;
```
4. **Render the Template**
With a template defined, you can render it to a string. This string can then be sent as a response to a client in a web application or stored for later use.
```typescript
async function renderMyTemplate() {
const renderedString = await smartNTML.renderTemplateResult(myTemplate);
console.log(renderedString);
}
renderMyTemplate();
```
### Working with Dynamic Content
`@push.rocks/smartntml` excels in rendering dynamic content. Assume you have an array of items that you want to display in a list:
```typescript
const items = ['Apple', 'Banana', 'Cherry'];
const listTemplate = deesElement.html`
<ul>
${items.map(item => deesElement.html`<li>${item}</li>`)}
</ul>
`;
```
You can dynamically render arrays or any functional JavaScript within your templates, making it incredibly powerful for generating dynamic HTML content.
### Advanced Usage
`@push.rocks/smartntml` can also integrate with other backend services and capabilities. For instance, using it alongside your server-side logic to render user-specific data, handling form submissions, or creating email templates.
**Note:** Always sanitize any user input before rendering it with `smartntml` to prevent XSS (Cross-Site Scripting) attacks.
### Support and Contribution
`@push.rocks/smartntml` is an open-source project and welcomes contributions from the community. Whether it's improving the documentation, adding new features, or reporting bugs, every contribution helps make `smartntml` better for everyone.
Before contributing to the project, make sure to discuss your ideas or issues on the repository's issue tracker. This ensures that your contributions align with the project's goals and don't overlap with existing efforts.
### Final Thoughts
`@push.rocks/smartntml` provides a streamlined and efficient way to use `lit-html`-like syntax for server-rendered templates in Node.js applications. It offers a blend of simplicity and power, enabling developers to create dynamic, data-driven HTML content on the backend with minimal effort. By integrating `@push.rocks/smartntml` into your project, you embrace modern JavaScript practices and significantly enhance your server-side rendering capabilities.
For more detailed usage examples and advanced features, make sure to check out the official documentation and explore the `@push.rocks/smartntml` codebase. Happy coding!
## 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.

View File

@ -1,26 +1,24 @@
import log from 'why-is-node-running';
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as smartntml from '../ts/index.js';
let testSmartntmlInstance: smartntml.Smartntml;
tap.test('first test', async () => {
testSmartntmlInstance = await smartntml.Smartntml.create();
testSmartntmlInstance = new smartntml.Smartntml();
});
tap.test('should render a string', async () => {
const arrayArg = [1, 2, 3, 4, 5, 6];
const stringResult = await testSmartntmlInstance.renderTemplateResult(testSmartntmlInstance.html`
const stringResult = await testSmartntmlInstance.renderTemplateResult(smartntml.deesElement.html`
<div class="hello">${arrayArg.map(
(element) => testSmartntmlInstance.html`<div>${element}</div>`
(element) => smartntml.deesElement.html`<div>${element}</div>`
)}</div>
`);
console.log(stringResult);
});
tap.test('should log', async () => {
log();
setTimeout(()=> process.exit(0), 0);
})
setTimeout(() => process.exit(0), 0);
});
tap.start();

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartntml',
version: '1.0.12',
description: 'lit-html for the backend'
name: '@push.rocks/smartntml',
version: '2.0.8',
description: 'Provides lit-html rendering capabilities for backend applications.'
}

17
ts/classes.smartntml.ts Normal file
View File

@ -0,0 +1,17 @@
import * as plugins from './smartntml.plugins.js';
export class Smartntml {
constructor() {}
public async renderTemplateResult(
templateResult: plugins.deesElement.TemplateResult,
stripCommentsArg = true
) {
const element = document.createElement('div');
plugins.deesElement.render(templateResult, element);
let stringResult = element.innerHTML;
if (stripCommentsArg) {
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
}
return stringResult;
}
}

View File

@ -1,39 +1,8 @@
import * as plugins from './smartntml.plugins.js';
import * as deesElement from '@designestate/dees-element';
// @ts-ignore
import './instrument/happydom.js';
import { Smartntml } from './classes.smartntml.js';
export { Smartntml };
import * as deesElement from '@design.estate/dees-element';
export { deesElement };
export class Smartntml {
// STATIC
public static async create() {
const smartntml = new Smartntml();
return smartntml;
}
private static smartntmlSingletonDeferred: plugins.smartpromise.Deferred<Smartntml>;
public static async createSingleton() {
if (this.smartntmlSingletonDeferred) {
return this.smartntmlSingletonDeferred.promise;
}
this.smartntmlSingletonDeferred = plugins.smartpromise.defer();
const smartntmlInstance = await this.create();
this.smartntmlSingletonDeferred.resolve(smartntmlInstance);
return this.smartntmlSingletonDeferred.promise;
}
// INSTANCE
private render = deesElement.render;
public html = deesElement.html;
public unsafeHTML = deesElement.unsafeHTML;
constructor() {
}
public async renderTemplateResult(templateResult: deesElement.TemplateResult, stripCommentsArg = true) {
const element = document.createElement('div');
this.render(templateResult, element);
let stringResult = element.innerHTML;
if (stripCommentsArg) {
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
}
return stringResult;
}
}

View File

@ -0,0 +1,9 @@
// happy-dom setup
// first lets setup indexeddb
import 'fake-indexeddb/auto';
// @ts-nocheck
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register();
window.location.href = 'http://localhost';

View File

@ -1,13 +1,11 @@
// happy-dom setup
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register();
window.location.href = 'http://localhost';
// @pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartpromise from '@push.rocks/smartpromise';
export {
smartpromise
}
export { smartpromise };
// designestate
import * as deesElement from '@design.estate/dees-element';
export { deesElement };
// third party scope

View File

@ -3,7 +3,12 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}