Merge pull request #620 from NathanaelA/createPage_autoload_page_css

frame-common.ts is missing the code to automagically load the page.css
This commit is contained in:
Hristo Hristov
2015-08-26 11:50:16 +03:00
6 changed files with 64 additions and 7 deletions

View File

@ -247,7 +247,7 @@ export function test_LoadPageFromModule() {
try { try {
var topFrame = FrameModule.topmost(); var topFrame = FrameModule.topmost();
TKUnit.assert(topFrame.currentPage.content instanceof LabelModule.Label, "Content of the test page should be a Label created within test-page-module."); TKUnit.assert(topFrame.currentPage.content instanceof LabelModule.Label, "Content of the test page should be a Label created within test-page-module.");
var testLabel = <LabelModule.Label>topFrame.currentPage.content var testLabel = <LabelModule.Label>topFrame.currentPage.content;
TKUnit.assert(testLabel.text === "Label created within a page module."); TKUnit.assert(testLabel.text === "Label created within a page module.");
} }
finally { finally {
@ -255,6 +255,35 @@ export function test_LoadPageFromModule() {
} }
} }
export function test_LoadPageFromDeclarativeWithCSS() {
helper.navigateToModule("ui/page/test-page-declarative-css");
try {
var topFrame = FrameModule.topmost();
TKUnit.assert(topFrame.currentPage.content instanceof LabelModule.Label, "Content of the test page should be a Label created within test-page-module-css.");
var testLabel = <LabelModule.Label>topFrame.currentPage.content;
TKUnit.assert(testLabel.text === "Label created within a page declarative file with css.");
TKUnit.assert(testLabel.style.backgroundColor.hex === "#ff00ff00", "Expected: #ff00ff00, Actual: " + testLabel.style.backgroundColor.hex);
}
finally {
helper.goBack();
}
}
export function test_LoadPageFromModuleWithCSS() {
helper.navigateToModule("ui/page/test-page-module-css");
try {
var topFrame = FrameModule.topmost();
TKUnit.assert(topFrame.currentPage.content instanceof LabelModule.Label, "Content of the test page should be a Label created within test-page-module-css.");
var testLabel = <LabelModule.Label>topFrame.currentPage.content;
TKUnit.assert(testLabel.text === "Label created within a page module css.");
TKUnit.assert(testLabel.style.backgroundColor.hex === "#ff00ff00", "Expected: #ff00ff00, Actual: " + testLabel.style.backgroundColor.hex);
}
finally {
helper.goBack();
}
}
export function test_NavigateToPageCreatedWithNavigationEntry() { export function test_NavigateToPageCreatedWithNavigationEntry() {
var expectedText = "Label created with a NavigationEntry"; var expectedText = "Label created with a NavigationEntry";
var testPage: PageModule.Page; var testPage: PageModule.Page;

View File

@ -0,0 +1,3 @@
Label {
background-color: #ff00ff00;
}

View File

@ -0,0 +1,3 @@
<Page>
<Label text="Label created within a page declarative file with css."/>
</Page>

View File

@ -0,0 +1,3 @@
Label {
background-color: #ff00ff00;
}

View File

@ -0,0 +1,19 @@
import PageModule = require("ui/page");
import LabelModule = require("ui/label");
export class TestPageModule extends PageModule.Page {
constructor() {
super();
var label = new LabelModule.Label();
label.text = "Label created within a page module css.";
this.content = label;
}
}
export function createPage() {
return new TestPageModule();
}
//export var Page = new TestPageModule();

View File

@ -65,6 +65,12 @@ export function resolvePageFromEntry(entry: definition.NavigationEntry): pages.P
if (!(page && page instanceof pages.Page)) { if (!(page && page instanceof pages.Page)) {
throw new Error("Failed to load Page from entry.moduleName: " + entry.moduleName); throw new Error("Failed to load Page from entry.moduleName: " + entry.moduleName);
} }
// Possible CSS file path.
var cssFileName = fileResolverModule.resolveFileName(moduleNamePath, "css");
if (cssFileName) {
page.addCssFile(cssFileName);
}
} }
return page; return page;
@ -83,12 +89,6 @@ function pageFromBuilder(moduleNamePath: string, moduleExports: any): pages.Page
element = builder.load(fileName, moduleExports); element = builder.load(fileName, moduleExports);
if (element instanceof pages.Page) { if (element instanceof pages.Page) {
page = <pages.Page>element; page = <pages.Page>element;
// Possible CSS file path.
var cssFileName = fileResolverModule.resolveFileName(moduleNamePath, "css");
if (cssFileName) {
page.addCssFile(cssFileName);
}
} }
} }