Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iri2pref #63

Merged
merged 4 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/AtteanX/Serializer/SPARQLHTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,26 @@ Serializes the L<Attean::API::Term> object as HTML.
s/&/&amp;/g;
s/</&lt;/g;
}
my $html = $uri;
my $html = qq[<a href="${uri}">$uri</a>];

if (my $map = $self->namespaces) {
my $abr = $map->abbreviate($uri);

if ($abr) {
return qq[<a href="${uri}">$abr</a>];
} else {
return $html;
}

} else {

return $html;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have an HTML link, too, with $html as both the href and the link text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Looks like I will have to modify the t/serializer-sparqlhtml.t too since some tests expect the plain IRIs. Or perhaps you want this change only when there is URI::NamespaceMap instance?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it done whether or not there's a namespace map.

I was planning on merging your test file with t/serializer-sparqlhtml.t anyway. So if you don't want to do that, I can take care of it during the merge.

}


# if ($link) {
# $html = qq[<a href="${uri}">$html</a>];
# }
return $html;
} elsif ($node->does('Attean::API::Literal')) {
my $html = $node->value;
for ($html) {
Expand All @@ -162,6 +177,7 @@ Serializes the L<Attean::API::Term> object as HTML.
}
}
with 'Attean::API::ResultSerializer';
with 'Attean::API::AbbreviatingSerializer';
}

1;
Expand Down
34 changes: 34 additions & 0 deletions t/issue_54.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use strict;
use warnings;

use Test::More tests => 4;
use Attean;
use Attean::IRI;

my $sclass = Attean->get_serializer('SPARQLHTML');

my $map = URI::NamespaceMap->new( {
foaf => 'http://xmlns.com/foaf/0.1/'
});

my $n1 = Attean::IRI->new('http://xmlns.com/foaf/0.1/Person');
my $n2 = Attean::IRI->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');

NAMESPACEMAP:{

my $s = $sclass->new(namespaces => $map);

is ($s->node_as_html($n1), '<a href="http://xmlns.com/foaf/0.1/Person">foaf:Person</a>', 'Return HTML link for IRI with abbrev');
is ($s->node_as_html($n2), '<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a>', 'Return HTML link for IRI - 1');

}

NO_NAMESPACEMAP:{

my $s = $sclass->new();

is ($s->node_as_html($n1), '<a href="http://xmlns.com/foaf/0.1/Person">http://xmlns.com/foaf/0.1/Person</a>', 'Return HTML link for IRI - 2');
is ($s->node_as_html($n2), '<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a>', 'Return HTML link for IRI - 3');

}

8 changes: 4 additions & 4 deletions t/serializer-sparqlhtml.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ END
my @rows = ($b =~ /(<tr)/g);
cmp_ok(scalar(@rows), '>=', 4, 'at least 1 header row and 3 data rows');
like($b, qr[<td>x</td>]);
like($b, qr[<td>http://example.org/p</td>]);
like($b, qr[<td><a href="http://example.org/p">http://example.org/p</a></td>]);
like($b, qr[<td>1</td>]);
like($b, qr[<td>x</td>]);
like($b, qr[<td>2</td>]);
like($b, qr[<td>http://perlrdf.org/</td>]);
like($b, qr[<td><a href="http://perlrdf.org/">http://perlrdf.org/</a></td>]);
};

subtest 'serialize_iter_to_io' => sub {
Expand All @@ -58,11 +58,11 @@ END
my @rows = ($b =~ /(<tr)/g);
cmp_ok(scalar(@rows), '>=', 4, 'at least 1 header row and 3 data rows');
like($b, qr[<td>x</td>]);
like($b, qr[<td>http://example.org/p</td>]);
like($b, qr[<td><a href="http://example.org/p">http://example.org/p</a></td>]);
like($b, qr[<td>1</td>]);
like($b, qr[<td>x</td>]);
like($b, qr[<td>2</td>]);
like($b, qr[<td>http://perlrdf.org/</td>]);
like($b, qr[<td><a href="http://perlrdf.org/">http://perlrdf.org/</a></td>]);
};
}

Expand Down