Enketo Transformer
NodeJS library that transforms OpenRosa/ODK XForms into a format the Enketo understands. It works both as a library module, as well as a standalone app.
Prerequisites
- nodeJS and npm (only tested on Ubuntu 14.04, on older distros the GCC compiler may not be recent enough)
Install as module
npm install enketo-transformer --save
Use as module
var transformer = require('enketo-transformer');
var xform = fs.readFileSync( 'path/to/xform.xml' );
transformer.transform( {
xform: xform,
theme: 'sometheme',
media: {
'myfile.png' : '/path/to/somefile.png',
'myfile.mp3' : '/another/path/to/2.mp3'
}
} ).then(function( result ){
});
Install as app (web API)
- clone repo
- install dependencies with
npm install
Use as app (web API)
- start with
npm start
- limited use with
GET /transform
with xform parameter (required, xform URL), or - full-featured use with:
POST /transform
with URL-encoded body including xform
(required, full XForm as a string), theme
(optional, string), and media
(optional, map) parameters
sample GET request:
curl http://localhost:8085/transform?xform=https://example.com/forms/78372/form.xml
sample POST request:
curl -d "xform=<xform>x</xform>&theme=plain&media[myfile.png]=/path/to/somefile.png&media[this]=that" http://localhost:8085/transform
Response format
{
"form" : "<form>.....</form>",
"model": "<model>...</model>"
}
Test
- install mocha
- run tests with
npm test
Develop
A vagrant configuration file and provisioning script is included. Use DEBUG environment variable to see debug terminal output, e.g.:
DEBUG=api,transformer,markdown,language node app.js
License
See license document. Also note the additional 'powered by enketo' footer requirement of enketo-xslt which is used in this repository and therefore applicable.
Change Log
See change log