commit e95e277d857a75f388758b7248d27189729d19cc
parent 4ac0e6db2b9b70dd1a67a03de596f0f78f6667e6
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Sat, 25 Apr 2015 21:13:15 -0600
pc_fcgi: simplify page generation
Diffstat:
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/pc_fcgi b/pc_fcgi
@@ -72,7 +72,7 @@ my $config = { INCLUDE_PATH => "$http_cfg{htdocs}/tt" };
my $template = Template->new($config) || die $Template::ERROR . "\n";
# try hard here not to use EVAL_PERL in the template
-my $sql = "select distinct manufacturer, part_num, lower(part_num), lower(manufacturer) ".
+my $sql = "select distinct manufacturer, part_num " .
"from prices where part_num like ? or manufacturer like ?";
my $search_sth = $dbh->prepare($sql);
@@ -93,11 +93,7 @@ while ($request->Accept() >= 0) {
$search_sth->execute("%$input%", "%$input%");
my $products = $search_sth->fetchall_arrayref();
- my $vars = {
- query => $input, num_results => scalar @$products,
- results => $products
- };
-
+ my $vars = { query => $input, results => $products };
$template->process("search.tt", $vars)
|| print "template: " . $template->error();
$requests_total++;
diff --git a/tt/search.tt b/tt/search.tt
@@ -1,6 +1,6 @@
[% WRAPPER wrapper.tt %]
- <p>Found <b>[% num_results %]</b> search
- [% IF num_results == 1 %]
+ <p>Found <b>[% results.size %]</b> search
+ [% IF results.size == 1 %]
result
[% ELSE %]
results
@@ -9,13 +9,16 @@
[% FOREACH part_num IN results %]
<div class="product">
- <a href="/manufacturers/[% part_num.3 %].html">
+ [% manuf_html = part_num.0.lower.replace('[ #\/]', '_') %]
+ [% part_html = part_num.1.lower.replace('[ #\/]', '_') %]
+
+ <a href="/manufacturers/[% manuf_html %].html">
<img alt="[% part_num.0 %]" class="logo_small"
- src="/logo/[% part_num.3 %].svg"/></a>
+ src="/logo/[% part_html %].svg"/></a>
[% part_num.1 %]<br>
- <object data="/svg/[% part_num.2 %].svg" type="image/svg+xml">
+ <object data="/svg/[% manuf_html %]/[% part_html %].svg" type="image/svg+xml">
</object>
</div>
[% END %]