Generate package links in a single place

This commit is contained in:
Steve Purcell 2014-08-16 16:09:44 +01:00
parent 6913492d76
commit 2da5efa433

View file

@ -166,6 +166,11 @@
return m("span.glyphicon.glyphicon-" + name); return m("span.glyphicon.glyphicon-" + name);
} }
function packageLink(pkg, contents) {
return m("a", {href: "/ " + encodeURIComponent(pkg.name), config: m.route},
contents || pkg.name);
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Package list // Package list
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -232,18 +237,14 @@
ctrl.sortedPackages().map(function(p) { ctrl.sortedPackages().map(function(p) {
return m("tr", { "class": visible[p.name] ? '' : 'filtered'}, return m("tr", { "class": visible[p.name] ? '' : 'filtered'},
[ [
m("td", [ m("td", packageLink(p)),
m("a", {href: "/" + p.name, config: m.route}, [
p.name
])
]),
m("td", [ m("td", [
m("a", {href: "/" + p.name, config: m.route}, [ m("a", {href: "/" + p.name, config: m.route}, [
p.description p.description
]) ])
]), ]),
m("td.version", [ m("td.version", [
m("a", {href: p.packageURL}, [ packageLink(p, [
p.version, p.version,
" ", " ",
glyphicon('download') glyphicon('download')
@ -296,10 +297,7 @@
this.depLink = function(dep) { this.depLink = function(dep) {
var depPkg = ctrl.packageWithName(dep.name); var depPkg = ctrl.packageWithName(dep.name);
var label = dep.name + " " + dep.version; var label = dep.name + " " + dep.version;
return depPkg ? m("a", {href: "/" + dep.name, config: m.route}, label) : label; return depPkg ? packageLink(dep, label) : label;
};
this.packageLink = function(pkg) {
return m("a", {href: "/" + pkg.name, config: m.route}, pkg.name);
}; };
return m("section", [ return m("section", [
m("h1", [ m("h1", [
@ -330,7 +328,7 @@
m("dt", "Dependencies"), m("dt", "Dependencies"),
m("dd", intersperse(pkg.dependencies.map(this.depLink), " / ")), m("dd", intersperse(pkg.dependencies.map(this.depLink), " / ")),
m("dt", "Needed by"), m("dt", "Needed by"),
m("dd", intersperse(ctrl.neededBy().map(this.packageLink), " / ")), m("dd", intersperse(ctrl.neededBy().map(packageLink), " / ")),
pkg.oldNames.length > 0 ? [ pkg.oldNames.length > 0 ? [
m("dt", "Renamed from:"), m("dt", "Renamed from:"),
pkg.oldNames pkg.oldNames