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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/AtteanX/Serializer/SPARQLHTML.pm
Expand Up @@ -141,6 +141,22 @@ Serializes the L<Attean::API::Term> object as HTML.
s/</&lt;/g;
}
my $html = $uri;

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

if ($abr) {
return qq[<a href="${html}">$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>];
# }
Expand All @@ -162,6 +178,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
@@ -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');
is ($s->node_as_html($n2), 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'Return plain IRI - 1');

}

NO_NAMESPACEMAP:{

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

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

}