1 | var marko = require("../");
|
2 |
|
3 | function defineRenderer(def) {
|
4 | var template = def.template;
|
5 | var getTemplateData = def.getTemplateData;
|
6 | var renderer = def.renderer;
|
7 |
|
8 | if (typeof template === "string") {
|
9 | template = marko.load(template);
|
10 | }
|
11 |
|
12 | var createOut;
|
13 |
|
14 | if (template) {
|
15 | createOut = template.createOut;
|
16 | } else {
|
17 | createOut = def.createOut || marko.createOut;
|
18 | }
|
19 |
|
20 | if (!renderer) {
|
21 |
|
22 |
|
23 |
|
24 | renderer = function renderer(input, out) {
|
25 | var newProps = input;
|
26 |
|
27 | if (!newProps) {
|
28 |
|
29 | newProps = {};
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | var templateData = getTemplateData
|
36 | ? getTemplateData(newProps, out)
|
37 | : newProps;
|
38 |
|
39 |
|
40 |
|
41 | template.render(templateData, out);
|
42 | };
|
43 | }
|
44 |
|
45 | renderer.render = function(input) {
|
46 | var out = createOut();
|
47 | renderer(input, out);
|
48 | return out.end();
|
49 | };
|
50 |
|
51 | return renderer;
|
52 | }
|
53 |
|
54 | module.exports = defineRenderer;
|