Compare commits

..

No commits in common. "master" and "v1.0.2" have entirely different histories.

20 changed files with 152 additions and 18403 deletions

18
.gitignore vendored
View File

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

View File

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

11
.vscode/launch.json vendored
View File

@ -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
View File

@ -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"]
}
}
}
}
}
}
]
}

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# 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 template String for {{somePlaceholder}} and {{anotherPlaceholder}}')
myTlt.getStringFor({
"somePlaceholder": "pushrocks",
"anotherPlaceholder": "anotherPlaceholder"
})
```

18
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/**
* 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 Normal file
View File

@ -0,0 +1,27 @@
"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=

View File

@ -1,28 +0,0 @@
{
"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

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +1,33 @@
{
"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",
"name": "tlt",
"version": "1.0.2",
"description": "templates done right",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)",
"buildDocs": "tsdoc"
"test": "(npmts)"
},
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartmustache.git"
"url": "git+ssh://git@gitlab.com/pushrocks/tlt.git"
},
"keywords": [
"templating",
"handlebars",
"text processing",
"data binding",
"code generation",
"string interpolation",
"dynamic content"
"template"
],
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/tlt/issues"
},
"homepage": "https://code.foss.global/push.rocks/smartmustache",
"homepage": "https://gitlab.com/pushrocks/tlt#README",
"dependencies": {
"handlebars": "^4.7.7"
"@types/mustache": "^0.8.29",
"mustache": "^2.3.0",
"typings-global": "^1.0.14"
},
"devDependencies": {
"@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"
]
}
"@types/should": "^8.1.30",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
}

4679
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@

153
readme.md
View File

@ -1,153 +0,0 @@
# @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 Normal file
View File

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

16
test/test.js Normal file
View File

@ -0,0 +1,16 @@
"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,20 +1,16 @@
import { tap, expect } from '@pushrocks/tapbundle';
import 'typings-test'
import * as should from 'should'
import * as tlt from '../ts/index.js';
import * as tlt from '../dist/index'
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();
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')
})
})

View File

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

View File

@ -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
View File

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