Browse Source

implement documentation generator function in JavaScript

JSON-35
Roker 5 years ago
parent
commit
f618b2d390
2 changed files with 81 additions and 2 deletions
  1. +17
    -2
      html/index.html
  2. +64
    -0
      html/interactive.js

+ 17
- 2
html/index.html View File

@ -22,7 +22,9 @@
</head>
<body>
<h1>Send example calls via jQuery – <span id="spn_version">(no JavaScript?)</span></h1>
<h1>p≡p JSON Server Adapter – <span id="spn_version">(no JavaScript?)</span></h1>
<h2>1. Send example calls via jQuery</h2>
<form id="frm" name="frm">
@ -47,9 +49,22 @@
</form>
<form id="frm_2" name="frm_2">
<textarea placeholder="Just a scratchboard for text copy & paste :-)" rows="20" cols="88">
<textarea placeholder="Just a scratchboard for text copy & paste :-)" rows="12" cols="80">
</textarea>
</form>
<hr>
<h2>2. Generate documentation</h2>
<form id="frm_doc" name="frm_doc">
Select output format:
<select id="doc_format" size="1">
<option value="html" checked>HTML Table</option>
<option value="md" >Markdown Table</option>
<option value="trac" >Trac Table</option>
</select>
<button type="button" name="btn_doc" onclick="create_doc()">Create!</button></dd>
</form>
<div id="doc_out" style="background-color:white;border:1px black solid; padding:10px;"></div>
<script type="text/javascript">
init_pep_functions();


+ 64
- 0
html/interactive.js View File

@ -500,3 +500,67 @@ function init_pep_functions()
document.getElementById("fn_name").innerHTML = optionList;
document.getElementById("spn_version").innerHTML = "version: " + server_version;
}
function create_doc()
{
var table_def = {
html : { start : '<table class="dtable">', end: '</table>\n',
header : '<tr><th>Function name</th><th>Return Type</th><th>Parameters</th></tr>\n',
line_start : '<tr>', line_end : '</tr>\n',
cell_start : '<td>' , cell_end : '</td>'
},
md : { start: '', end: '\n',
header : '| Function name | Return Type | Parameters |\n' +
'|---------------|-------------|------------|\n',
line_start : '', line_end : '|\n',
cell_start : '| ', cell_end: ' '
},
trac : { start: '', end: '\n',
header : '||= Function name =||= Return Type =||= Parameters =||\n',
line_start : '|', line_end : '|\n',
cell_start : '| ', cell_end: ' |'
}
};
var format_name = document.getElementById('doc_format').value;
var format_def = table_def[format_name];
var output = "";
for(var i=0, len=pep_functions.length; i<len; ++i)
{
var f = pep_functions[i];
if(f.separator)
{
output += format_def.end + "\n" + f.name + "\n" + format_def.start + format_def.header;
}else{
output += format_def.line_start
+ format_def.cell_start + f.name + format_def.cell_end
+ format_def.cell_start + f["return"] + format_def.cell_end
+ format_def.cell_start ;
for( var p=0, plen = f.params.length; p<plen; ++p)
{
if(p>0) output += ', ';
output += f.params[p].type;
switch(f.params[p].direction)
{
case 'In' : break;
case 'Out' : output += '⇑'; break;
case 'InOut' : output += '⇕'; break;
}
}
output += format_def.cell_end + format_def.line_end;
}
}
if(format_name != "html")
output = "<pre>" + output + "\n</pre>";
document.getElementById("doc_out").innerHTML =
'<h4>Function reference for the p≡p JSON Server Adapter. Version “' + server_version + '”</h4>'
+ 'Output parameters are denoted by a <b>⇑</b>, InOut parameters are denoted by a <b>⇕</b> after the parameter type.<br>'
+ output;
}

Loading…
Cancel
Save