From db5efc2a8d744706a1bbbb66b96897d9906ee70e Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Mon, 29 Jun 2015 15:02:19 +0300 Subject: [PATCH] look for plugins/modules in tns_modules folder not only in the app root + test --- .../xml-declaration/xml-declaration-tests.ts | 26 ++++++++++++++----- ui/builder/component-builder.ts | 13 +++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/apps/tests/xml-declaration/xml-declaration-tests.ts b/apps/tests/xml-declaration/xml-declaration-tests.ts index 54385ba32..73aa541c7 100644 --- a/apps/tests/xml-declaration/xml-declaration-tests.ts +++ b/apps/tests/xml-declaration/xml-declaration-tests.ts @@ -242,7 +242,21 @@ export function test_parse_ShouldParseCustomComponentWithoutXml() { TKUnit.assert(ctrl instanceof myCustomControlWithoutXml.MyControl, "Expected result: custom control is defined!; Actual result: " + ctrl); }; -export function test_parse_ShouldParseCustomComponentWitXml() { +export function test_parse_ShouldParseCustomComponentWithoutXmlFromTNSModules() { + var p = builder.parse(''); + var ctrl = p.content; + + TKUnit.assert(ctrl instanceof labelModule.Label, "Expected result: custom control is defined!; Actual result: " + ctrl); +}; + +export function test_parse_ShouldParseCustomComponentWithoutXmlFromTNSModulesWhenNotSpecified() { + var p = builder.parse(''); + var ctrl = p.content; + + TKUnit.assert(ctrl instanceof labelModule.Label, "Expected result: custom control is defined!; Actual result: " + ctrl); +}; + +export function test_parse_ShouldParseCustomComponentWithXml() { var p = builder.parse(''); var panel = p.content; var lbl = panel.getChildAt(0); @@ -250,21 +264,21 @@ export function test_parse_ShouldParseCustomComponentWitXml() { TKUnit.assert(lbl.text === "mymodulewithxml", "Expected result: 'mymodulewithxml'; Actual result: " + lbl); }; -export function test_parse_ShouldParseCustomComponentWitXml_WithAttributes() { +export function test_parse_ShouldParseCustomComponentWithXml_WithAttributes() { var p = builder.parse(''); var panel = p.content; TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility"); }; -export function test_parse_ShouldParseCustomComponentWitXml_WithCustomAttributes() { +export function test_parse_ShouldParseCustomComponentWithXml_WithCustomAttributes() { var p = builder.parse(''); var panel = p.content; TKUnit.assertEqual(panel["myProperty"], "myValue", "customControl.myProperty"); }; -export function test_parse_ShouldParseCustomComponentWitXmlNoJS() { +export function test_parse_ShouldParseCustomComponentWithXmlNoJS() { var p = builder.parse(''); var panel = p.content; var lbl = panel.getChildAt(0); @@ -272,14 +286,14 @@ export function test_parse_ShouldParseCustomComponentWitXmlNoJS() { TKUnit.assertEqual(lbl.text, "I'm all about taht XML, no JS", "label.text"); }; -export function test_parse_ShouldParseCustomComponentWitXmlNoJS_WithAttributes() { +export function test_parse_ShouldParseCustomComponentWithXmlNoJS_WithAttributes() { var p = builder.parse(''); var panel = p.content; TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility"); }; -export function test_parse_ShouldParseCustomComponentWitXmlNoJS_WithCustomAttributes() { +export function test_parse_ShouldParseCustomComponentWithXmlNoJS_WithCustomAttributes() { var p = builder.parse(''); var panel = p.content; diff --git a/ui/builder/component-builder.ts b/ui/builder/component-builder.ts index e926ed8fe..5f2c66dee 100644 --- a/ui/builder/component-builder.ts +++ b/ui/builder/component-builder.ts @@ -58,8 +58,19 @@ export function getComponentModule(elementName: string, namespace: string, attri var moduleId = MODULES[elementName] || UI_PATH + elementName.toLowerCase(); try { + if (types.isString(namespace)) { + var pathInsideTNSModules = fs.path.join(fs.knownFolders.currentApp().path, "tns_modules", namespace); + + if (fs.Folder.exists(pathInsideTNSModules)) { + moduleId = pathInsideTNSModules; + } else { + // We expect module at root level in the app. + moduleId = fs.path.join(fs.knownFolders.currentApp().path, namespace); + } + } + // Require module by module id. - instanceModule = require(types.isString(namespace) && fs.path.join(fs.knownFolders.currentApp().path, namespace) || moduleId); + instanceModule = require(moduleId); // Get the component type from module. var instanceType = instanceModule[elementName] || Object;