editor: extracting metadata from xml
[fnpeditor.git] / modules / visualEditor.transformations.js
1 if(typeof module !== 'undefined' && module.exports) {
2     var $ = require('jquery');
3 }
4
5 (function($) {
6
7     var transformations = {};
8
9     transformations.fromXML = {
10         getHTMLTree: function(xml) {
11             return xml;
12         },
13         getMetaData: function(xml) {
14             var toret = {};
15             $(xml).find('metadata').children().each(function() {
16                 var node = $(this);
17                 toret[this.nodeName.split(':')[1].toLowerCase()] = node.text();
18             })
19             return toret;
20         },
21         getDocumentDescription: function(xml) {
22             return {
23                 HTMLTree: this.getHTMLTree(xml),
24                 metadata: this.getMetaData(xml)
25             }
26         }
27     }
28
29     transformations.toXML = {
30         getXML: function(documentDescription) {
31             return documentDescription.HTMLTree;
32         }
33     }
34
35
36     if(typeof module !== 'undefined' && module.exports) {
37         module.exports = transformations;
38     } else {
39         rng.modules.visualEditor.transformations = transformations;
40     }
41
42 })($);