diff --git a/package.json b/package.json index e94fbb9..0be5522 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,40 @@ { - "name": "angular2-twig", - "version": "1.0.0", - "description": "Twig template engine support for Angular2", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/manekinekko/angular2-twig.git" - }, - "keywords": [ - "twig", - "angular2", - "template", - "engine" - ], - "author": "Wassim Chegham ", - "license": "MIT", - "bugs": { - "url": "https://github.com/manekinekko/angular2-twig/issues" - }, - "engines": { - "node": ">= 5.4.1 < 6" - }, - "homepage": "https://github.com/manekinekko/angular2-twig#readme", - "dependencies": { - "angular2": "2.0.0-beta.6", - "es6-shim": "^0.33.8", - "reflect-metadata": "0.1.2", - "rxjs": "5.0.0-beta.0", - "systemjs": "^0.19.16", - "zone.js": "0.5.14" - } -} + "name": "@manekinekko/angular-twig", + "version": "1.0.0", + "description": "Twig template engine support for Angular", + "main": "twig-decorator.js", + "scripts": { + "start": "tsc" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/manekinekko/angular-twig.git" + }, + "keywords": [ + "twig", + "angular", + "template", + "engine" + ], + "author": "Wassim Chegham ", + "license": "MIT", + "bugs": { + "url": "https://github.com/manekinekko/angular-twig/issues" + }, + "engines": { + "node": ">= 5.4.1 < 8" + }, + "homepage": "https://github.com/manekinekko/angular-twig#readme", + "dependencies": { + "@angular/core": "^4.0.0", + "es6-shim": "^0.35.3", + "rxjs": "^5.1.0", + "reflect-metadata": "0.1.2", + "zone.js": "^0.8.4", + "twig": "^1.10.4" + }, + "devDependencies": { + "@types/node": "~6.0.60", + "typescript": "~2.2.0" + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index bc86561..dfa03fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,20 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "noImplicitAny": false, - "outDir": ".", - "rootDir": ".", - "sourceMap": true, - "declaration": true - }, - "exclude": [ - "node_modules" - ] -} + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, + "outDir": ".", + "rootDir": ".", + "sourceMap": true, + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "lib": [ + "es2016", + "dom" + ] + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/twig-decorator.d.ts b/twig-decorator.d.ts index 0a11a21..98f7533 100644 --- a/twig-decorator.d.ts +++ b/twig-decorator.d.ts @@ -1 +1 @@ -export declare function Twig(args?: {}): (cls: any) => void; +export declare function Twig(args?: any): (cls: any) => void; diff --git a/twig-decorator.js b/twig-decorator.js index a47a5db..cc8462e 100644 --- a/twig-decorator.js +++ b/twig-decorator.js @@ -1,19 +1,18 @@ "use strict"; -var core_1 = require('angular2/core'); -var async_1 = require('angular2/src/facade/async'); -var twig = window.twig; +Object.defineProperty(exports, "__esModule", { value: true }); +var core_1 = require("@angular/core"); +var twig_1 = require("twig"); function Twig(args) { if (args === void 0) { args = {}; } return function TwigDecorator(cls) { args.template = RenderSync(args); - args.templateUrl = ''; TwigComponent(args)(cls); }; } exports.Twig = Twig; function loadTemplate(url) { var xhr = new XMLHttpRequest(); - xhr.open('GET', url, false); + xhr.open('GET', url, false); // MUST BE SYNC FOR NOW!!! xhr.send(); return xhr.responseText; } @@ -31,23 +30,24 @@ function RenderSync(args) { tpl = loadTemplate(args.templateUrl); } console.log('annotation Twig OK'); - return twig({ + return twig_1.twig({ id: 'RenderSync', data: tpl }).render(args.context); } +// Not working for now because decorators are resolved synchronously! function RenderAsync(args) { - var completer = async_1.PromiseWrapper.completer(); - twig({ - id: 'RenderAsync', - href: args.templateUrl, - load: function (template) { - var tpl = template.render(args.context); - console.log('annotation Twig OK'); - completer.resolve(tpl); - }, - error: completer.reject + return new Promise(function (resolve, reject) { + twig_1.twig({ + id: 'RenderAsync', + href: args.templateUrl, + load: function (template) { + var tpl = template.render(args.context); + console.log('annotation Twig OK'); + resolve(tpl); + }, + error: reject + }); }); - return completer.promise; } -//# sourceMappingURL=twig-decorator.js.map +//# sourceMappingURL=twig-decorator.js.map \ No newline at end of file diff --git a/twig-decorator.js.map b/twig-decorator.js.map index 803e121..a67b5e1 100644 --- a/twig-decorator.js.map +++ b/twig-decorator.js.map @@ -1 +1 @@ -{"version":3,"file":"twig-decorator.js","sourceRoot":"","sources":["twig-decorator.ts"],"names":[],"mappings":";AAAA,qBAEO,eAAe,CAAC,CAAA;AAEvB,sBAEO,2BAA2B,CAAC,CAAA;AAEnC,IAAI,IAAI,GAAmB,MAAO,CAAC,IAAI,CAAC;AAExC,cAAqB,IAAW;IAAX,oBAAW,GAAX,SAAW;IAC9B,MAAM,CAAC,uBAAuB,GAAG;QAC/B,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC;AANe,YAAI,OAMnB,CAAA;AAED,sBAAsB,GAAG;IACvB,IAAI,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IAC/B,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,GAAG,CAAC,IAAI,EAAE,CAAC;IACX,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC;AAC1B,CAAC;AAED,uBAAuB,MAAM;IAC3B,MAAM,CAAC,UAAS,GAAG;QACjB,IAAI,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;QAChE,WAAW,CAAC,IAAI,CAAC,IAAI,gBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACxC,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;QACxD,MAAM,CAAC,GAAG,CAAC;IACb,CAAC,CAA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AAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACxC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;gBAClC,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC;YACD,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"} \ No newline at end of file diff --git a/twig-decorator.ts b/twig-decorator.ts index 240ebf2..96942f5 100644 --- a/twig-decorator.ts +++ b/twig-decorator.ts @@ -1,17 +1,13 @@ import { Component -} from 'angular2/core'; +} from '@angular/core'; +import {twig} from 'twig'; -import { - PromiseWrapper -} from 'angular2/src/facade/async'; - -var twig: Function = (window).twig; +declare var Reflect; export function Twig(args:any={}) { return function TwigDecorator(cls) { args.template = RenderSync(args); - args.templateUrl = ''; TwigComponent(args)(cls); }; } @@ -49,16 +45,16 @@ function RenderSync(args) { // Not working for now because decorators are resolved synchronously! function RenderAsync(args) { - var completer = PromiseWrapper.completer(); - twig({ - id: 'RenderAsync', - href: args.templateUrl, - load: (template) => { - let tpl = template.render(args.context); - console.log('annotation Twig OK'); - completer.resolve(tpl); - }, - error: completer.reject + return new Promise( (resolve, reject) => { + twig({ + id: 'RenderAsync', + href: args.templateUrl, + load: (template) => { + let tpl = template.render(args.context); + console.log('annotation Twig OK'); + resolve(tpl); + }, + error: reject + }); }); - return completer.promise; } diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..ab423ff --- /dev/null +++ b/yarn.lock @@ -0,0 +1,80 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@angular/core@^4.0.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@angular/core/-/core-4.1.0.tgz#72ec173316879571880c9c483ed6dfc0caab94b0" + +"@types/node@~6.0.60": + version "6.0.71" + resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.71.tgz#aa49e0109e35f1457867b45822caf7f4883ca248" + +balanced-match@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" + +brace-expansion@^1.0.0: + version "1.1.7" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" + dependencies: + balanced-match "^0.4.1" + concat-map "0.0.1" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +es6-shim@^0.35.3: + version "0.35.3" + resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.35.3.tgz#9bfb7363feffff87a6cdb6cd93e405ec3c4b6f26" + +foreachasync@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/foreachasync/-/foreachasync-3.0.0.tgz#5502987dc8714be3392097f32e0071c9dee07cf6" + +locutus@^2.0.5: + version "2.0.8" + resolved "https://registry.yarnpkg.com/locutus/-/locutus-2.0.8.tgz#557d669e39999dea03d1b0ac1d9e9bab8e81e4f7" + +minimatch@3.0.x: + version "3.0.3" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" + dependencies: + brace-expansion "^1.0.0" + +reflect-metadata@0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.2.tgz#ea23e5823dc830f292822bd3da9b89fd57bffb03" + +rxjs@^5.1.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.3.0.tgz#d88ccbdd46af290cbdb97d5d8055e52453fabe2d" + dependencies: + symbol-observable "^1.0.1" + +symbol-observable@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d" + +twig@^1.10.4: + version "1.10.4" + resolved "https://registry.yarnpkg.com/twig/-/twig-1.10.4.tgz#2ebad1e7e38c02b9cc772934822da1163d4ad4a1" + dependencies: + locutus "^2.0.5" + minimatch "3.0.x" + walk "2.3.x" + +typescript@~2.2.0: + version "2.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.2.tgz#606022508479b55ffa368b58fee963a03dfd7b0c" + +walk@2.3.x: + version "2.3.9" + resolved "https://registry.yarnpkg.com/walk/-/walk-2.3.9.tgz#31b4db6678f2ae01c39ea9fb8725a9031e558a7b" + dependencies: + foreachasync "^3.0.0" + +zone.js@^0.8.4: + version "0.8.9" + resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.9.tgz#34aaa9a3ec6d0e4acebd1b761adafa590473638b"