1
0
Fork 0
forked from 0x2620/oxjs

less obscure Ox.map

This commit is contained in:
rolux 2012-05-22 16:29:37 +02:00
commit 12cf77cef5
21 changed files with 125 additions and 101 deletions

View file

@ -42,7 +42,7 @@ Ox.doc <f> Generates documentation for annotated JavaScript
Ox.doc = (function() {
// fixme: dont require the trailing '@'
var re = {
item: /^(.+?) <(.+?)> (.+)$/,
item: /^(.+?) <(.+?)>(.*?)$/,
multiline: /^\/\*\@.*?\n([\w\W]+)\n.*?\@\*\/$/,
script: /\n(\s*<script>s*\n[\w\W]+\n\s*<\/script>s*)/g,
singleline: /^\/\/@\s*(.*?)\s*$/,
@ -122,9 +122,10 @@ Ox.doc = (function() {
var lines = decodeLinebreaks(str).split('\n'),
indent = getIndent(lines[1]);
return {
statement: Ox.map(lines, function(line, i) {
return i && i < lines.length - 1 ?
line.substr(indent) : null;
statement: Ox.filter(lines, function(line, i) {
return i && i < lines.length - 1;
}).map(lines, function(line, i) {
return line.substr(indent);
}).join('\n')
};
}
@ -336,7 +337,7 @@ Ox.minify = function() {
'number', 'method', 'object', 'property'
].indexOf(token.type) > -1;
}
return Ox.map(tokens, function(token, i) {
return Ox.filter(Ox.map(tokens, function(token, i) {
var ret = source.substr(token.offset, token.length);
if (token.type == 'comment') {
if (ret[1] == '/') {
@ -348,8 +349,7 @@ Ox.minify = function() {
ret = i == length - 1 || tokens[i + 1].type == 'whitespace'
? null : ' ';
}
}
if (token.type == 'linebreak' || token.type == 'whitespace') {
} else if (token.type == 'linebreak' || token.type == 'whitespace') {
// remove consecutive linebreaks or whitespace
ret = ret[0];
}
@ -392,7 +392,7 @@ Ox.minify = function() {
ret = null;
}
return ret;
}).join('');
})).join('');
}
};