Skip to content

Commit

Permalink
New rep: named node map
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Jun 27, 2014
1 parent 89167e7 commit de26e8a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/firebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require("./reps/function.js");
require("./reps/text-node.js");
require("./reps/css-rule.js");
require("./reps/attribute.js");
require("./reps/named-node-map.js");

// Hello World (will be removed at some point)
require("./helloWorld/helloWorldPanel.js");
Expand Down
105 changes: 105 additions & 0 deletions lib/reps/named-node-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* See license.txt for terms of usage */

"use strict";

module.metadata = {
"stability": "experimental"
};

const { Trace, TraceError } = require("../core/trace.js");
const { Domplate } = require("../core/domplate.js");
const { Rep } = require("./rep.js");
const { Reps } = require("./reps.js");
const { Locale } = require("../core/locale.js");

// Domplate
const { domplate, SPAN, TAG, FOR } = Domplate;
const { OBJECTLINK } = Rep.tags;

/**
* @rep
*/
var NamedNodeMap = domplate(Rep,
/** @lends NamedNodeMap */
{
className: "NamedNodeMap",

tag:
OBJECTLINK(
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
FOR("prop", "$object|longPropIterator",
SPAN({"class": "nodeName"}, "$prop.name"),
SPAN({"class": "objectEqual", role: "presentation"}, "$prop.equal"),
TAG("$prop.tag", {object: "$prop.object"}),
SPAN({"class": "objectComma", role: "presentation"}, "$prop.delim")
),
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]")
),

shortTag:
OBJECTLINK(
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
FOR("prop", "$object|shortPropIterator",
SPAN({"class": "nodeName"}, "$prop.name"),
SPAN({"class": "objectEqual", role: "presentation"}, "$prop.equal"),
TAG("$prop.tag", {object: "$prop.object"}),
SPAN({"class": "objectComma", role: "presentation"}, "$prop.delim")
),
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]")
),

supportsObject: function(grip, type) {
return (grip.kind == "MapLike" && grip.preview);
},

longPropIterator: function(object) {
return this.propIterator(object, 100);
},

shortPropIterator: function(object) {
return this.propIterator(object, Options.get("ObjectShortIteratorMax"));
},

propIterator: function (object, max) {
max = max || 3;

This comment has been minimized.

Copy link
@simonlindholm

simonlindholm Jun 28, 2014

Member

remove this default, or if you for some reason want to keep it for some more generic propIterator function, use function (object, max = 3) instead.

This comment has been minimized.

Copy link
@SebastianZ

SebastianZ Jun 30, 2014

Member

use function (object, max = 3) instead.

+1
Though the group should decide whether default parameters should be used. And if so, we should add it to our coding style.

Sebastian


var props = [];
for (var i=0; i<object.length && i<max; i++) {
var item = object.item(i);
var name = item.name;
var value = item.value;

var rep = Firebug.getRep(value);
var tag = rep.tag;

props.push({tag: tag, name: name, object: value, equal: "=", delim: ", "});
}

if (object.length > max) {
var index = max - 1, more = object.length - max + 1;
if (index < 1) {
index = 1;
more++;
}

props[index] = {
object: more + " " + Locale.$STR("firebug.reps.more") + "...",
tag: FirebugReps.Caption.tag,
name: "",
equal: "",
delim: ""
};
}
else if (props.length > 0) {
props[props.length-1].delim = "";
}

return props;
},
});

// Registration
Reps.registerRep(NamedNodeMap);

// Exports from this module
exports.NamedNodeMap = NamedNodeMap;

3 comments on commit de26e8a

@simonlindholm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the property iterator duplication?

@janodvarko
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'd like to avoid that too. Please create a new issue.
Honza

@simonlindholm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#20

Please sign in to comment.