diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f93687 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +coverage/ +public/ +pages/ diff --git a/README.md b/README.md index 0604737..05be775 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ templates done right We recommend the use of TypeScript for best in class Intellisense ```javascript -import * as tlt from 'tlt +import { Tlt } from 'tlt' -let myTlt = new tlt('my template String for {{somePlaceholder}} and {{anotherPlaceholder}}') +let myTlt = new Tlt('my template String for {{somePlaceholder}} and {{anotherPlaceholder}}') myTlt.getStringFor({ "somePlaceholder": "pushrocks", "anotherPlaceholder": "anotherPlaceholder" diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..bd6cdbd --- /dev/null +++ b/dist/index.d.ts @@ -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; +} diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..1486107 --- /dev/null +++ b/dist/index.js @@ -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= \ No newline at end of file diff --git a/package.json b/package.json index b980a9d..20d5c4d 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,15 @@ "bugs": { "url": "https://gitlab.com/pushrocks/tlt/issues" }, - "homepage": "https://gitlab.com/pushrocks/tlt#README" + "homepage": "https://gitlab.com/pushrocks/tlt#README", + "dependencies": { + "@types/mustache": "^0.8.29", + "mustache": "^2.3.0", + "typings-global": "^1.0.14" + }, + "devDependencies": { + "@types/should": "^8.1.30", + "should": "^11.1.1", + "typings-test": "^1.0.3" + } } diff --git a/test/test.d.ts b/test/test.d.ts new file mode 100644 index 0000000..2fd432a --- /dev/null +++ b/test/test.d.ts @@ -0,0 +1 @@ +import 'typings-test'; diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..55c2ed0 --- /dev/null +++ b/test/test.js @@ -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= \ No newline at end of file diff --git a/test/test.ts b/test/test.ts new file mode 100644 index 0000000..4b1bb5c --- /dev/null +++ b/test/test.ts @@ -0,0 +1,16 @@ +import 'typings-test' +import * as should from 'should' + +import * as tlt from '../dist/index' + +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') + }) +}) diff --git a/ts/index.ts b/ts/index.ts new file mode 100644 index 0000000..48146f9 --- /dev/null +++ b/ts/index.ts @@ -0,0 +1,29 @@ +import * as mustache from 'mustache' + +/** + * class Tlt allows templates to be used with different sets of data + */ +export class Tlt { + templateString: string + + /** + * constructor of class Tlt + */ + constructor(templateStringArg: string) { + this.templateString = templateStringArg + } + + /** + * 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.templateString = templateStringArg + } +}