1. Toby Inkster
  2. p5-demiblog4

Commits

Toby Inkster  committed 1eb7c33 Draft

blogindex rdfa serializer

  • Participants
  • Parent commits 5513c68
  • Branches default

Comments (0)

Files changed (2)

File lib/Demiblog4/Transformer/Graph.pm

View file
 use HTTP::Negotiate;
 use RDF::Trine::Serializer;
 use RDF::RDFa::Generator;
+use RDF::RDFa::Generator::Demiblog4::BlogIndex;
 use RDF::RDFa::Generator::Demiblog4::SingleResource;
 use HTML::HTML5::Writer;
 
 }
 
 handle transform_html ($flavour, $mediatype)
-{
-	my $entitler = $ctxt->app->entitler;
-	my $title    =
-		$entitler->title(RDF::Trine::Node::Resource::->new($ctxt->data_subject))
-		// $ctxt->data_subject;
-	
+{	
 	my $style = 'Demiblog4::General';
 	$style = 'Demiblog4::SingleResource'
 		if !ref $ctxt->data_subject;
 	$style = 'Demiblog4::BlogIndex'
 		if ref $ctxt->data_subject eq 'ARRAY';
 	
+	my $entitler = $ctxt->app->entitler;
+	my $title;
+	my $ts_handling;
+	if (ref $ctxt->data_subject eq 'ARRAY')
+	{
+		$ts_handling = !!1;
+		$title = 'Blog';
+	}
+	else
+	{
+		$ts_handling = !!0;
+		$title =
+			$entitler->title(RDF::Trine::Node::Resource::->new($ctxt->data_subject))
+			// $ctxt->data_subject;
+	}
+	
 	my $ser = RDF::RDFa::Generator::->new(
-		style     => $style,
-		subject   => $ctxt->data_subject,
-		entitler  => $entitler,
-		title     => $title,
+		style              => $style,
+		subject            => $ctxt->data_subject,
+		entitler           => $entitler,
+		title              => $title,
+		timestamp_handling => $ts_handling,
 	);
 	my $writer = HTML::HTML5::Writer::->new(
 		markup   => $flavour,

File lib/RDF/RDFa/Generator/Demiblog4/BlogIndex.pm

View file
+package RDF::RDFa::Generator::Demiblog4::BlogIndex;
+
+use Demiblog4::Sugar
+	-types => -all;
+use MooseX::NonMoose;
+extends 'RDF::RDFa::Generator::HTML::Hidden';
+with 'Demiblog4::RDFa::ResourceOutput';
+
+# vaguely interesting inherited attributes
+has qwa[ base namespaces title ] => (is => read_only);
+
+has subject => (
+	is         => read_only,
+	isa        => ArrayRef,
+	required   => true,
+);
+
+method nodes ($input)
+{
+	my ($pd_hash, $secondary_data) = $self->_split_data($input);
+	
+	my @nodes =
+		map {
+			$self->resource_output(
+				$pd_hash->{$_},
+				$_,
+			)
+		}
+		@{ $self->subject };
+	
+	push @nodes, $self->SUPER::nodes($secondary_data);
+	
+	return @nodes;
+}
+
+method _split_data ($input)
+{
+	my $primary   = {};
+	my $secondary = RDF::Trine::Model::->new;
+	my $topic     = $self->subject;
+	
+	my $iter = $input->get_statements((undef)x4);
+	while (my $st = $iter->next)
+	{
+		if ($st->subject->is_resource and $st->subject->uri ~~ $topic)
+		{
+			($primary->{ $st->subject->uri } //= RDF::Trine::Model::->new)
+				->add_statement($st);
+		}
+		elsif ($st->object->is_resource and $st->object->uri ~~ $topic)
+		{
+			($primary->{ $st->object->uri } //= RDF::Trine::Model::->new)
+				->add_statement($st);
+		}
+		else
+		{
+			$secondary->add_statement($st);
+		}
+	}
+	
+	($primary, $secondary)
+}
+