Skip to content

Instantly share code, notes, and snippets.

@marcellodesales
Last active August 29, 2015 14:10
Show Gist options
  • Save marcellodesales/6ec634ca20ca285e194f to your computer and use it in GitHub Desktop.
Save marcellodesales/6ec634ca20ca285e194f to your computer and use it in GitHub Desktop.
From JSON to XML Todos for compatible with http://todos.sourceforge.net/manual.html
[
{
"file": "/home/mdesales/dev/github-intuit/sp-quality/src/test_tasks.js",
"text": "Find a workaround to install https://github.com/badges/shields locally as a module",
"kind": "FIXME",
"line": 49
}
]
/** @module lib/Todos Docs */
"use strict";
var builder = require("xmlbuilder");
/**
* @param {object} todosJson is instance of the json report.
* @return {object} An XML representation of the todos based on sourceforge's todo.
*/
module.exports.serialize = function(todosJson) {
// Generate the XML following the convention http://todos.sourceforge.net/samples/simple.xml
var commentsXml = builder.create("comments");
commentsXml.att("xmlns", "http://todos.sourceforge.net");
commentsXml.att("version", "0.1.0");
// Loop through all of them
todosJson.forEach(function(todo) {
var commentXml = commentsXml.ele("comment", todo.text);
commentXml.att("file", todo.file);
commentXml.att("line", todo.line);
commentXml.att("pattern", todo.kind);
});
// Generate the XML file
commentsXml = commentsXml.end({ pretty: true});
return commentsXml;
};
<?xml version="1.0"?>
<comments xmlns="http://todos.sourceforge.net" version="0.1.0">
<comment file="/home/mdesales/dev/github-intuit/sp-quality/src/test_tasks.js" line="49" pattern="FIXME">Find a workaround to install https://github.com/badges/shields locally as a module</comment>
</comments>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment