From: Aleksander Ɓukasz Date: Wed, 10 Apr 2013 13:32:39 +0000 (+0200) Subject: editor: extracting metadata from xml X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/56ab6eadd6887a63a83c768abf3c02393d1f4a28?hp=fd01330786845fedb31dd93439bf8b1c82cd56c6 editor: extracting metadata from xml --- diff --git a/modules/visualEditor.transformations.js b/modules/visualEditor.transformations.js index c317314..2d2f630 100644 --- a/modules/visualEditor.transformations.js +++ b/modules/visualEditor.transformations.js @@ -1,23 +1,42 @@ -rng.modules.visualEditor.transformations = {}; +if(typeof module !== 'undefined' && module.exports) { + var $ = require('jquery'); +} + +(function($) { -rng.modules.visualEditor.transformations.fromXML = { - getHTMLTree: function(xml) { - return xml; - }, - getMetaData: function(xml) { - return {}; - }, - getDocumentDescription: function(xml) { - return { - HTMLTree: this.getHTMLTree(xml), - metadata: this.getMetaData(xml) + var transformations = {}; + + transformations.fromXML = { + getHTMLTree: function(xml) { + return xml; + }, + getMetaData: function(xml) { + var toret = {}; + $(xml).find('metadata').children().each(function() { + var node = $(this); + toret[this.nodeName.split(':')[1].toLowerCase()] = node.text(); + }) + return toret; + }, + getDocumentDescription: function(xml) { + return { + HTMLTree: this.getHTMLTree(xml), + metadata: this.getMetaData(xml) + } } } -} + transformations.toXML = { + getXML: function(documentDescription) { + return documentDescription.HTMLTree; + } + } -rng.modules.visualEditor.transformations.toXML = { - getXML: function(documentDescription) { - return documentDescription.HTMLTree; + + if(typeof module !== 'undefined' && module.exports) { + module.exports = transformations; + } else { + rng.modules.visualEditor.transformations = transformations; } -} \ No newline at end of file + +})($); \ No newline at end of file