sub structure {
my ($self, $data) = @_;
+ return unless $data;
if (ref($data) eq 'HASH') {
if (keys %$data > 1
and values %$data == grep ref($_) eq 'HASH', values %$data) {
$data->{$_}->{name} ||= $_ for keys %$data;
my @cols = grep $_ ne 'name', sort keys %{(values %$data)[0]};
unshift @cols, 'name';
- return {
+ return [{
columns => \@cols,
show_columns => 1,
data => [ @{$data}{sort keys %$data} ],
- }
+ }]
}
}
- return {
+ return [{
columns => [ 'key', 'value' ],
data => [ map +{ key => $_, value => $data->{$_} }, sort keys %$data ],
- };
+ }];
} elsif (blessed($data) and $data->isa('IO::All::Dir')) {
- return {
+ return [{
columns => [ 'name', 'explore' ],
data => [
map +{ name => $_, explore => $self->link_to($_) }, keys %$data,
]
- };
+ }];
} else {
die "Confused by $data";
}
}
sub link_to {
- my ($self, $to) = @_;
+ my ($self, @to) = @_;
use HTML::Tags;
+ s/\//\./g for my @link = @to;
+ my $link = join('/', @link, '');
+ my $to = $to[-1];
my $html = join '', HTML::Tags::to_html_string(
- <a href="${to}/">, "Explore $to", </a>
+ <a href="${link}">, "Explore $to", </a>
);
return \$html;
}
sub descend {
my ($self, $target, @path) = @_;
+ return unless $target;
if (blessed($target) and $target->isa('IO::All::File')) {
$target = $self->json->decode(scalar $target->all);
}
return $target unless @path;
- my $step = shift @path;
- $self->descend($target->{$step}, @path);
+ (my $undot = my $step = shift @path) =~ s/\./\//g;
+ $self->descend($target->{$step}||$target->{$undot}, @path);
}
sub render_table {
}
sub render_el {
- my ($self, $whole, $part) = @_;
+ my ($self, $whole, $key, $part) = @_;
if (ref($part) eq 'ARRAY') {
return join(', ', @$part);
}
if (ref($part) eq 'HASH') {
if ($whole->{key}) {
return $self->link_to($whole->{key})
+ } elsif ($whole->{name}) {
+ return $self->link_to($whole->{name}, $key);
}
$part = '(complex)';
}