This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
xforms-engine.js
70 lines (66 loc) · 1.73 KB
/
xforms-engine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* MOST Web Framework
* A JavaScript Web Framework
* http://themost.io
*
* Copyright (c) 2014, Kyriakos Barbounakis k.barbounakis@gmail.com, Anthi Oikonomou anthioikonomou@gmail.com
*
* Released under the BSD3-Clause license
* Date: 2014-05-07
*/
/**
* @private
*/
var xforms = require('xforms'), xml = require('most-xml'), fs = require('fs');
/**
* @class XFormsEngine
* @param {HttpContext=} context
* @constructor
* @property {HttpContext} context Gets or sets an instance of HttpContext that represents the current HTTP context.
*/
function XFormsEngine(context) {
/**
* @type {HttpContext}
*/
var ctx = context;
Object.defineProperty(this,'context', {
get: function() {
return ctx;
},
set: function(value) {
ctx = value;
},
configurable:false,
enumerable:false
});
}
/**
* Renders the document that exists in the specified path
* @param {String} path - The path where XFORM file exists
* @param {Object} options - An object that represents the options provided for this rendering
*/
XFormsEngine.prototype.render = function(path, options, callback) {
try {
xforms.loadDocument(path,
/**
* @param err
* @param {FormDocument} doc
*/
function(err, doc) {
if (err) {
callback(err);
}
else {
doc.render(null, function(err, result) {
callback(null, result);
});
}
});
}
catch (e) {
callback(e);
}
}
if (typeof exports !== 'undefined') module.exports.createInstance = function(context) {
return new XFormsEngine(context);
};