Skip to content

Commit

Permalink
Extend apiParam type with optional size (e.g. fieldname{0,12}).
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed Sep 17, 2014
1 parent bb80960 commit a37ea8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
28 changes: 17 additions & 11 deletions lib/parsers/api_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function parse(content, source, defaultGroup)
// Replace Linebreak with Unicode
content = content.replace(/\n/g, "\uffff");

// Old-RegExp:
// Old-RegExp:
// var parseRegExp = /^(?:(?:\((.+?)\))\s*)?(?:(?:\{(.+?)\})\s*)?(\[?(\S[a-zA-Z0-9._\-]*)(?:=['|"]?([\s.a-zA-Z0-9_\-]*)['|"]?)?\]?)\s*(.*)?(^@|$)/g;

function _objectValuesToString(obj)
Expand Down Expand Up @@ -44,17 +44,22 @@ function parse(content, source, defaultGroup)
e: "\\s*)?"
},
vBrackets: {
b: "(\\[?", // 3
fieldname: "(\\S[a-zA-Z0-9\/._\\-]*)", // 4
vDefaultValue: {
b: "(?:=['|\"]?",
defaultValue: "(.+?(?=['|\"|\\]]))", // 5
e: "['|\"]?)?"
b: "(\\[?", // 3
fieldname: "(\\S[a-zA-Z0-9\/._\\-]*)", // 4
vSize: {
b: "(?:\\{?",
size: "(.+?)", // 5
e: "\\})?"
},
vDefaultValue: {
b: "(?:=['|\"]?",
defaultValue: "(.+?(?=['|\"|\\]]))", // 6
e: "['|\"]?)?"
},
e: "\\]?)"
},
oWhitespace: "\\s*",
vDescription: "(.*)?", // 6
vDescription: "(.*)?", // 7
e: "(^@|$)"
};
var parseRegExp = new RegExp(_objectValuesToString(regExp));
Expand All @@ -63,17 +68,18 @@ function parse(content, source, defaultGroup)
if( ! matches) return null;

// Reverse Unicode Linebreaks
if(matches[6]) matches[6] = matches[6].replace(/\uffff/g, "\n");
if(matches[7]) matches[7] = matches[7].replace(/\uffff/g, "\n");

group = matches[1] || defaultGroup || "Parameter";

return {
group: group,
type: matches[2],
field: matches[4],
defaultValue: matches[5],
defaultValue: matches[6],
optional: (matches[3] !== matches[4]) ? true : false,
description: matches[6] || ""
size: matches[5],
description: matches[7] || ""
};
} // parse

Expand Down
4 changes: 4 additions & 0 deletions template/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ td {
left: auto;
}

.type-size {
color: #999999;
}

/* ------------------------------------------------------------------------------------------
* apidoc - intro
* ------------------------------------------------------------------------------------------ */
Expand Down
7 changes: 6 additions & 1 deletion template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ <h2>{{__ @key}}</h2>
{{#each this}}
<tr>
<td class="code">{{{splitFill field "." "&nbsp;&nbsp;"}}}{{#if optional}} <span class="label label-optional">{{__ "optional"}}</span>{{/if}}</td>
{{#if ../../_hasType}}<td>{{{type}}}</td>{{/if}}
{{#if ../../_hasType}}
<td>
{{{type}}}
{{#if size}}<span class="type-size">&#123;{{{size}}}&#125;</span>{{/if}}
</td>
{{/if}}
<td>
{{{nl2br description}}}
{{#if defaultValue}}<p class="default-value">{{__ "Default value:"}} <code>{{{defaultValue}}}</code></p>{{/if}}
Expand Down

0 comments on commit a37ea8c

Please sign in to comment.