commit e0237a9c5ba5b414b91774cd746f66c69ddf70e4
parent 79a118716613d24a656513e009bcb332f963e933
Author: kyle <kyle@getaddrinfo.net>
Date:   Sun,  8 Nov 2015 22:52:29 -0700
html: create a single logo/ file map to use everywhere
- in multiple files we were globbing onto filenames
- do this in a single common place now and pass around the hash
- this should fix the long standing no logo problem on production machine
Diffstat:
3 files changed, 27 insertions(+), 40 deletions(-)
diff --git a/ps_html b/ps_html
@@ -48,6 +48,17 @@ my $catrom_to_bezier = Math::MatrixReal->new_from_rows(
 );
 my $m_t = ~$catrom_to_bezier;
 
+# make a logo file map using massaged names as keys
+opendir(DH, "$cfg->{http}{htdocs}/logo");
+my @files = readdir(DH);
+closedir(DH);
+
+my %logo_hash;
+for my $filename (@files) {
+	my $last_dot = rindex($filename, ".");
+	my $logo_name = substr($filename, 0, $last_dot);
+	$logo_hash{$logo_name} = "/logo/$filename";
+}
 
 #
 # manufacturers
@@ -136,10 +147,10 @@ my $types_list = $dbh->selectall_hashref($coarse_sql, \@key_fields);
 my $vars = {
 	manufacturer_list => $manufacturer_list,
 	retailer_list => $retailer_list,
-	types_list => $types_list
+	types_list => $types_list,
+	logo_hash => \%logo_hash,
 };
-$www->process("index.tt", $vars, "index.html")
-	or die $www->error(), "\n";
+$www->process("index.tt", $vars, "index.html") or die $www->error(), "\n";
 
 #
 # about
@@ -277,7 +288,7 @@ sub generate_folder
 
 			my $vars = {
 				name => $it, type => PL($type, scalar @$products),
-				products => $products
+				products => $products, logo_hash => \%logo_hash
 			};
 			my $type_link = linkify($type);
 			my $out_path = "$name_lc/$it_link/$type_link.html";
diff --git a/tt/fine_list.tt b/tt/fine_list.tt
@@ -1,11 +1,7 @@
 [% WRAPPER wrapper.tt %]
 [% name_link = name.lower.replace('[ #\/]', '_') %]
-[% PERL %]
-	my $name_html = $stash->get("name_link");
-	my ($logo) = glob("logo/$name_html*");
-	$stash->set("logo", $logo);
-[% END %]
-	<h1><img alt="[% name %]" class="logo_small" src="/[% logo %]"/>
+	<h1><img alt="[% name %]" class="logo_small"
+		src="[% logo_hash.item(name_link) %]"/>
 		[% name %] [% type %] ([% products.size %] total)</h1>
 
 	[% FOREACH product IN products %]
@@ -13,15 +9,10 @@
 		[% manuf_html = product.0.lower.replace('[ #\/]', '_') %]
 		[% part_link  = product.1.lower.replace('[ #\/]', '_') %]
 		<a name="[% part_link %]"></a>
-		[% PERL %]
-			my $manuf_html = $stash->get("manuf_html");
-			my ($logo) = glob("logo/$manuf_html*");
-			$stash->set("logo", $logo);
-		[% END %]
 		[%# make the manufacturer logo into a link %]
 		<a href="/manufacturers/[% manuf_html %].html">
 			<img alt="[% product.0 %]" class="logo_small"
-			src="/[% logo %]"/></a>
+			src="[% logo_hash.item(manuf_html) %]"/></a>
 
 		[%# display the description %]
 		[% product.2 %]
diff --git a/tt/index.tt b/tt/index.tt
@@ -3,21 +3,16 @@
 	<div class="column">
 	<h2>Manufacturers ([% manufacturer_list.keys.size %] total)</h2>
 
-	[% FOREACH item IN manufacturer_list.keys.sort %]
-		[% item_link = item.lower.replace('[ #\/]', '_') %]
-		[% PERL %]
-			my $link = $stash->get("item_link");
-			# glob onto file with any extension
-			my ($logo) = glob("logo/$link.*");
-			$stash->set("logo", $logo);
-		[% END %]
+	[% FOREACH manuf IN manufacturer_list.keys.sort %]
+		[% item_link = manuf.lower.replace('[ #\/]', '_') %]
 		<div class="list_item">
 		<a href="/manufacturers/[% item_link %].html">
-			<img class="logo" alt="[% item %]" src="/[% logo %]" />
+			<img class="logo" alt="[% manuf %]"
+				src="[% logo_hash.item(item_link) %]" />
 		</a><br>
 
 		Types: 
-		[% FOREACH pair IN manufacturer_list.$item.pairs %]
+		[% FOREACH pair IN manufacturer_list.$manuf.pairs %]
 			[% n = pair.value.count %]
 			[% type_link = pair.key.lower.replace('[ #\/]', '_') %]
 			[% n %] <a href="/manufacturers/[% item_link %]/[% type_link %].html">
@@ -34,14 +29,9 @@
 	<h2>Retailers ([% retailer_list.keys.size %] total)</h2>
 	[% FOREACH item IN retailer_list.keys.sort %]
 		[% item_link = item.lower.replace('[ #\/]', '_') %]
-		[% PERL %]
-			my $link = $stash->get("item_link");
-			# glob onto file with any extension
-			my ($logo) = glob("logo/$link.*");
-			$stash->set("logo", $logo);
-		[% END %]
 		<a href="/retailers/[% item_link %].html">
-			<img class="retailer_logo" alt="[% item %]" src="/[% logo %]" />
+			<img class="retailer_logo" alt="[% item %]"
+				src="[% logo_hash.item(item_link) %]" />
 		</a>
 		<br />
 
@@ -57,15 +47,10 @@
 	<h2>Product Types ([% types_list.keys.size %] total)</h2>
 	[% FOREACH item IN types_list.keys.sort %]
 		[% item_link = item.lower.replace('[ #\/]', '_') %]
-		[% PERL %]
-			my $link = $stash->get("item_link");
-			# glob onto file with any extension
-			my ($logo) = glob("logo/$link.*");
-			$stash->set("logo", $logo);
-		[% END %]
 		<div class="list_item">
 		<a href="/types/[% item_link %].html">
-			<img class="product_type" alt="[% item %]" src="/[% logo %]" />
+			<img class="product_type" alt="[% item %]"
+				src="[% logo_hash.item(item_link) %]" />
 		</a><br />
 
 		[% item %] manufacturers: