Skip to content

Commit

Permalink
FIX: Broken HTML representations.
Browse files Browse the repository at this point in the history
Closes #7.
Closes #8.
Closes #9.
  • Loading branch information
benel committed Apr 30, 2014
1 parent 4d06b3d commit fe2d55e
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions lib/hypertopic.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
exports.Viewpoint = function(o) {

this.data = {
topics: {},
upper: [],
users: []
};
if (!o) {
this.data = {
topics: {},
upper: [],
users: []
};
} else {
this.data = o;
this.data.upper = [];
for (var t in o.topics) {
var topic = this.data.topics[t];
if (!topic.broader || topic.broader.length==0) {
this.data.upper.push({id:t});
}
for each (var b in topic.broader) {
var broader = this.data.topics[b];
if (!broader.narrower) {
broader.narrower = [];
}
broader.narrower.push({id:t});
}
}
}

this.addRow = function(key, value) {
var subject = key[key.length-1];
Expand Down Expand Up @@ -41,13 +59,13 @@ exports.Viewpoint = function(o) {
this.data.topics[id].bound = true;
}

this.sendHtmlNode = function(node) {
var node = this.data.topics[node.id];
this.sendHtmlNode = function(id) {
var node = this.data.topics[id];
send('<li class="topic'
+ ((node.bound)?' bound':'')
+ '">' + node.name + '<ul>');
for each (var child in node.narrower) {
this.sendHtmlNode(child);
this.sendHtmlNode(child.id);
}
send("</ul></li>");
}
Expand All @@ -56,7 +74,7 @@ exports.Viewpoint = function(o) {
send("<section>");
send("<h1>" + this.data.viewpoint_name +"</h1><ul>");
for each (var upper in this.data.upper) {
this.sendHtmlNode(upper);
this.sendHtmlNode(upper.id);
}
send("</ul>");
send("</section>");
Expand All @@ -66,6 +84,7 @@ exports.Viewpoint = function(o) {
exports.Item = function() {
this.viewpoints = {};
this.attributes = [];

this.addTopic = function(viewpoint, t) {
if (viewpoint) {
var v = viewpoint._id;
Expand All @@ -75,11 +94,13 @@ exports.Item = function() {
this.viewpoints[v].bind(t);
}
}

this.addAttributes = function(object) {
for (k in object) {
this.attributes.push([k, object[k]]);
}
}

this.sendHTML = function() {
send("<section>");
send('<table>');
Expand Down

0 comments on commit fe2d55e

Please sign in to comment.