Compare commits

...

45 Commits

Author SHA1 Message Date
862a424dd4 update description 2024-05-29 14:14:55 +02:00
5a3da93578 update tsconfig 2024-04-14 18:01:23 +02:00
fc3b3d38aa update npmextra.json: githost 2024-04-01 21:36:46 +02:00
c5f0568c66 update npmextra.json: githost 2024-04-01 19:59:02 +02:00
394a13a9f3 update npmextra.json: githost 2024-03-30 21:48:02 +01:00
53b5cf2b58 switch to new org scheme 2023-07-11 01:15:06 +02:00
ca91dbc6dc switch to new org scheme 2023-07-10 10:16:46 +02:00
e87c14f3d8 3.0.2 2022-08-07 17:56:02 +02:00
d8abd96ad4 fix(core): update 2022-08-07 17:56:02 +02:00
543bb4b54d 3.0.1 2022-08-07 17:55:40 +02:00
e9da16ce4d fix(core): update 2022-08-07 17:55:40 +02:00
0040d714ef 3.0.0 2022-08-07 16:45:39 +02:00
084954b210 BREAKING CHANGE(core): switch to esm 2022-08-07 16:45:38 +02:00
1d6cc3833d 2.0.12 2021-05-17 15:49:47 +00:00
034c99151d fix(core): update 2021-05-17 15:49:46 +00:00
0c2b543d34 2.0.11 2021-05-17 12:37:02 +00:00
a0702190f7 fix(core): update 2021-05-17 12:37:01 +00:00
dedd7135f5 update 2021-05-17 12:36:21 +00:00
f84280d330 update 2021-05-17 12:36:15 +00:00
b0a2ebe470 2.0.10 2021-03-27 15:07:02 +00:00
1ab3432325 fix(core): update 2021-03-27 15:07:02 +00:00
c6a09e5f40 2.0.9 2020-01-12 18:54:10 +00:00
099d331fa7 fix(core): update 2020-01-12 18:54:09 +00:00
e6f9459fc8 2.0.8 2019-10-26 23:36:13 +02:00
d25fe85fcd fix(core): update 2019-10-26 23:36:13 +02:00
5ef057e31f 2.0.7 2019-02-17 17:04:32 +01:00
494cb72d78 fix(core): update 2019-02-17 17:04:31 +01:00
7b27b231ff 2.0.6 2019-02-17 16:56:18 +01:00
bd9ac0ab46 fix(security): add snyk 2019-02-17 16:56:18 +01:00
1c53edca7d 2.0.5 2019-02-17 16:55:08 +01:00
6b279824fb fix(core): update 2019-02-17 16:55:07 +01:00
c06b8e6a18 2.0.4 2018-09-15 12:43:01 +02:00
a707dff92d fix(structure): fix internal naming 2018-09-15 12:43:01 +02:00
7bad738cb1 2.0.3 2018-09-15 01:31:22 +02:00
0e5db8f6b4 fix(core): update 2018-09-15 01:31:22 +02:00
deadd463de 2.0.2 2018-09-15 01:19:54 +02:00
e783dcb1f8 fix(core): update 2018-09-15 01:19:54 +02:00
Phil Kunz
62cacffe61 Merge branch 'master' into 'master'
Master

See merge request pushrocks/tlt!1
2018-09-14 21:02:17 +00:00
Phil Kunz
df76935a52 Master 2018-09-14 21:02:17 +00:00
f078653846 update 2018-09-14 10:12:37 +02:00
50d70eaece update gitlab yml 2017-02-25 23:41:06 +01:00
452f086d84 1.0.5 2017-02-25 23:40:22 +01:00
0113d8ea19 update to handlebars 2017-02-25 23:40:15 +01:00
a5a8f5ae24 1.0.4 2016-11-20 17:54:39 +01:00
01ad44078c improve README 2016-11-20 17:54:13 +01:00
20 changed files with 18404 additions and 155 deletions

18
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,59 +1,128 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- test
- release
- trigger
- pages
- security
- test
- release
- metadata
testLEGACY:
stage: test
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci test legacy
- 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
testLTS:
stage: test
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci test lts
- 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
testSTABLE:
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci test stable
- 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 publish
- 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: trigger
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
stage: metadata
script:
- npmci command npmpage --host gitlab
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"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"]
}
}
}
}
}
}
]
}

View File

@ -1,17 +0,0 @@
# tlt
templates done right
## Usage
We recommend the use of TypeScript for best in class Intellisense
```javascript
import { Tlt } from 'tlt'
let myTlt = new Tlt('my {{somePlaceholder}} are {{anotherPlaceholder}}!')
let appliedString = myTlt.applyData({
"somePlaceholder": "horses",
"anotherPlaceholder": "awesome"
})
// appliedString will be 'my horses are awesome!'
```

18
dist/index.d.ts vendored
View File

@ -1,18 +0,0 @@
/**
* class Tlt allows templates to be used with different sets of data
*/
export declare class Tlt {
templateString: string;
/**
* constructor of class Tlt
*/
constructor(templateStringArg: string);
/**
* returns template string with data applied
*/
applyData(data: any): string;
/**
* set a new template string
*/
setTemplate(templateStringArg: string): void;
}

27
dist/index.js vendored
View File

@ -1,27 +0,0 @@
"use strict";
const mustache = require("mustache");
/**
* class Tlt allows templates to be used with different sets of data
*/
class Tlt {
/**
* constructor of class Tlt
*/
constructor(templateStringArg) {
this.templateString = templateStringArg;
}
/**
* returns template string with data applied
*/
applyData(data) {
return mustache.render(this.templateString, data);
}
/**
* set a new template string
*/
setTemplate(templateStringArg) {
this.templateString = templateStringArg;
}
}
exports.Tlt = Tlt;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEscUNBQW9DO0FBRXBDOztHQUVHO0FBQ0g7SUFHSTs7T0FFRztJQUNILFlBQVksaUJBQXlCO1FBQ2pDLElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUE7SUFDM0MsQ0FBQztJQUVEOztPQUVHO0lBQ0gsU0FBUyxDQUFDLElBQVM7UUFDZixNQUFNLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsY0FBYyxFQUFFLElBQUksQ0FBQyxDQUFBO0lBQ3JELENBQUM7SUFFRDs7T0FFRztJQUNILFdBQVcsQ0FBQyxpQkFBeUI7UUFDakMsSUFBSSxDQUFDLGNBQWMsR0FBRyxpQkFBaUIsQ0FBQTtJQUMzQyxDQUFDO0NBQ0o7QUF2QkQsa0JBdUJDIn0=

28
npmextra.json Normal file
View File

@ -0,0 +1,28 @@
{
"npmci": {
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartmustache",
"description": "A library for creating and applying templates using Handlebars.",
"npmPackagename": "@push.rocks/smartmustache",
"license": "MIT",
"keywords": [
"templating",
"handlebars",
"text processing",
"data binding",
"code generation",
"string interpolation",
"dynamic content"
]
}
},
"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"
}
}

13298
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,57 @@
{
"name": "tlt",
"version": "1.0.3",
"description": "templates done right",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@push.rocks/smartmustache",
"version": "3.0.2",
"description": "A library for creating and applying templates using Handlebars.",
"private": false,
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/tlt.git"
"url": "https://code.foss.global/push.rocks/smartmustache.git"
},
"keywords": [
"template"
"templating",
"handlebars",
"text processing",
"data binding",
"code generation",
"string interpolation",
"dynamic content"
],
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/tlt/issues"
},
"homepage": "https://gitlab.com/pushrocks/tlt#README",
"homepage": "https://code.foss.global/push.rocks/smartmustache",
"dependencies": {
"@types/mustache": "^0.8.29",
"mustache": "^2.3.0",
"typings-global": "^1.0.14"
"handlebars": "^4.7.7"
},
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
}
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsrun": "^1.2.37",
"@gitzone/tstest": "^1.0.73",
"@pushrocks/tapbundle": "^5.0.4"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

4679
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

153
readme.md Normal file
View File

@ -0,0 +1,153 @@
# @push.rocks/smartmustache
templates done right
## Install
To install `@push.rocks/smartmustache`, use npm:
```bash
npm install @push.rocks/smartmustache
```
Ensure you have Node.js and npm installed on your system before running the install command.
## Usage
To use `@push.rocks/smartmustache` in your project, follow these examples to understand how to integrate and utilize the library with its core functionalities. `@push.rocks/smartmustache` leverages Handlebars for templating, providing a seamless and efficient way to render dynamic content.
### Setting Up Your Project
First, ensure your project is set up to use ECMAScript modules (ESM) and TypeScript. Your `tsconfig.json` should include:
```json
{
"compilerOptions": {
"module": "ESNext",
"target": "es2020",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
```
This setup will allow you to use ESM syntax in your TypeScript files efficiently.
### Basic Templating
Let's start with a basic example of using `@push.rocks/smartmustache` to apply data to a template string.
1. **Create a New Template Instance:**
First, import `SmartMustache` and create an instance by passing a template string to its constructor.
```typescript
import { SmartMustache } from '@push.rocks/smartmustache';
const template = 'Hello, {{name}}! Welcome to {{location}}.';
const myTemplate = new SmartMustache(template);
```
2. **Apply Data to the Template:**
Next, apply data to your template using the `applyData` method.
```typescript
const result = myTemplate.applyData({
name: 'John Doe',
location: 'SmartMustache World'
});
console.log(result); // Outputs: Hello, John Doe! Welcome to SmartMustache World.
```
### Advanced Usage
**Conditional Statements and Loops:**
Handlebars syntax allows for conditionals and loops. `@push.rocks/smartmustache` fully supports these Handlebars features.
- **Conditionals:**
Consider you have a template that should render content based on certain conditions.
```typescript
const conditionalTemplate = new SmartMustache(`
{{#if isAdmin}}
<p>Welcome, admin.</p>
{{else}}
<p>Welcome, user.</p>
{{/if}}
`);
console.log(conditionalTemplate.applyData({ isAdmin: true }));
```
- **Loops:**
Similarly, if you'd like to iterate over an array of items:
```typescript
const loopTemplate = new SmartMustache(`
<ul>
{{#each items}}
<li>{{this}}</li>
{{/each}}
</ul>
`);
console.log(loopTemplate.applyData({
items: ['Item 1', 'Item 2', 'Item 3']
}));
```
### Providing Helpers
`@push.rocks/smartmustache` allows integrating Handlebars helpers to extend templating capabilities.
```typescript
import Handlebars from 'handlebars';
// Register a Handlebars helper
Handlebars.registerHelper('uppercase', function(aString) {
return aString.toUpperCase();
});
const helperTemplate = new SmartMustache('Hello, {{uppercase name}}!');
console.log(helperTemplate.applyData({ name: 'john' })); // Outputs: Hello, JOHN!
```
### Reusing Templates
You can reuse an instance of `SmartMustache` by setting a new template string.
```typescript
myTemplate.setTemplate('Goodbye, {{name}}. See you in {{location}}.');
console.log(myTemplate.applyData({
name: 'Jane Doe',
location: 'the virtual world'
}));
```
### Conclusion
`@push.rocks/smartmustache` provides a powerful and intuitive way to work with templates in your TypeScript projects. By following these guides, you'll be able to implement dynamic content rendering seamlessly. The flexibility of Handlebars within a TypeScript-friendly wrapper accelerates development, ensuring your templates are both manageable and scalable.
## 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.

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,16 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const tlt = require("../dist/index");
describe('tlt', function () {
let testTlt;
it('should create a valid instance of tlt', function () {
testTlt = new tlt.Tlt('some awesome {{customString}}');
should(testTlt).be.instanceOf(tlt.Tlt);
});
it('should output a valid string with some data', function () {
let appliedString = testTlt.applyData({ customString: 'horse' });
should(appliedString).equal('some awesome horse');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMscUNBQW9DO0FBRXBDLFFBQVEsQ0FBQyxLQUFLLEVBQUU7SUFDWixJQUFJLE9BQWdCLENBQUE7SUFDcEIsRUFBRSxDQUFDLHVDQUF1QyxFQUFFO1FBQ3hDLE9BQU8sR0FBRyxJQUFJLEdBQUcsQ0FBQyxHQUFHLENBQUMsK0JBQStCLENBQUMsQ0FBQTtRQUN0RCxNQUFNLENBQUMsT0FBTyxDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDMUMsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsNkNBQTZDLEVBQUU7UUFDOUMsSUFBSSxhQUFhLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFDLFlBQVksRUFBRSxPQUFPLEVBQUMsQ0FBQyxDQUFBO1FBQzlELE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxLQUFLLENBQUMsb0JBQW9CLENBQUMsQ0FBQTtJQUNyRCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -1,16 +1,20 @@
import 'typings-test'
import * as should from 'should'
import { tap, expect } from '@pushrocks/tapbundle';
import * as tlt from '../dist/index'
import * as tlt from '../ts/index.js';
describe('tlt', function() {
let testTlt: tlt.Tlt
it('should create a valid instance of tlt', function() {
testTlt = new tlt.Tlt('some awesome {{customString}}')
should(testTlt).be.instanceOf(tlt.Tlt)
})
it('should output a valid string with some data', function(){
let appliedString = testTlt.applyData({customString: 'horse'})
should(appliedString).equal('some awesome horse')
})
})
let testMustache: tlt.SmartMustache;
tap.test('should create a valid instance of tlt', async () => {
testMustache = new tlt.SmartMustache(
'some awesome {{customString}} that is {{license}} licensed'
);
expect(testMustache).toBeInstanceOf(tlt.SmartMustache);
});
tap.test('should output a valid string with some data', async () => {
let appliedString = testMustache.applyData({
customString: 'horse',
license: 'MIT',
});
expect(appliedString).toEqual('some awesome horse that is MIT licensed');
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartmustache',
version: '3.0.2',
description: 'templates done right'
}

View File

@ -1,29 +1,29 @@
import * as mustache from 'mustache'
import handlebars from 'handlebars';
/**
* class Tlt allows templates to be used with different sets of data
*/
export class Tlt {
templateString: string
export class SmartMustache {
template: any;
/**
* constructor of class Tlt
*/
constructor(templateStringArg: string) {
this.templateString = templateStringArg
}
/**
* constructor of class Tlt
*/
constructor(templateStringArg: string) {
this.template = handlebars.compile(templateStringArg);
}
/**
* returns template string with data applied
*/
applyData(data: any): string {
return mustache.render(this.templateString, data)
}
/**
* returns template string with data applied
*/
applyData(data: any): string {
return this.template(data);
}
/**
* set a new template string
*/
setTemplate(templateStringArg: string) {
this.templateString = templateStringArg
}
/**
* set a new template string
*/
setTemplate(templateStringArg: string) {
this.template = handlebars.compile(templateStringArg);
}
}

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}