add geo module documentation and tests
This commit is contained in:
parent
7c3a40368f
commit
43fa75c8db
8 changed files with 203 additions and 98 deletions
|
@ -4,7 +4,13 @@ Ox.load('UI', {
|
|||
}, function() {
|
||||
Ox.Theme('classic');
|
||||
Ox.DocPanel({
|
||||
files: ['Ox.js', 'Ox.UI/js/Map/Ox.Map.js', 'Ox.UI/js/Core/Ox.Element.js', 'Ox.UI/js/Core/Ox.JQueryElement.js'],
|
||||
files: [
|
||||
'Ox.js',
|
||||
'Ox.Geo/Ox.Geo.js',
|
||||
'Ox.UI/js/Map/Ox.Map.js',
|
||||
'Ox.UI/js/Core/Ox.Element.js',
|
||||
'Ox.UI/js/Core/Ox.JQueryElement.js'
|
||||
],
|
||||
getModule: function(item) {
|
||||
var file = item.file.replace(Ox.PATH, '');
|
||||
return file == 'Ox.js' ? 'Ox' : file.split('/')[0];
|
||||
|
|
|
@ -2,99 +2,114 @@ Ox.load('UI', {
|
|||
debug: true,
|
||||
theme: 'classic'
|
||||
}, function() {
|
||||
var colors = [
|
||||
[[255, 64, 64], [224, 32, 32]],
|
||||
[[64, 192, 64], [32, 160, 32]]
|
||||
],
|
||||
gradients = [
|
||||
'-moz-linear-gradient(',
|
||||
'-webkit-gradient(linear, '
|
||||
];
|
||||
var $foo = $('<div>')
|
||||
.css({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
overflowY: 'scroll'
|
||||
})
|
||||
.appendTo(Ox.UI.$body);
|
||||
Ox.test(Ox.PATH + 'Ox.js', function(tests) {
|
||||
var total = tests.length,
|
||||
succeeded = tests.filter(function(test) {
|
||||
return test.success;
|
||||
}).length,
|
||||
failed = total - succeeded,
|
||||
names = Ox.unique(tests.map(function(test) {
|
||||
return test.name;
|
||||
})).sort();
|
||||
testsByName = {};
|
||||
tests.forEach(function(test) {
|
||||
if (!(test.name in testsByName)) {
|
||||
testsByName[test.name] = [];
|
||||
}
|
||||
testsByName[test.name].push(test);
|
||||
Ox.load('Geo', function() {
|
||||
var $div = $('<div>')
|
||||
.css({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
overflowY: 'scroll'
|
||||
})
|
||||
.appendTo(Ox.UI.$body),
|
||||
colors = [
|
||||
[[255, 64, 64], [224, 32, 32]],
|
||||
[[64, 192, 64], [32, 160, 32]]
|
||||
],
|
||||
counter = 0,
|
||||
files = [
|
||||
Ox.PATH + 'Ox.js',
|
||||
Ox.PATH + 'Ox.Geo/Ox.Geo.js'
|
||||
],
|
||||
tests = [];
|
||||
files.forEach(function(file) {
|
||||
Ox.test(file, function(fileTests) {
|
||||
tests = Ox.merge(tests, fileTests);
|
||||
if (++counter == files.length) {
|
||||
renderTests();
|
||||
}
|
||||
});
|
||||
});
|
||||
getBar(total == succeeded)
|
||||
.html(
|
||||
'<b>' + total + ' tests, ' +
|
||||
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
||||
)
|
||||
.appendTo($foo);
|
||||
names.forEach(function(name) {
|
||||
var tests = testsByName[name],
|
||||
total = tests.length,
|
||||
function renderTests() {
|
||||
var total = tests.length,
|
||||
succeeded = tests.filter(function(test) {
|
||||
return test.success;
|
||||
}).length,
|
||||
failed = total - succeeded,
|
||||
classname = name.replace('.', '');
|
||||
names = Ox.unique(tests.map(function(test) {
|
||||
return test.name;
|
||||
})).sort();
|
||||
testsByName = {};
|
||||
tests.forEach(function(test) {
|
||||
if (!(test.name in testsByName)) {
|
||||
testsByName[test.name] = [];
|
||||
}
|
||||
testsByName[test.name].push(test);
|
||||
});
|
||||
getBar(total == succeeded)
|
||||
.html(
|
||||
'<b>' + name + '</b> — ' + total +
|
||||
' test' + (total == 1 ? '' : 's') + ', ' +
|
||||
'<b>' + total + ' tests, ' +
|
||||
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
||||
)
|
||||
.click(function() {
|
||||
$('.' + classname).toggle();
|
||||
})
|
||||
.appendTo($foo);
|
||||
tests.forEach(function(test) {
|
||||
getBar(test.success, true)
|
||||
.addClass(classname)
|
||||
.appendTo($div);
|
||||
names.forEach(function(name) {
|
||||
var tests = testsByName[name],
|
||||
total = tests.length,
|
||||
succeeded = tests.filter(function(test) {
|
||||
return test.success;
|
||||
}).length,
|
||||
failed = total - succeeded,
|
||||
classname = name.replace('.', '');
|
||||
getBar(total == succeeded)
|
||||
.html(
|
||||
Ox.repeat(' ', 4) +
|
||||
'<b>> ' + Ox.encodeHTML(test.statement) + ' </b> ==> ' +
|
||||
(test.success ? '' : Ox.encodeHTML(test.actual) + ' !=> ') +
|
||||
Ox.encodeHTML(test.expected)
|
||||
'<b>' + name + '</b> — ' + total +
|
||||
' test' + (total == 1 ? '' : 's') + ', ' +
|
||||
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
||||
)
|
||||
.hide()
|
||||
.appendTo($foo);
|
||||
.click(function() {
|
||||
$('.' + classname).toggle();
|
||||
})
|
||||
.appendTo($div);
|
||||
tests.forEach(function(test) {
|
||||
getBar(test.success, true)
|
||||
.addClass(classname)
|
||||
.html(
|
||||
Ox.repeat(' ', 4) +
|
||||
'<b>> ' + Ox.encodeHTML(test.statement) + ' </b> ==> ' +
|
||||
(test.success ? '' : Ox.encodeHTML(test.actual) + ' !=> ') +
|
||||
Ox.encodeHTML(test.expected)
|
||||
)
|
||||
.hide()
|
||||
.appendTo($div);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
function getBar(success, darker) {
|
||||
var $div = $('<div>')
|
||||
.css({
|
||||
width: window.innerWidth - Ox.UI.SCROLLBAR_SIZE,
|
||||
height: '15px',
|
||||
padding: '4px 8px 4px 8px',
|
||||
fontFamily: 'Menlo, Monaco, Courier',
|
||||
fontSize: '12px',
|
||||
whiteSpace: 'nowrap',
|
||||
MozUserSelect: 'text',
|
||||
WebkitUserSelect: 'text'
|
||||
});
|
||||
gradients.forEach(function(gradient) {
|
||||
$div.css({
|
||||
background: gradient + 'left top, left bottom, from(rgb(' +
|
||||
getColor(success, 0) + ')), to(rgb(' +
|
||||
getColor(success, 1) + ')))'
|
||||
});
|
||||
});
|
||||
function getColor(success, i) {
|
||||
return colors[+success][i].map(function(color) {
|
||||
return color - (darker || 0) * 32;
|
||||
}).join(', ')
|
||||
}
|
||||
return $div;
|
||||
}
|
||||
});
|
||||
function getBar(success, darker) {
|
||||
var $div = $('<div>')
|
||||
.css({
|
||||
width: window.innerWidth - Ox.UI.SCROLLBAR_SIZE,
|
||||
height: '15px',
|
||||
padding: '4px 8px 4px 8px',
|
||||
fontFamily: 'Menlo, Monaco, Courier',
|
||||
fontSize: '12px',
|
||||
whiteSpace: 'nowrap',
|
||||
MozUserSelect: 'text',
|
||||
WebkitUserSelect: 'text'
|
||||
});
|
||||
['moz', 'webkit'].forEach(function(browser) {
|
||||
Ox.print('-' + browser + '-linear-gradient(left top, left bottom, rgb(' +
|
||||
getColor(success, 0) + '), rgb(' +
|
||||
getColor(success, 1) + '))')
|
||||
$div.css({
|
||||
background: '-' + browser + '-linear-gradient(top, rgb(' +
|
||||
getColor(success, 0) + '), rgb(' +
|
||||
getColor(success, 1) + '))'
|
||||
});
|
||||
});
|
||||
function getColor(success, i) {
|
||||
return colors[+success][i].map(function(color) {
|
||||
return color - (darker || 0) * 32;
|
||||
}).join(', ')
|
||||
}
|
||||
return $div;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,8 +2,79 @@ Ox.load.Geo = function(options, callback) {
|
|||
|
||||
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) {
|
||||
|
||||
//@ Constants ----------------------------------------------------------
|
||||
|
||||
/*@
|
||||
Ox.COUNTRIES <[o]> Array of countries
|
||||
area <n> Area of the country in square meters
|
||||
code <s> ISO 3166 country code
|
||||
dependencies <[s]> Array of dependencies of the country (country codes)
|
||||
dependency <[s]> Array of countries the country is a dependency of (country codes)
|
||||
east <n> Longitude of eastern boundary in deg
|
||||
former <b> True if the country is a former country
|
||||
imageURLs <o> Collection of dataURLs
|
||||
marker <s> Map marker
|
||||
imdbCode <s> IMDb country code
|
||||
imdbName <s> IMDb country name
|
||||
lat <n> Latitude of the center in deg
|
||||
lng <n> Longitude of the center in deg
|
||||
name <s> Name
|
||||
north <n> Latitude of northern boundary in deg
|
||||
other <b> True if the country is an "other entity" (EU, FX, UK)
|
||||
south <n> Latitude of southern boundary in deg
|
||||
wikipediaURL <s> URL of the wikipedia article for the country
|
||||
west <n> Longitude of western boundary in deg
|
||||
<script>
|
||||
Ox.test.array = [
|
||||
// Current independent countries with dependencies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return c.dependencies.length && !c.former && !c.other;
|
||||
}).length,
|
||||
// Current independent countries without dependencies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return !c.dependencies.length && !c.dependency.length &&
|
||||
!c.former && !c.other;
|
||||
}).length,
|
||||
// Current dependecies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return c.dependency.length && !c.former && !c.other;
|
||||
}).length,
|
||||
// Former independent countries with dependencies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return c.dependencies.length && c.former && !c.other;
|
||||
}).length,
|
||||
// Former independent countries without dependencies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return !c.dependencies.length && !c.dependency.length &&
|
||||
c.former && !c.other;
|
||||
}).length,
|
||||
// Former dependecies
|
||||
Ox.COUNTRIES.filter(function(c) {
|
||||
return c.dependency.length && c.former && !c.other;
|
||||
}).length,
|
||||
// Other entities
|
||||
Ox.COUNTRIES.filter(function(c) { return c.other; }).length
|
||||
];
|
||||
</script>
|
||||
> Ox.COUNTRIES.length
|
||||
311
|
||||
> Ox.sum(Ox.test.array)
|
||||
311
|
||||
> Ox.test.array
|
||||
[15, 189, 74, 1, 16, 13, 3]
|
||||
@*/
|
||||
Ox.COUNTRIES = data;
|
||||
|
||||
//@ Functions ----------------------------------------------------------
|
||||
|
||||
/*@
|
||||
Ox.getCountryByCode <f> Returns a country object for a given country code
|
||||
(code) -> <o> Country object
|
||||
code <s> ISO 3166 country code
|
||||
> Ox.getCountryByCode('US').name
|
||||
'United States'
|
||||
@*/
|
||||
|
||||
Ox.getCountryByCode = function(code) {
|
||||
var country;
|
||||
Ox.forEach(Ox.COUNTRIES, function(c) {
|
||||
|
@ -15,6 +86,14 @@ Ox.load.Geo = function(options, callback) {
|
|||
return country;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.getCountryByName <f> Returns a country object for a given country name
|
||||
(name) -> <o> Country object
|
||||
name <s> Country name
|
||||
> Ox.getCountryByName('United States').code
|
||||
'US'
|
||||
@*/
|
||||
|
||||
Ox.getCountryByName = function(name) {
|
||||
var country;
|
||||
Ox.forEach(Ox.COUNTRIES, function(c) {
|
||||
|
|
|
@ -274,7 +274,8 @@ Ox.BlockTimeline = function(options, self) {
|
|||
self.$tooltip.options({
|
||||
title: subtitle ?
|
||||
'<span class=\'OxBright\'>' +
|
||||
Ox.highlight(subtitle.value, self.options.find).replace(/\n/g, '<br/>') + '</span><br/>' +
|
||||
Ox.highlight(subtitle.value, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
||||
'</span><br/>' +
|
||||
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
||||
Ox.formatDuration(position, 3)
|
||||
})
|
||||
|
|
|
@ -54,7 +54,7 @@ Ox.LargeTimeline = function(options, self) {
|
|||
left: (v['in'] * self.fps) + 'px',
|
||||
width: (((v['out'] - v['in']) * self.fps) - 2) + 'px'
|
||||
})
|
||||
.html(Ox.highlight(v.value, self.options.find))
|
||||
.html(Ox.highlight(v.value, self.options.find, 'OxHighlight'))
|
||||
.appendTo(self.$timeline)
|
||||
});
|
||||
|
||||
|
|
|
@ -130,7 +130,8 @@ Ox.SmallTimeline = function(options, self) {
|
|||
self.$tooltip.options({
|
||||
title: subtitle ?
|
||||
'<span class=\'OxBright\'>' +
|
||||
Ox.highlight(subtitle.value, self.options.find).replace(/\n/g, '<br/>') + '</span><br/>' +
|
||||
Ox.highlight(subtitle.value, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
||||
'</span><br/>' +
|
||||
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
||||
Ox.formatDuration(position, 3)
|
||||
})
|
||||
|
|
|
@ -320,7 +320,10 @@ Ox.VideoEditorPlayer = function(options, self) {
|
|||
var subtitle = getSubtitle();
|
||||
if (subtitle != self.subtitle) {
|
||||
self.subtitle = subtitle;
|
||||
self.$subtitle.html(Ox.highlight(self.subtitle, self.options.find).replace(/\n/g, '<br/>'));
|
||||
self.$subtitle.html(
|
||||
Ox.highlight(self.subtitle, self.options.find, 'Ox.Highlight')
|
||||
.replace(/\n/g, '<br/>')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
source/Ox.js
20
source/Ox.js
|
@ -2903,7 +2903,6 @@ Ox.doc = (function() {
|
|||
}
|
||||
function parseNode(node) {
|
||||
var item = parseItem(node.line), subitem;
|
||||
Ox.print(node, node.line, 'item', item);
|
||||
node.nodes && node.nodes.forEach(function(node) {
|
||||
var key, line = node.line, subitem;
|
||||
if (!/^#/.test(node.line)) {
|
||||
|
@ -2946,10 +2945,8 @@ Ox.doc = (function() {
|
|||
}
|
||||
function parseTest(str) {
|
||||
var lines = decodeLinebreaks(str).split('\n');
|
||||
Ox.print('$$$', str)
|
||||
return {
|
||||
statement: lines[0].substr(2),
|
||||
// result: JSON.parse(lines[1].trim())
|
||||
result: lines[1].trim()
|
||||
};
|
||||
}
|
||||
|
@ -3144,7 +3141,6 @@ Ox.test = function(file, callback) {
|
|||
var tests = [];
|
||||
items.forEach(function(item) {
|
||||
item.examples && item.examples.forEach(function(example) {
|
||||
Ox.print(example)
|
||||
var actual = eval(example.statement);
|
||||
if (example.result) {
|
||||
tests.push({
|
||||
|
@ -3859,12 +3855,16 @@ Ox.endsWith = function(str, sub) {
|
|||
return str.substr(str.length - sub.length) == sub;
|
||||
};
|
||||
|
||||
Ox.highlight = function(txt, str) {
|
||||
// fixme: move to ox.ui
|
||||
return str ? txt.replace(
|
||||
/*@
|
||||
Ox.highlight <f> Highlight matches in a string
|
||||
> Ox.highlight('foobar', 'foo', 'match')
|
||||
'<span class="match">foo</span>bar'
|
||||
@*/
|
||||
Ox.highlight = function(txt, str, classname) {
|
||||
return txt.replace(
|
||||
new RegExp('(' + str + ')', 'ig'),
|
||||
'<span class="OxHighlight">$1</span>'
|
||||
) : txt;
|
||||
'<span class="' + classname + '">$1</span>'
|
||||
);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
@ -4028,7 +4028,7 @@ Ox.toCamelCase <f> Takes a string with '-', '/' or '_', returns a camelCase stri
|
|||
@*/
|
||||
|
||||
Ox.toCamelCase = function(str) {
|
||||
return str.replace(/[\-_\/][a-z]/g, function(str) {
|
||||
return str.replace(/[\-\/_][a-z]/g, function(str) {
|
||||
return str[1].toUpperCase();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue