diff --git a/lib/parsers/api_param.js b/lib/parsers/api_param.js index fb2cd303..ed3d990b 100644 --- a/lib/parsers/api_param.js +++ b/lib/parsers/api_param.js @@ -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 = ""; @@ -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: "^", @@ -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 diff --git a/template/css/style.css b/template/css/style.css index 2c9c9164..b0133657 100644 --- a/template/css/style.css +++ b/template/css/style.css @@ -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; @@ -125,10 +125,6 @@ td { left: auto; } -.type-size { - color: #999999; -} - /* ------------------------------------------------------------------------------------------ * apidoc - intro * ------------------------------------------------------------------------------------------ */ @@ -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); } diff --git a/template/index.html b/template/index.html index bb01cff6..9ca13f81 100644 --- a/template/index.html +++ b/template/index.html @@ -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}} @@ -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}}"> @@ -186,12 +186,12 @@ <h2>{{__ @key}}</h2> {{#if ../../_hasType}} <td> {{{type}}} - {{#if size}}<span class="type-size">{{{{size}}}}</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}} @@ -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}}"> @@ -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> @@ -262,7 +262,7 @@ <h3> </fieldset> </form> - {{/if}} + {{/if}} </script> <script id="template-compare-article" type="text/x-handlebars-template"> @@ -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}}} @@ -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}}} @@ -414,7 +414,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl {{else}} {{#if compare.permission.name}} <p> - {{__ "Permission:"}} + {{__ "Permission:"}} <del> <br> @@ -432,7 +432,7 @@ <h1>{{underscoreToSpace article.group}} - {{{showDiff article.title compare.titl <del> {{{compare.permission}}} </del> - </p> + </p> {{/if}} {{/if}} {{/if}} diff --git a/test/fixtures/example/param.js b/test/fixtures/example/param.js index 835d743f..45fb478b 100644 --- a/test/fixtures/example/param.js +++ b/test/fixtures/example/param.js @@ -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 */ /**