rename vars
This commit is contained in:
parent
84050d67a3
commit
b1ff236b3f
1 changed files with 27 additions and 26 deletions
|
@ -61,13 +61,13 @@ Ox.doc = (function() {
|
||||||
function encodeLinebreaks(match, submatch) {
|
function encodeLinebreaks(match, submatch) {
|
||||||
return '\n' + (submatch || match).replace(/\n/g, '\u21A9');
|
return '\n' + (submatch || match).replace(/\n/g, '\u21A9');
|
||||||
}
|
}
|
||||||
function getIndent(str) {
|
function getIndent(string) {
|
||||||
var indent = -1;
|
var indent = -1;
|
||||||
while (str[++indent] == ' ') {}
|
while (string[++indent] == ' ') {}
|
||||||
return indent;
|
return indent;
|
||||||
}
|
}
|
||||||
function parseItem(str) {
|
function parseItem(string) {
|
||||||
var matches = re.item.exec(str);
|
var matches = re.item.exec(string);
|
||||||
// to tell a variable with default value, like
|
// to tell a variable with default value, like
|
||||||
// name <string|'<a href="...">foo</a>'> summary
|
// name <string|'<a href="...">foo</a>'> summary
|
||||||
// from a line of description with tags, like
|
// from a line of description with tags, like
|
||||||
|
@ -82,9 +82,9 @@ Ox.doc = (function() {
|
||||||
summary: matches[3].trim()
|
summary: matches[3].trim()
|
||||||
}, parseType(matches[2])) : null;
|
}, parseType(matches[2])) : null;
|
||||||
}
|
}
|
||||||
function parseName(str) {
|
function parseName(string) {
|
||||||
var matches = re.usage.exec(str);
|
var matches = re.usage.exec(string);
|
||||||
return matches ? matches[0] : str;
|
return matches ? matches[0] : string;
|
||||||
}
|
}
|
||||||
function parseNode(node) {
|
function parseNode(node) {
|
||||||
var item = parseItem(node.line), subitem;
|
var item = parseItem(node.line), subitem;
|
||||||
|
@ -117,9 +117,9 @@ Ox.doc = (function() {
|
||||||
});
|
});
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
function parseScript(str) {
|
function parseScript(string) {
|
||||||
// remove script tags and extra indentation
|
// remove script tags and extra indentation
|
||||||
var lines = decodeLinebreaks(str).split('\n'),
|
var lines = decodeLinebreaks(string).split('\n'),
|
||||||
indent = getIndent(lines[1]);
|
indent = getIndent(lines[1]);
|
||||||
return {
|
return {
|
||||||
statement: lines.slice(1, -1).map(function(line, i) {
|
statement: lines.slice(1, -1).map(function(line, i) {
|
||||||
|
@ -182,9 +182,9 @@ Ox.doc = (function() {
|
||||||
});
|
});
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
function parseTest(str) {
|
function parseTest(string) {
|
||||||
// fixme: we cannot properly handle tests where a string contains '\n '
|
// fixme: we cannot properly handle tests where a string contains '\n '
|
||||||
var lines = decodeLinebreaks(str).split('\n ');
|
var lines = decodeLinebreaks(string).split('\n ');
|
||||||
return {
|
return {
|
||||||
statement: lines[0].slice(2),
|
statement: lines[0].slice(2),
|
||||||
result: lines[1].trim()
|
result: lines[1].trim()
|
||||||
|
@ -249,24 +249,24 @@ Ox.doc = (function() {
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
function parseType(str) {
|
function parseType(string) {
|
||||||
// returns {types: [""]}
|
// returns {types: [""]}
|
||||||
// or {types: [""], default: ""}
|
// or {types: [""], default: ""}
|
||||||
// or {types: [""], super: ""}
|
// or {types: [""], super: ""}
|
||||||
var isArray,
|
var array,
|
||||||
|
isArray,
|
||||||
ret = {types: []},
|
ret = {types: []},
|
||||||
split,
|
|
||||||
type;
|
type;
|
||||||
// only split by ':' if there is no default string value
|
// only split by ':' if there is no default string value
|
||||||
if ('\'"'.indexOf(str.slice(-2, -1)) == -1) {
|
if ('\'"'.indexOf(string.slice(-2, -1)) == -1) {
|
||||||
split = str.split(':');
|
array = string.split(':');
|
||||||
str = split[0];
|
string = array[0];
|
||||||
if (split.length == 2) {
|
if (array.length == 2) {
|
||||||
ret.super = split[1];
|
ret.super = array[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str.split('|').forEach(function(str) {
|
string.split('|').forEach(function(string) {
|
||||||
var unwrapped = unwrap(str);
|
var unwrapped = unwrap(string);
|
||||||
if (unwrapped in types) {
|
if (unwrapped in types) {
|
||||||
ret.types.push(wrap(types[unwrapped]))
|
ret.types.push(wrap(types[unwrapped]))
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -276,14 +276,15 @@ Ox.doc = (function() {
|
||||||
) {
|
) {
|
||||||
ret.types.push(wrap(type[0]));
|
ret.types.push(wrap(type[0]));
|
||||||
} else {
|
} else {
|
||||||
ret['default'] = str;
|
ret['default'] = string;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function unwrap(str) {
|
function unwrap(string) {
|
||||||
return (isArray = /^\[.+\]$/.test(str)) ? str.slice(1, -1) : str;
|
return (isArray = /^\[.+\]$/.test(string))
|
||||||
|
? string.slice(1, -1) : string;
|
||||||
}
|
}
|
||||||
function wrap(str) {
|
function wrap(string) {
|
||||||
return isArray ? '[' + str + 's' + ']' : str;
|
return isArray ? '[' + string + 's' + ']' : string;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue