Permalink
Browse files

Update format to match JSON output from http://srv.buzzword.org.uk/op…

  • Loading branch information...
fiann committed May 28, 2010
1 parent 81b7ded commit ac05915ce4f032632fd87a2dffa08499a6e29aa2
Showing with 28 additions and 4 deletions.
  1. +3 −2 src/jquery.ogp.js
  2. +25 −2 test/the-rock.js
View
@@ -19,7 +19,7 @@
}
$.fn.ogp = function() {
- var ns = null, data = [];
+ var ns = null, data = {};
$(this).each(function () {
$(this).parents().andSelf().each(function () {
ns = checkNamespacePresent(this);
@@ -44,7 +44,8 @@
key = prop.substring(ns.length);
value = $(this).attr("content");
console.log("Found OGP data %s=%s", key, value);
- data.push( {key:value} );
+ data[key] = data[key] || [];
+ data[key].push(value);
}
});
});
View
@@ -11,6 +11,29 @@ test("jQuery.ogp plugin is present", function () {
module("Parsing");
test("OGP data is found", function () {
- data = $('head').ogp();
+ var data = $('head').ogp();
ok(typeof data === "object", "ogp data not found");
-});
+});
+
+test("OGP data fields", function () {
+ var data = $('head').ogp();
+ var expected = {
+ title : ["The Rock"],
+ type : ["movie"],
+ url : ["http://www.imdb.com/title/tt0117500/"],
+ image : ["http://ia.media-imdb.com/rock.jpg"]
+ };
+ if (QUnit.equiv(expected, data)) {
+ ok(true, "All data is present as expected");
+ } else {
+ var field;
+ for (field in expected) {
+ ok(QUnit.equiv(expected[field], data[field]), "og:"+field);
+ }
+ for (field in data) {
+ if (! expected[field]) {
+ ok(false, "unexpected field 'og:" + field + "' found in data");
+ }
+ }
+ }
+})

0 comments on commit ac05915

Please sign in to comment.