Merge pull request #1609 from xtuple/4_5_x
[xtuple] / scripts / templates / xtuple_specs / tmpl / properties.tmpl
1 <?js
2     var props = obj;
3     var endUser = env.conf.templates.endUser;
4     
5     /* sort subprops under their parent props (like opts.classname) */
6     var parentProp = null;
7     props.forEach(function(prop, i) {
8         if (!prop) { return; }
9         if ( parentProp && prop.name && prop.name.indexOf(parentProp.name + '.') === 0 ) {
10             prop.name = prop.name.substr(parentProp.name.length+1);
11             parentProp.subprops = parentProp.subprops || [];
12             parentProp.subprops.push(prop);
13             props[i] = null;
14         }
15         else {
16             parentProp = prop;
17         }
18     });
19     
20     /* determine if we need extra columns, "attributes" and "default" */
21     props.hasAttributes = false;
22     props.hasDefault = false;
23     props.hasName = false;
24     
25     props.forEach(function(prop) {
26         if (!prop) { return; }
27         
28         if (prop.optional || prop.nullable) {
29             props.hasAttributes = true;
30         }
31         
32         if (prop.name) {
33             props.hasName = true;
34         }
35         
36         if (typeof prop.defaultvalue !== 'undefined') {
37             props.hasDefault = true;
38         }
39     });
40 ?>
41
42 <table class="props">
43     <thead>
44         <tr>
45                 <?js if (props.hasName) {?>
46                 <th>Name</th>
47                 <?js } ?>
48                 
49                 <?js if (!endUser) {?>
50                 <th>Type</th>
51                 <?js } ?>
52                 
53                 <?js if (props.hasAttributes) {?>
54                 <th>Argument</th>
55                 <?js } ?>
56                 
57                 <?js if (props.hasDefault) {?>
58                 <th>Default</th>
59                 <?js } ?>
60                 
61                 <th class="last">Reference</th>
62         </tr>
63         </thead>
64         
65         <tbody>
66         <?js
67         var self = this;
68             props.forEach(function(prop) {
69                 if (!prop) { return; }
70             if (!prop.description) {
71               // don't futz with a falsy description
72             } else if(endUser && prop.description.indexOf("()") >= 0) {
73               // () means: don't display this prop at all to the end user
74               return;
75             } else if(endUser) {
76               // don't show square-bracketed text to end users.
77               prop.description = prop.description.replace(/\[.*?\]/, "");
78               prop.description = prop.description.replace("(", "").replace(")", "");
79             } else {
80               prop.description = prop.description.replace(/\(.*?\)/, "");
81               prop.description = prop.description.replace("[", "").replace("]", "");
82             }
83         ?>
84         
85         <tr>
86             <?js if (props.hasName) {?>
87                 <td class="name"><code><?js= prop.name ?></code></td>
88             <?js } ?>
89             
90             <?js if (!endUser) {?>
91                 <td class="type">
92                 <?js if (prop.type && prop.type.names) {?>
93                     <?js= self.partial('type.tmpl', prop.type.names) ?>
94                 <?js } ?>
95                 </td>
96             <?js } ?>
97             
98             <?js if (props.hasAttributes) {?>
99                 <td class="attributes">
100                 <?js if (prop.optional) { ?>
101                     &lt;optional><br>
102                 <?js } ?>
103                     
104                 <?js if (prop.nullable) { ?>
105                     &lt;nullable><br>
106                 <?js } ?>
107                 </td>
108             <?js } ?>
109             
110             <?js if (props.hasDefault) {?>
111                 <td class="default">
112                 <?js if (typeof prop.defaultvalue !== 'undefined') { ?>
113                     <?js= self.htmlsafe(prop.defaultvalue) ?>
114                 <?js } ?>
115                 </td>
116             <?js } ?>
117             
118             <td class="description last"><?js= prop.description ?><?js if (prop.subprops) { ?>
119                 <h6>Properties</h6><?js= self.partial('properties.tmpl', prop.subprops) ?>
120             <?js } ?></td>
121         </tr>
122         
123         <?js }); ?>
124         </tbody>
125 </table>