[librdf-rdfa-generator-perl] 09/64: Minor changes for RDF-RDFa-Linter.

Jonas Smedegaard dr at jones.dk
Sat Dec 23 12:22:50 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.106-1
in repository librdf-rdfa-generator-perl.

commit bd30f96ca1410dbebfec5dc5da2901728cec5539
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Sun May 16 22:34:15 2010 +0000

    Minor changes for RDF-RDFa-Linter.
    
    --HG--
    branch : RDF-RDFa-Generator
    extra : convert_revision : svn%3A3fe8e991-6959-4966-b76d-b07eca2b6e37/RDF-RDFa-Generator%40353
---
 lib/RDF/RDFa/Generator/HTML/Head.pm        |  8 ++---
 lib/RDF/RDFa/Generator/HTML/Pretty.pm      | 50 ++++++++++++++++++++++++------
 lib/RDF/RDFa/Generator/HTML/Pretty/Note.pm | 39 +++++++++++++++++++++++
 3 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/lib/RDF/RDFa/Generator/HTML/Head.pm b/lib/RDF/RDFa/Generator/HTML/Head.pm
index eabf435..786f885 100644
--- a/lib/RDF/RDFa/Generator/HTML/Head.pm
+++ b/lib/RDF/RDFa/Generator/HTML/Head.pm
@@ -26,9 +26,9 @@ sub injection_site
 
 sub inject_document
 {
-	my ($proto, $html, $model) = @_;
+	my ($proto, $html, $model, %opts) = @_;
 	my $dom   = $proto->_get_dom($html);
-	my @nodes = $proto->nodes($model);
+	my @nodes = $proto->nodes($model, %opts);
 	
 	my $xc = XML::LibXML::XPathContext->new($dom);
 	$xc->registerNs('xhtml', 'http://www.w3.org/1999/xhtml');
@@ -42,7 +42,7 @@ sub inject_document
 
 sub create_document
 {
-	my ($proto, $model) = @_;
+	my ($proto, $model, %opts) = @_;
 	my $self = (ref $proto) ? $proto : $proto->new;
 	
 	my $html = sprintf(<<HTML, ($self->{'version'}||'1.0'), ($self->{'title'} || 'RDFa Document'), ref $self);
@@ -55,7 +55,7 @@ sub create_document
 </html>
 HTML
 
-	return $proto->inject_document($html, $model);
+	return $proto->inject_document($html, $model, %opts);
 }
 
 sub _get_dom
diff --git a/lib/RDF/RDFa/Generator/HTML/Pretty.pm b/lib/RDF/RDFa/Generator/HTML/Pretty.pm
index 28ce710..65b8516 100644
--- a/lib/RDF/RDFa/Generator/HTML/Pretty.pm
+++ b/lib/RDF/RDFa/Generator/HTML/Pretty.pm
@@ -5,11 +5,12 @@ use base qw'RDF::RDFa::Generator::HTML::Hidden';
 use common::sense;
 use constant XHTML_NS => 'http://www.w3.org/1999/xhtml';
 use Icon::FamFamFam::Silk;
+use RDF::RDFa::Generator::HTML::Pretty::Note;
 use XML::LibXML qw':all';
 
 sub create_document
 {
-	my ($proto, $model) = @_;
+	my ($proto, $model, %opts) = @_;
 	my $self = (ref $proto) ? $proto : $proto->new;
 	
 	my $html = sprintf(<<HTML, ($self->{'version'}||'1.0'), ($self->{'title'} || 'RDFa Document'), ref $self);
@@ -25,12 +26,12 @@ sub create_document
 </html>
 HTML
 
-	return $proto->inject_document($html, $model);
+	return $proto->inject_document($html, $model, %opts);
 }
 
 sub nodes
 {
-	my ($proto, $model) = @_;
+	my ($proto, $model, %opts) = @_;
 	my $self = (ref $proto) ? $proto : $proto->new;
 	
 	my $stream = $self->_get_stream($model);
@@ -57,10 +58,10 @@ sub nodes
 		$self->_resource_heading($subjects->{$s}->[0]->subject, $subject_node, $subjects->{$s}, $prefixes);
 		$self->_resource_classes($subjects->{$s}->[0]->subject, $subject_node, $subjects->{$s}, $prefixes);
 		$self->_resource_statements($subjects->{$s}->[0]->subject, $subject_node, $subjects->{$s}, $prefixes);
-		## TODO Query $model for statements that act as special notes for the subject (in a separate graph)
-		#$self->_resource_notes($subjects->{$s}->[0]->subject, $subject_node, $model);
+		$self->_resource_notes($subjects->{$s}->[0]->subject, $subject_node, $model, $opts{'notes_heading'}||'Notes', $opts{'notes'})
+			if defined $opts{'notes'};
 	}
-	
+
 	if ($self->{'version'} == 1.1
 	and $self->{'prefix_attr'})
 	{
@@ -100,10 +101,6 @@ sub _resource_heading
 	return $self;
 }
 
-## TODO
-## <span rel="rdf:type"><img about="[foaf:Person]" src="fsfwfwfr.png"
-##                           title="http://xmlns.com/foaf/0.1/Person" /></span>
-
 sub _resource_classes
 {
 	my ($self, $subject, $node, $statements, $prefixes) = @_;
@@ -215,10 +212,43 @@ sub _resource_statements
 	return $self;
 }
 
+sub _resource_notes
+{
+	my ($self, $subject, $node, $model, $notes_heading, $notes) = @_;
+	
+	my @relevant;
+	
+	foreach my $note (@$notes)
+	{
+		push @relevant, $note
+			if $note->is_relevant_to($subject);
+	}
+	
+	if (@relevant)
+	{
+		my $heading = $node->addNewChild(XHTML_NS, 'h4');
+		$heading->appendTextNode($notes_heading || 'Notes');
+
+		my $list = $node->addNewChild(XHTML_NS, 'ul');
+
+		foreach my $note (@relevant)
+		{
+			$list->appendChild( $note->node(XHTML_NS, 'li') );
+		}
+	}
+	
+	return $self;
+}
+
 sub _img
 {
 	my ($self, $type) = @_;
 	
+	if ($type eq 'urn:x-rdf-rdfa-linter:internals:OpenGraphProtocolNode')
+	{
+		return 'data:image/png;charset=binary;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oFEBYGBzcdoOEAAALhSURBVCjPJdLfb4trHADw7/d53nbr2661X9ZV29mE/VLMYplwchwnmCziR7iSEHbpQnAj7lxJJBIhJELcSBAh50iErAcJ2wnLRrJstQXdL7Sbtmpv173P3vd9nq8Ln7/hg3/t6BJCAEB9Q/2Na1d8Xt1YmsuaSVsKn7u6Sl/lZjoAIiIAEJG2aJpSyi2dnceOH87I4UfD12fyw7aJ0mIu3fHqZbHa7s4VxwLuECJDRA0Bund3vXz1cmWCjMyzz33uz31e4zsCANcg2Kimtz8Ya32xv+VC1N/BkPM//tzW03MEArN3b/1X6vJ8G+VKYmWUwjEyC [...]
+	}
+	
 	my $icons = {
 		'http://xmlns.com/foaf/0.1/Document'                   => 'page_white_text',
 		'http://xmlns.com/foaf/0.1/Person'                     => 'user',
diff --git a/lib/RDF/RDFa/Generator/HTML/Pretty/Note.pm b/lib/RDF/RDFa/Generator/HTML/Pretty/Note.pm
new file mode 100644
index 0000000..6cde4eb
--- /dev/null
+++ b/lib/RDF/RDFa/Generator/HTML/Pretty/Note.pm
@@ -0,0 +1,39 @@
+package RDF::RDFa::Generator::HTML::Pretty::Note;
+
+use 5.008;
+use common::sense;
+use constant XHTML_NS => 'http://www.w3.org/1999/xhtml';
+use XML::LibXML qw':all';
+
+sub new
+{
+	my ($class, $subject, $text) = @_;
+	
+	return bless {
+		'subject' => $subject,
+		'text'    => $text,
+		}, $class;
+}
+
+sub node
+{
+	my ($self, $namespace, $element) = @_;
+	die "unknown namespace" unless $namespace eq XHTML_NS;
+	
+	my $node = XML::LibXML::Element->new($element);
+	$node->setNamespace($namespace, undef, 1);
+	
+	$node->appendTextNode($self->{'text'});
+	
+	return $node;
+}
+
+sub is_relevant_to
+{
+	my ($self, $something) = @_;
+	return $self->{'subject'}->equal($something);
+}
+
+*is_relevent_to = \&is_relevant_to;
+
+1;
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/librdf-rdfa-generator-perl.git



More information about the Pkg-perl-cvs-commits mailing list