From c2f1fe9407cc920701dee5a1762f462648dc28e0 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Thu, 12 May 2016 13:05:49 +0300 Subject: [PATCH 1/2] Support "relative" URLs in component decorators. We get resolved absolute paths from Angular prefixed by a "//" --- src/nativescript-angular/xhr.ts | 28 +++++++++++++++++++--------- tests/app/tests/xhr-paths.ts | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/app/tests/xhr-paths.ts diff --git a/src/nativescript-angular/xhr.ts b/src/nativescript-angular/xhr.ts index 24989c0ba..6bce615fd 100644 --- a/src/nativescript-angular/xhr.ts +++ b/src/nativescript-angular/xhr.ts @@ -2,14 +2,24 @@ import {path, knownFolders, File} from "file-system"; import {XHR} from "@angular/compiler/src/xhr"; export class FileSystemXHR extends XHR { - get(url: string): Promise { - let appDir = knownFolders.currentApp().path; - let templatePath = path.join(appDir, url); + resolve(url: string, baseUrl: string): string { + //Angular assembles absolute URL's and prefixes them with // + if (url.indexOf("//") !== 0) { + //Resolve relative URL's based on the app root. + return path.join(baseUrl, url); + } else { + return url; + } + } - if (!File.exists(templatePath)) { - throw new Error(`File ${url} does not exist.`); - } - let templateFile = File.fromPath(templatePath); - return templateFile.readText(); - } + get(url: string): Promise { + const appDir = knownFolders.currentApp().path; + const templatePath = this.resolve(url, appDir); + + if (!File.exists(templatePath)) { + throw new Error(`File ${templatePath} does not exist. Resolved from: ${url}.`); + } + let templateFile = File.fromPath(templatePath); + return templateFile.readText(); + } } diff --git a/tests/app/tests/xhr-paths.ts b/tests/app/tests/xhr-paths.ts new file mode 100644 index 000000000..ab9033459 --- /dev/null +++ b/tests/app/tests/xhr-paths.ts @@ -0,0 +1,15 @@ +//make sure you import mocha-config before @angular/core +import {assert} from "./test-config"; +import {FileSystemXHR} from "nativescript-angular/xhr"; + +describe("XHR name resolution", () => { + it("resolves relative paths from app root", () => { + const xhr = new FileSystemXHR(); + assert.strictEqual("/app/dir/mydir/mycomponent.html", xhr.resolve("mydir/mycomponent.html", "/app/dir")) + }); + + it("resolves absolute paths as is", () => { + const xhr = new FileSystemXHR(); + assert.strictEqual("//app/mydir/mycomponent.html", xhr.resolve("//app/mydir/mycomponent.html", "/app/dir")) + }); +}) From 9a3535320db90ef5560e01ebf07b73abe11aae33 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Thu, 12 May 2016 13:05:56 +0300 Subject: [PATCH 2/2] Update ctags config. --- .ctags-exclude | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.ctags-exclude b/.ctags-exclude index 6e7c9dcf0..4841229da 100644 --- a/.ctags-exclude +++ b/.ctags-exclude @@ -3,27 +3,16 @@ bin build android17.d.ts ios.d.ts -ng-sample/app -ng-sample/src/angular2 -ng-sample/src/nativescript-angular +ng-sample/app/nativescript-angular ng-sample/platforms +ng-sample/node_modules ng-sample/lib ng-sample/src/typings -todomvc/app -todomvc/src/angular2 -todomvc/src/nativescript-angular -todomvc/platforms -todomvc/lib -todomvc/src/typings -todomvc/typings -startup-test/app -startup-test/src/angular2 -startup-test/src/nativescript-angular -startup-test/platforms -startup-test/lib -startup-test/src/typings -src/angular2 -web/*.js +tests/app/nativescript-angular +tests/platforms +tests/node_modules +tests/lib +tests/src/typings +tests/typings +web src/*.js -deps/angular/dist -deps/angular/tmp