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

@ -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) {

View file

@ -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)
})

View file

@ -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)
});

View file

@ -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)
})

View file

@ -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/>')
);
}
}

View file

@ -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();
});
};