[Debtags-commits] [svn] r1523 - central-database/branches/alioth/webfrontend

Enrico Zini enrico at costa.debian.org
Wed Nov 23 12:44:34 UTC 2005


Author: enrico
Date: Wed Nov 23 12:44:33 2005
New Revision: 1523

Modified:
   central-database/branches/alioth/webfrontend/maint
   central-database/branches/alioth/webfrontend/search.cgi
Log:
maint can now create a Javascript source with the vocabulary data

Modified: central-database/branches/alioth/webfrontend/maint
==============================================================================
--- central-database/branches/alioth/webfrontend/maint	(original)
+++ central-database/branches/alioth/webfrontend/maint	Wed Nov 23 12:44:33 2005
@@ -7,11 +7,29 @@
 
 sub usage ()
 {
-	print STDERR qq{Usage: $0 init|resync|check|dump|tagcat|patch-from|applypatch
+	print STDERR qq{Usage: $0 init|resync|check|dump|tagcat|patch-from|applypatch|jsvocab
 };
 	exit 1;
 }
 
+sub format_ldesc ($)
+{
+	my ($desc) = @_;
+	$desc =~ s/\n+\s*\.\s*\n+/\n<\/p>\n<p>\n/mg;
+	$desc =~ s/\n  +\*/<li>/mg;
+	return "<p>$desc</p>";
+}
+sub jsescape ($)
+{
+	my ($str) = @_;
+	$str =~ s/\n/\\n/g;
+	$str =~ s/\t/\\t/g;
+	$str =~ s/"/\\"/g;
+	$str =~ s/'/\\'/g;
+	return $str;
+}
+
+
 my $cmd = shift @ARGV or usage();
 
 if ($cmd eq 'init')
@@ -164,6 +182,60 @@
 		$in->close();
 	}
 	Engine::closeDB();
+} elsif ($cmd eq 'jsvocab') {
+	Engine::openDB();
+	print q{// Define classes and instances for a global tag vocabulary
+
+function Facet(name, sdesc, ldesc)
+{
+	this = new Object;
+	this.name = name;
+	this.sdesc = sdesc;
+	this.ldesc = ldesc;
+	this.tags = new Array();
+}
+Facet.prototype.add = function(tag) {
+	this.tags.push(tag);
+	this[tag.name] = tag;
+}
+
+function Tag(name, sdesc, ldesc)
+{
+	this = new Object;
+	this.name = name;
+	this.sdesc = sdesc;
+	this.ldesc = ldesc;
+}
+
+function Vocabulary()
+{
+	this = new Object;
+	this.facets = new Array();
+}
+Vocabulary.prototype.add = function(facet) {
+	this.facets.push(facet);
+	this[facet.name] = facet;
+}
+
+var voc = new Vocabulary();
+
+};
+	for my $f (sort { $a->name() cmp $b->name() } Engine::allFacets())
+	{
+		printf "var f = new Facet('%s', '%s', '%s')\n",
+			$f->name,
+			jsescape($f->sdesc),
+			jsescape(format_ldesc($f->ldesc));
+		for my $t (sort { $a->name() cmp $b->name() } $f->tags())
+		{
+			printf "f.add(new Tag('%s', '%s', '%s'))\n",
+				$t->name,
+				jsescape($t->sdesc),
+				jsescape(format_ldesc($t->ldesc));
+		}
+		print "voc.add(f)\n";
+	}
+	Engine::closeDB();
 } else {
 	usage();
 }

Modified: central-database/branches/alioth/webfrontend/search.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/search.cgi	(original)
+++ central-database/branches/alioth/webfrontend/search.cgi	Wed Nov 23 12:44:33 2005
@@ -1,5 +1,7 @@
 #!/usr/bin/perl -w
 
+# TODO: breaks looking for libsvn
+
 use strict;
 use warnings;
 use English;



More information about the Debtags-commits mailing list