Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Show truncated items, with option to expand them

A count is shown below files/dists where the full results are omitted,
searching for the specific thing will show it, which is aided by links
to that specific search.

Improves on issue #11, but still need to figure out a nicer way of
presenting the rather noticeably wrong count at the top right.
  • Loading branch information...
commit 138c6c1795154276aaf15ab33f1c04c1d9c5b272 1 parent fcbc534
@dgl authored
View
43 lib/WWW/CPANGrep.pm
@@ -121,18 +121,21 @@ sub render_response {
link_format => '<a href="?q=' . encode_entities(uri_escape_utf8($q)) . '&amp;page=%p">%a</a>'
});
+ my @result_set = @$results[$pager->first - 1 .. $pager->last - 1];
+
$output = $output
->select('#time')->replace_content(sprintf "%0.2f", $duration)
->select('#total')->replace_content($count > MAX ? "more than " . MAX : $count)
->select('#start-at')->replace_content($pager->first)
- ->select('#end-at')->replace_content($pager->last);
+ ->select('#end-at')->replace_content(scalar map @{$_->{results}},
+ map @{$_->{files}}, @result_set);
$output = $output->select('.results')->repeat_content(
[ map {
my $result = $_;
sub {
my($package) = $result->{dist} =~ m{([^/]+)$};
- $package =~ s/\.(?:tar\.gz|zip|tar\.bz2)$//;
+ $package =~ s/\.(?:tar\.gz|zip|tar\.bz2|tgz|tbz)$//i;
my $author = ($result->{dist} =~ m{^([^/]+)})[0];
$_ = $_->select('.files')->repeat_content([map {
@@ -146,17 +149,47 @@ sub render_response {
} @{$file->{results}}]);
my $filename = "$package/$file->{file}";
- $_->select('.file-link')->replace_content($filename)
+ $_ = $_->select('.file-link')->replace_content($filename)
->then
->set_attribute(href => "https://metacpan.org/source/$author/$filename#L1");
+
+ if($file->{truncated}) {
+ $_ = $_->select('.file-number')
+ ->replace_content($file->{truncated})
+ ->select('.more-file')
+ ->set_attribute(href => "/?q=$q+dist=$result->{distname}+file=$file->{file}");
+
+ if($file->{truncated} == 1) {
+ $_ = $_->select('.plural')->replace("");
+ }
+ } else {
+ $_ = $_->select('.more-file')->replace("");
+ }
+
+ $_;
}
} @{$result->{files}}]);
- $_->select('.dist-link')->replace_content("$author/$package")
+ $_ = $_->select('.dist-link')->replace_content("$author/$package")
->then
->set_attribute(href => "https://metacpan.org/release/$author/$package");
+
+ if($result->{truncated}) {
+ $_ = $_->select('.dist-number')
+ ->replace_content($result->{truncated})
+ ->select('a.more-dist')
+ ->set_attribute(href => "/?q=$q+dist=$result->{distname}");
+
+ if($result->{truncated} == 1) {
+ $_ = $_->select('.plural')->replace("");
+ }
+ } else {
+ $_ = $_->select('.more-dist')->replace("");
+ }
+
+ $_;
}
- } @$results[$pager->first - 1 .. $pager->last - 1]]);
+ } @result_set]);
return $output->select('.pagination')->replace_content(\$pager->html);
}
View
31 lib/WWW/CPANGrep/Search.pm
@@ -255,7 +255,7 @@ sub filter_results {
$option->{type} eq 'file' ? sub { $_->{file}->{file} =~ $option->{re} } :
$option->{type} eq 'dist' ? sub { $_->{file}->{distname} =~ $option->{re} } :
$option->{type} eq 'author' ? sub { (split m{/}, $_->{file}->{dist}, 2)[0] =~ $option->{re} } :
- die "Unkown type";
+ die "Unknown type";
my $matcher = $predicate;
$matcher = sub { !$predicate->() } if $option->{negate};
@results = grep $matcher->(), @results;
@@ -279,23 +279,34 @@ sub filter_results {
push @{$files{$result->{file}->{file}}}, $result;
}
- push @ordered, { dist => $dist, files => [], truncated => 0 };
+ push @ordered, {
+ dist => $dist,
+ distname => $dist_results[0]->{file}->{distname},
+ files => [],
+ truncated => 0,
+ };
my $i = 0;
for my $file(sort { lc $a cmp lc $b } keys %files) {
+ if(keys %dists > 1 && $i >= 20 / keys %dists) {
+ $ordered[-1]->{truncated} = scalar keys(%files) - $i;
+ last;
+ }
+ $i++;
+
my @file_results = @{$files{$file}};
- if(@file_results > 3 && keys %files > 1) {
+ my $truncated = 0;
+ if(keys %files > 1 && @file_results > 3) {
+ $truncated = @file_results - 3;
@file_results = @file_results[0 .. 2];
- $file_results[-1]->{truncated} = 1;
}
- push $ordered[-1]->{files}, { file => $file, results => \@file_results };
-
- if($i++ >= 20 / keys %dists) {
- $ordered[-1]->{truncated} = 1;
- last;
- }
+ push $ordered[-1]->{files}, {
+ file => $file,
+ results => \@file_results,
+ truncated => $truncated,
+ };
}
}
View
6 share/css/cpangrep.css
@@ -117,6 +117,12 @@ BODY#grep_index .footer {
margin: 0.5em 1em;
}
+.more-file {
+ display: block;
+ font-size: 0.8em;
+ margin: 0em 0.5em 0.5em 1em;
+}
+
.dist-link, .dist-link:visited, .dist-link:active {
font-size: 0.9em;
color: #060;
View
9 share/html/results.html
@@ -9,7 +9,7 @@
<meta name="keywords" content="cpan,search,regex,regexp,regular,expressions,reg,exp,ex,re,find,through,within,inside,in" />
<meta name="robots" content="all" />
<link rel="icon" type="image/png" href="/favicon.png" />
- <link rel="stylesheet" type="text/css" media="screen, projection" href="//dg.cx/cpangrep/cpangrep.css" />
+ <link rel="stylesheet" type="text/css" media="screen, projection" href="//s.cpan.me/cpangrep.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
@@ -26,7 +26,7 @@
<body>
<div class="header">
- <a href="/"><img src="//dg.cx/cpangrep/magnify80.png" alt="CPAN->GREP" class="magnify" /></a>
+ <a href="/"><img src="//s.cpan.me/magnify80.png" alt="CPAN->GREP" class="magnify" /></a>
<form action="/" method="get">
<p>
@@ -48,9 +48,12 @@
<pre class="excerpt">52471 | Ferula assa-foetida L. | | synonym |
52471 | asafoetida | | common name |
52473 | Astrantia epipactis | | synonym |</pre>
- </span></span>
+ </span>
+ <a class="more-file" href=""><span class="file-number">1</span> more match<span class="plural">es</span> »<br /></a>
+ </span>
</span>
<a href="bleh" class="dist-link">MOTIF/Bio-LITE-Taxonomy-NCBI-0.04.tar.gz</a>
+ <span class="more-dist">&ndash; <a class="more-dist" href=""><span class="dist-number">1</span> more file<span class="plural">s</span> »</a></span>
</div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.