platform specific component declaration support for UI builder + tests

This commit is contained in:
Vladimir Enchev
2015-06-17 10:51:32 +03:00
parent 1a9c7af8b0
commit b38d181b67
2 changed files with 40 additions and 0 deletions

View File

@ -5,9 +5,19 @@ import file_access_module = require("file-system/file-system-access");
import types = require("utils/types");
import componentBuilder = require("ui/builder/component-builder");
import templateBuilderDef = require("ui/builder/template-builder");
import platform = require("platform");
var KNOWNCOLLECTIONS = "knownCollections";
function isPlatform(value: string): boolean {
return value && (value.toLowerCase() === platform.platformNames.android.toLowerCase()
|| value.toLowerCase() === platform.platformNames.ios.toLowerCase());
}
function isCurentPlatform(value: string): boolean {
return value && value.toLowerCase() === platform.device.os.toLowerCase();
}
export function parse(value: string, exports: any): view.View {
var viewToReturn: view.View;
@ -32,9 +42,29 @@ function parseInternal(value: string, exports: any): componentBuilder.ComponentM
var templateBuilder: templateBuilderDef.TemplateBuilder;
var currentPlatformContext: string;
// Parse the XML.
var xmlParser = new xml.XmlParser((args: xml.ParserEvent) => {
if (args.eventType === xml.ParserEventType.StartElement) {
if (isPlatform(args.elementName)) {
currentPlatformContext = args.elementName;
return;
}
}
if (currentPlatformContext && !isCurentPlatform(currentPlatformContext)) {
return;
}
if (args.eventType === xml.ParserEventType.EndElement) {
if (isPlatform(args.elementName)) {
currentPlatformContext = undefined;
return;
}
}
if (templateBuilder) {
if (args.eventType === xml.ParserEventType.StartElement) {
templateBuilder.addStartElement(args.prefix, args.namespace, args.elementName, args.attributes);