summaryrefslogtreecommitdiff
path: root/lib/VNDB/Func.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r--lib/VNDB/Func.pm77
1 files changed, 76 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 435f0fec..64b56625 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -7,7 +7,7 @@ use TUWF ':html';
use Exporter 'import';
use POSIX 'strftime', 'ceil', 'floor';
use VNDBUtil;
-our @EXPORT = (@VNDBUtil::EXPORT, qw| clearfloat cssicon tagscore mt minage fil_parse fil_serialize |);
+our @EXPORT = (@VNDBUtil::EXPORT, qw| clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags childtags charspoil |);
# three ways to represent the same information
@@ -105,5 +105,80 @@ sub fil_serialize {
} grep defined($fil->{$_}), keys %$fil;
}
+
+# generates a parent tags/traits listing
+sub parenttags {
+ my($t, $index, $type) = @_;
+ p;
+ my @p = _parenttags(@{$t->{parents}});
+ for my $p (@p ? @p : []) {
+ a href => "/$type", $index; #mt '_tagp_indexlink';
+ for (reverse @$p) {
+ txt ' > ';
+ a href => "/$type$_->{id}", $_->{name};
+ }
+ txt " > $t->{name}";
+ br;
+ }
+ end 'p';
+}
+
+# arg: tag/trait hashref
+# returns: [ [ tag1, tag2, tag3 ], [ tag1, tag2, tag5 ] ]
+sub _parenttags {
+ my @r;
+ for my $t (@_) {
+ for (@{$t->{'sub'}}) {
+ push @r, [ $t, @$_ ] for _parenttags($_);
+ }
+ push @r, [$t] if !@{$t->{'sub'}};
+ }
+ return @r;
+}
+
+
+# a child tags/traits box
+sub childtags {
+ my($self, $title, $type, $t) = @_;
+
+ div class => 'mainbox';
+ h1 $title;
+ ul class => 'tagtree';
+ for my $p (sort { @{$b->{'sub'}} <=> @{$a->{'sub'}} } @{$t->{childs}}) {
+ li;
+ a href => "/$type$p->{id}", $p->{name};
+ b class => 'grayedout', " ($p->{c_items})" if $p->{c_items};
+ end, next if !@{$p->{'sub'}};
+ ul;
+ for (0..$#{$p->{'sub'}}) {
+ last if $_ >= 5 && @{$p->{'sub'}} > 6;
+ li;
+ txt '> ';
+ a href => "/$type$p->{sub}[$_]{id}", $p->{'sub'}[$_]{name};
+ b class => 'grayedout', " ($p->{sub}[$_]{c_items})" if $p->{'sub'}[$_]{c_items};
+ end;
+ }
+ if(@{$p->{'sub'}} > 6) {
+ li;
+ txt '> ';
+ a href => "/$type$p->{id}", style => 'font-style: italic', mt $type eq 'g' ? '_tagp_moretags' : '_traitp_more', @{$p->{'sub'}}-5;
+ end;
+ }
+ end;
+ end 'li';
+ }
+ end 'ul';
+ clearfloat;
+ br;
+ end 'div';
+}
+
+
+# generates the class elements for character spoiler hiding
+sub charspoil {
+ return "charspoil charspoil_$_[0]".($_[0] ? ' hidden' : '');
+}
+
+
1;