Skip to content

Commit

Permalink
Start changing apiParam for size.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed Sep 19, 2014
1 parent 77605e5 commit 6e9ad1b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 50 deletions.
47 changes: 30 additions & 17 deletions lib/parsers/api_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ function parse(content, source, defaultGroup)
// Replace Linebreak with Unicode
content = content.replace(/\n/g, "\uffff");

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

function _objectValuesToString(obj)
{
var str = "";
Expand All @@ -21,7 +18,9 @@ function parse(content, source, defaultGroup)
return str;
} // _objectValuesToString

// Search: group, type, field, defaultValue, optional, description
content = "{Number} param35=2 Type, parameter, default value and description.";

// Search: group, type, fieldname, defaultValue, size, description
// Example: {Boolean} [user.name="Default Value"] Users lastname.
var regExp = {
b: "^",
Expand All @@ -43,42 +42,56 @@ function parse(content, source, defaultGroup)
},
e: "\\s*)?"
},
vBrackets: {
vField: {
b: "(\\[?", // 3
fieldname: "(\\S[a-zA-Z0-9\/._\\-]*)", // 4
vSize: {
b: "(?:\\{",
size: "(.+?)", // 5
e: "\\})?"
},
vDefaultValue: {
b: "(?:=['|\"]?",
defaultValue: "(.+?(?=['|\"|\\]]))", // 6
e: "['|\"]?)?"
b: "(?:=",
withQuote: {
b: "(?:['|\"]",
defaultValue: "(.+?(?=['|\"|\\]]))", // 5
e: "['|\"]?)"
},
withoutQuote: {
b: "(?!['|\"]",
defaultValue: "(.+?(?=[\\]|\\s|$]))", // 5
e: "[\\]|\\s|$])"
},
e: ")?"
},
e: "\\]?)"
},
vSize: {
oWhitespace: "\\s*",
b: "(?:\\{",
size: "(.+?)", // 6
e: "\\})?"
},
oWhitespace: "\\s*",
vDescription: "(.*)?", // 7
e: "(^@|$)"
e: "(^@|$)" // 8 ???
};
var parseRegExp = new RegExp(_objectValuesToString(regExp));
var matches = parseRegExp.exec(content);

if( ! matches) return null;

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

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

//if (content.substr(0, 16) === "{Number} param35") {
console.log(matches);
process.exit(1);

return {
group: group,
type: matches[2],
field: matches[4],
defaultValue: matches[6],
defaultValue: matches[5],
optional: (matches[3] && matches[3][0] === "[") ? true : false,
size: matches[5],
size: matches[6],
description: matches[7] || ""
};
} // parse
Expand Down
10 changes: 3 additions & 7 deletions template/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body {
max-width: 1280px;
}

body, p, a, div, th, td {
body, p, a, div, th, td {
font-family: "Source Sans Pro", sans-serif;
font-weight: 400;
font-size: 16px;
Expand Down Expand Up @@ -125,10 +125,6 @@ td {
left: auto;
}

.type-size {
color: #999999;
}

/* ------------------------------------------------------------------------------------------
* apidoc - intro
* ------------------------------------------------------------------------------------------ */
Expand Down Expand Up @@ -469,10 +465,10 @@ tr.del td {
}

@keyframes bouncedelay {
0%, 80%, 100% {
0%, 80%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
} 40% {
} 40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
Expand Down
20 changes: 10 additions & 10 deletions template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h1>{{underscoreToSpace article.group}}{{#if article.title}} - {{article.title}}

{{#if article.permission.name}}
<p>
{{__ "Permission:"}}
{{__ "Permission:"}}
{{article.permission.name}}

{{#if article.permission.description}}
Expand All @@ -146,7 +146,7 @@ <h1>{{underscoreToSpace article.group}}{{#if article.title}} - {{article.title}}
</li>
{{/each}}
</ul>

<div class="tab-content">
{{#each article.examples}}
<div class="tab-pane{{#if_eq @index compare=0}} active{{/if_eq}}" id="examples-{{../id}}-{{@index}}">
Expand Down Expand Up @@ -186,12 +186,12 @@ <h2>{{__ @key}}</h2>
{{#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}}
{{#if size}}<p class="type-size">{{__ "Size range:"}} <code>{{{size}}}</code></p>{{/if}}
</td>
</tr>
{{/each}}
Expand All @@ -207,7 +207,7 @@ <h2>{{__ @key}}</h2>
</li>
{{/each}}
</ul>

<div class="tab-content">
{{#each params.examples}}
<div class="tab-pane{{#if_eq @index compare=0}} active{{/if_eq}}" id="{{../section}}-examples-{{../id}}-{{@index}}">
Expand All @@ -233,7 +233,7 @@ <h2>{{__ "Send a Sample Request"}}</h2>
</div>
</div>
</div>

{{#each article.parameter.fields.Parameter}}
<div class="control-group">
<label class="control-label" for="sample-request-field-{{field}}">{{field}}</label>
Expand Down Expand Up @@ -262,7 +262,7 @@ <h3>

</fieldset>
</form>
{{/if}}
{{/if}}
</script>

<script id="template-compare-article" type="text/x-handlebars-template">
Expand Down Expand Up @@ -363,7 +363,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl
<script id="template-article-compare-permission" type="text/x-handlebars-template">
{{#if article.permission.name}}
<p>
{{__ "Permission:"}}
{{__ "Permission:"}}
{{#if compare.permission.name}}

{{{showDiff article.permission.name compare.permission.name}}}
Expand Down Expand Up @@ -393,7 +393,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl
{{else}}
{{#if article.permission}}
<p>
{{__ "Permission:"}}
{{__ "Permission:"}}
{{#if compare.permission.name}}
<ins>
{{{article.permission}}}
Expand All @@ -414,7 +414,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl
{{else}}
{{#if compare.permission.name}}
<p>
{{__ "Permission:"}}
{{__ "Permission:"}}

<del>
<br>
Expand All @@ -432,7 +432,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl
<del>
{{{compare.permission}}}
</del>
</p>
</p>
{{/if}}
{{/if}}
{{/if}}
Expand Down
57 changes: 41 additions & 16 deletions test/fixtures/example/param.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,50 @@
* @apiVersion 0.1.1
* @apiDescription Parameters and different Versions: 0.1.1
*
* @apiParam {String} param1 Parameter with type and description.
* @apiParam {String} param2
* @apiParam {String} param3="Default Value" Parameter with type, description and default value.
* @apiParam {String} param4="Default Value"
* @apiParam param1 Parameter and description.
* @apiParam param2
* @apiParam param3="Default Value" Parameter, default value and description.
* @apiParam param4="Default Value"
*
* @apiParam param5 Basic Parameter with description.
* @apiParam param6
* @apiParam param7="Default Value" Basic Parameter with description and default value.
* @apiParam param8="Default Value"
* @apiParam [param5] Optional parameter and description.
* @apiParam [param6]
* @apiParam [param7="Default Value"] Optional parameter, default value and description.
* @apiParam [param8="Default Value"]
*
* @apiParam [param9] Optional basic Parameter with description.
* @apiParam [param10]
* @apiParam [param11="Default Value"] Optional basic Parameter with description and default value.
* @apiParam [param12="Default Value"]
* @apiParam param9 (4711) Parameter, allowed value and description.
* @apiParam param10 (4711)
* @apiParam param11="Default Value" (4711) Parameter, default value, allowed value and description.
* @apiParam param12="Default Value" (4711)
*
* @apiParam {String} [param13] Optional Parameter with type and description.
* @apiParam {String} [param14]
* @apiParam {String} [param15="Default Value"] Optional Parameter with type, description and default value.
* @apiParam {String} [param16="Default Value"]
* @apiParam {String} param13 Type, parameter and description.
* @apiParam {String} param14
* @apiParam {String} param15="Default Value" Type, parameter and default value.
* @apiParam {String} param16="Default Value"
*
* @apiParam {String} [param17] Type, optional parameter and description.
* @apiParam {String} [param18]
* @apiParam {String} [param19="Default Value"] Type, optional parameter, default value and description.
* @apiParam {String} [param20="Default Value"]
*
* @apiParam {String} param21 (4711) Type, parameter, allowed value and description.
* @apiParam {String} param22 (4711)
* @apiParam {String} param23="Default Value" (4711) Type, parameter, default value, allowed value and description.
* @apiParam {String} param24="Default Value" (4711)
*
* @apiParam {String} [param25] (4711) Type, optional parameter, allowed value and description.
* @apiParam {String} [param26] (4711)
* @apiParam {String} [param27="Default Value"] (4711) Type, optional parameter, default value, allowed value and description.
* @apiParam {String} [param28="Default Value"] (4711)
*
* @apiParam {String} [param29] ("allowed1", "allowed2") Type, optional parameter, allowed strings and description.
* @apiParam {String} [param30] ("allowed1", "allowed2")
* @apiParam {String} [param31="Default Value"] ("allowed1", "allowed2") Type, optional parameter, default value, allowed strings and description.
* @apiParam {String} [param32="Default Value"] ("allowed1", "allowed2")
*
* @apiParam {String} param33="Default Value" {4,8} Type, parameter, default value, size and description.
* @apiParam {Number} param34=1 {1-3} Type, parameter, default value, size and description.
* @apiParam {Number} param35=2 Type, parameter, default value and description.
* @apiParam {Number} param36=2
*/

/**
Expand Down

0 comments on commit 6e9ad1b

Please sign in to comment.