add geo module documentation and tests

This commit is contained in:
rolux 2011-05-09 10:54:52 +02:00
commit 43fa75c8db
8 changed files with 203 additions and 98 deletions

View file

@ -4,7 +4,13 @@ Ox.load('UI', {
}, function() { }, function() {
Ox.Theme('classic'); Ox.Theme('classic');
Ox.DocPanel({ 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) { getModule: function(item) {
var file = item.file.replace(Ox.PATH, ''); var file = item.file.replace(Ox.PATH, '');
return file == 'Ox.js' ? 'Ox' : file.split('/')[0]; return file == 'Ox.js' ? 'Ox' : file.split('/')[0];

View file

@ -2,22 +2,33 @@ Ox.load('UI', {
debug: true, debug: true,
theme: 'classic' theme: 'classic'
}, function() { }, function() {
var colors = [ Ox.load('Geo', function() {
[[255, 64, 64], [224, 32, 32]], var $div = $('<div>')
[[64, 192, 64], [32, 160, 32]]
],
gradients = [
'-moz-linear-gradient(',
'-webkit-gradient(linear, '
];
var $foo = $('<div>')
.css({ .css({
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight, height: window.innerHeight,
overflowY: 'scroll' overflowY: 'scroll'
}) })
.appendTo(Ox.UI.$body); .appendTo(Ox.UI.$body),
Ox.test(Ox.PATH + 'Ox.js', function(tests) { 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();
}
});
});
function renderTests() {
var total = tests.length, var total = tests.length,
succeeded = tests.filter(function(test) { succeeded = tests.filter(function(test) {
return test.success; return test.success;
@ -38,7 +49,7 @@ Ox.load('UI', {
'<b>' + total + ' tests, ' + '<b>' + total + ' tests, ' +
succeeded + ' succeeded, ' + failed + ' failed</b>' succeeded + ' succeeded, ' + failed + ' failed</b>'
) )
.appendTo($foo); .appendTo($div);
names.forEach(function(name) { names.forEach(function(name) {
var tests = testsByName[name], var tests = testsByName[name],
total = tests.length, total = tests.length,
@ -56,7 +67,7 @@ Ox.load('UI', {
.click(function() { .click(function() {
$('.' + classname).toggle(); $('.' + classname).toggle();
}) })
.appendTo($foo); .appendTo($div);
tests.forEach(function(test) { tests.forEach(function(test) {
getBar(test.success, true) getBar(test.success, true)
.addClass(classname) .addClass(classname)
@ -67,10 +78,10 @@ Ox.load('UI', {
Ox.encodeHTML(test.expected) Ox.encodeHTML(test.expected)
) )
.hide() .hide()
.appendTo($foo); .appendTo($div);
});
}); });
}); });
}
function getBar(success, darker) { function getBar(success, darker) {
var $div = $('<div>') var $div = $('<div>')
.css({ .css({
@ -83,11 +94,14 @@ Ox.load('UI', {
MozUserSelect: 'text', MozUserSelect: 'text',
WebkitUserSelect: 'text' WebkitUserSelect: 'text'
}); });
gradients.forEach(function(gradient) { ['moz', 'webkit'].forEach(function(browser) {
Ox.print('-' + browser + '-linear-gradient(left top, left bottom, rgb(' +
getColor(success, 0) + '), rgb(' +
getColor(success, 1) + '))')
$div.css({ $div.css({
background: gradient + 'left top, left bottom, from(rgb(' + background: '-' + browser + '-linear-gradient(top, rgb(' +
getColor(success, 0) + ')), to(rgb(' + getColor(success, 0) + '), rgb(' +
getColor(success, 1) + ')))' getColor(success, 1) + '))'
}); });
}); });
function getColor(success, i) { function getColor(success, i) {
@ -98,3 +112,4 @@ Ox.load('UI', {
return $div; return $div;
} }
}); });
});

View file

@ -2,8 +2,79 @@ Ox.load.Geo = function(options, callback) {
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) { 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; 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) { Ox.getCountryByCode = function(code) {
var country; var country;
Ox.forEach(Ox.COUNTRIES, function(c) { Ox.forEach(Ox.COUNTRIES, function(c) {
@ -15,6 +86,14 @@ Ox.load.Geo = function(options, callback) {
return country; 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) { Ox.getCountryByName = function(name) {
var country; var country;
Ox.forEach(Ox.COUNTRIES, function(c) { Ox.forEach(Ox.COUNTRIES, function(c) {

View file

@ -274,7 +274,8 @@ Ox.BlockTimeline = function(options, self) {
self.$tooltip.options({ self.$tooltip.options({
title: subtitle ? title: subtitle ?
'<span class=\'OxBright\'>' + '<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(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
Ox.formatDuration(position, 3) Ox.formatDuration(position, 3)
}) })

View file

@ -54,7 +54,7 @@ Ox.LargeTimeline = function(options, self) {
left: (v['in'] * self.fps) + 'px', left: (v['in'] * self.fps) + 'px',
width: (((v['out'] - v['in']) * self.fps) - 2) + '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) .appendTo(self.$timeline)
}); });

View file

@ -130,7 +130,8 @@ Ox.SmallTimeline = function(options, self) {
self.$tooltip.options({ self.$tooltip.options({
title: subtitle ? title: subtitle ?
'<span class=\'OxBright\'>' + '<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(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
Ox.formatDuration(position, 3) Ox.formatDuration(position, 3)
}) })

View file

@ -320,7 +320,10 @@ Ox.VideoEditorPlayer = function(options, self) {
var subtitle = getSubtitle(); var subtitle = getSubtitle();
if (subtitle != self.subtitle) { if (subtitle != self.subtitle) {
self.subtitle = 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/>')
);
} }
} }

View file

@ -2903,7 +2903,6 @@ Ox.doc = (function() {
} }
function parseNode(node) { function parseNode(node) {
var item = parseItem(node.line), subitem; var item = parseItem(node.line), subitem;
Ox.print(node, node.line, 'item', item);
node.nodes && node.nodes.forEach(function(node) { node.nodes && node.nodes.forEach(function(node) {
var key, line = node.line, subitem; var key, line = node.line, subitem;
if (!/^#/.test(node.line)) { if (!/^#/.test(node.line)) {
@ -2946,10 +2945,8 @@ Ox.doc = (function() {
} }
function parseTest(str) { function parseTest(str) {
var lines = decodeLinebreaks(str).split('\n'); var lines = decodeLinebreaks(str).split('\n');
Ox.print('$$$', str)
return { return {
statement: lines[0].substr(2), statement: lines[0].substr(2),
// result: JSON.parse(lines[1].trim())
result: lines[1].trim() result: lines[1].trim()
}; };
} }
@ -3144,7 +3141,6 @@ Ox.test = function(file, callback) {
var tests = []; var tests = [];
items.forEach(function(item) { items.forEach(function(item) {
item.examples && item.examples.forEach(function(example) { item.examples && item.examples.forEach(function(example) {
Ox.print(example)
var actual = eval(example.statement); var actual = eval(example.statement);
if (example.result) { if (example.result) {
tests.push({ tests.push({
@ -3859,12 +3855,16 @@ Ox.endsWith = function(str, sub) {
return str.substr(str.length - sub.length) == sub; return str.substr(str.length - sub.length) == sub;
}; };
Ox.highlight = function(txt, str) { /*@
// fixme: move to ox.ui Ox.highlight <f> Highlight matches in a string
return str ? txt.replace( > Ox.highlight('foobar', 'foo', 'match')
'<span class="match">foo</span>bar'
@*/
Ox.highlight = function(txt, str, classname) {
return txt.replace(
new RegExp('(' + str + ')', 'ig'), new RegExp('(' + str + ')', 'ig'),
'<span class="OxHighlight">$1</span>' '<span class="' + classname + '">$1</span>'
) : txt; );
}; };
/*@ /*@
@ -4028,7 +4028,7 @@ Ox.toCamelCase <f> Takes a string with '-', '/' or '_', returns a camelCase stri
@*/ @*/
Ox.toCamelCase = function(str) { Ox.toCamelCase = function(str) {
return str.replace(/[\-_\/][a-z]/g, function(str) { return str.replace(/[\-\/_][a-z]/g, function(str) {
return str[1].toUpperCase(); return str[1].toUpperCase();
}); });
}; };