4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web'; |
6 |
|
|
|
use MooseX::Types::Moose qw(Str Int ArrayRef); |
|
|
use MooseX::Types::Structured qw/Dict/; |
|
|
|
|
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
|
|
9 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
10 |
|
|
11 |
present C<sponge> as Exhibit from L<http://simile.mit.edu/exhibit/> |
present C<sponge> as Exhibit from L<http://simile.mit.edu/exhibit/> |
12 |
|
|
13 |
|
=head1 SEE ALSO |
14 |
|
|
15 |
|
L<Frey::View::Exhibit::JSON> |
16 |
|
|
17 |
=cut |
=cut |
18 |
|
|
19 |
has sponge => ( |
has pipe => ( |
20 |
is => 'rw', |
is => 'rw', |
21 |
isa => Dict[ |
isa => 'Str', |
22 |
rows => ArrayRef[ArrayRef], |
required => 1, |
23 |
NAME => ArrayRef[Str], |
default => 'Frey::DelIcioUs/as_sponge|Frey::View::Exhibit::JSON/as_markup', |
|
], |
|
|
# required => 1, |
|
24 |
); |
); |
25 |
|
|
|
sub as_data { |
|
|
my ($self) = @_; |
|
|
|
|
|
confess "need sponge" unless $self->as_sponge; |
|
|
|
|
|
my $items; |
|
|
my $names = $self->as_sponge->{NAME}; |
|
|
|
|
|
my $id = 0; |
|
|
my $have_id = grep { m{^id$} } @$names; |
|
|
my $have_label = grep { m{^label$} } @$names; |
|
|
|
|
|
foreach my $row ( @{ $self->as_sponge->{rows} } ) { |
|
|
my $item; |
|
|
map { $item->{ $names->[$_] } = $row->[$_] } ( 0 .. $#{ $row } ); |
|
|
$item->{id} = $id unless $have_id; |
|
|
$item->{label} = $id unless $have_label; |
|
|
$id++; |
|
|
push @{ $items->{items} }, $item; |
|
|
} |
|
|
|
|
|
return $items; |
|
|
} |
|
|
|
|
26 |
sub depends { |
sub depends { |
27 |
my ($self) = @_; |
my ($self) = @_; |
28 |
$self->add_head(qq{ |
my $pipe = $self->url_escape( $self->pipe ); |
29 |
<link href="/Frey::Pipe/as_markup?pipe=Frey::DelIcioUs/as_sponge|Frey::View::Exhibit/as_data|Frey::View::JSON/as_markup" |
$self->add_head(qq| |
30 |
type="application/json" rel="exhibit/data" /> |
<link href="/Frey::Pipe/as_markup?pipe=$pipe" type="application/json" rel="exhibit/data" /> |
31 |
}); |
|); |
32 |
$self->add_head(qq| |
$self->add_head(qq| |
33 |
<script src="http://static.simile.mit.edu/exhibit/api-2.0/exhibit-api.js" |
<script src="http://static.simile.mit.edu/exhibit/api-2.0/exhibit-api.js" |
34 |
type="text/javascript"></script> |
type="text/javascript"></script> |