Skip to content

Instantly share code, notes, and snippets.

@achudars
Last active August 29, 2015 14:16
Show Gist options
  • Save achudars/74ee29976da21ebff13a to your computer and use it in GitHub Desktop.
Save achudars/74ee29976da21ebff13a to your computer and use it in GitHub Desktop.
HTML2IFML mapping
pre {
// initial setup of the IFML model structure
var IFMLModel := new IFML!IFMLModel;
IFMLModel.id = "journey";
IFMLModel.name = "journey";
IFMLModel.contentModel := new IFML!ContentModel;
IFMLModel.contentModel.id = "ContentModel";
IFMLModel.contentModel.name = "ContentModel";
IFMLModel.interactionFlowModel := new IFML!InteractionFlowModel;
IFMLModel.interactionFlowModel.id = "InteractionFlowModel";
IFMLModel.interactionFlowModel.name = "InteractionFlowModel";
}
rule XML2IFML
transform xml : XML!t_journey
to ifml : IFML!Window {
traverse(xml, ifml);
IFMLModel.interactionFlowModel.interactionFlowModelElements.add(ifml);
}
operation traverse(xml : Any, ifml : Any) {
ifml.id = xml.getNodeName();
ifml.name = xml.getNodeName();
for (child in xml.children) {
var node;
if (child.isTypeOf(t_transition)) {
node := new IFML!Event;
//} else if (child.isTypeOf(t_form) or child.isTypeOf(t_ul) or child.isTypeOf(t_input)){
// node := new IFML!ViewComponent;
//} else if (child.isTypeOf(t_li)) { node := new IFML!ViewComponentPart;
// << OMITTED MAPPING RULES GO HERE >>
} else { node := new IFML!ViewContainer; }
setIdentification(node,child);
if (node.isTypeOf(IFML!Event) or node.isTypeOf(IFML!ViewContainer)) {
ifml.viewElements.add(node);
} else if (node.isTypeOf(IFML!ViewComponentPart)) {
ifml.viewComponentParts.add(node);
} else {
ifml.viewElements.add(node);
}
// recursively traverse
traverse(child,node);
}
}
operation setIdentification(node : Any, child : Any) {
node.id = child.a_id;
node.name = child.getNodeName();
// property parentViewComponentPart for ViewComponentPart must be set
if (node.isTypeOf(IFML!ViewComponentPart)) {
node.parentViewComponentPart := node;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment