From: Matt S Trout Date: Tue, 8 Feb 2011 23:32:30 +0000 (+0000) Subject: URL generation for SubList X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34597fb2ec25323b95cd300178bfd82bdbfb4d04;p=scpubgit%2FSCS.git URL generation for SubList --- diff --git a/lib/SCSite/Page.pm b/lib/SCSite/Page.pm index 223b92b..a0e5c15 100644 --- a/lib/SCSite/Page.pm +++ b/lib/SCSite/Page.pm @@ -3,15 +3,16 @@ package SCSite::Page; use IO::All; use Moo; -has $_ => (is => 'ro') for qw(title description keywords body created); +has $_ => (is => 'ro') for qw(title description keywords body created path); -has "_$_" => (is => 'ro', init_arg => $_) for qw(page_set path); +has "_$_" => (is => 'ro', init_arg => $_) for qw(page_set); sub children { my ($self) = @_; my $ps = $self->_page_set; (ref $ps)->new( - base_dir => io->dir($ps->base_dir)->catdir($self->_path), + top_dir => $ps->base_dir, + base_dir => io->dir($ps->base_dir)->catdir($self->path), max_depth => 1 ); } diff --git a/lib/SCSite/PageSet.pm b/lib/SCSite/PageSet.pm index f9db60d..3f7d307 100644 --- a/lib/SCSite/PageSet.pm +++ b/lib/SCSite/PageSet.pm @@ -8,9 +8,18 @@ use Syntax::Keyword::Gather; use SCSite::Page; use Moo; +has top_dir => (is => 'ro', lazy => 1, builder => 'base_dir'); has base_dir => (is => 'ro', required => 1); has max_depth => (is => 'ro', default => quote_sub q{ 0 }); +has rel_path => (is => 'lazy'); + +sub _build_rel_path { + my ($self) = @_; + io->dir('/') + ->catdir(File::Spec->abs2rel($self->base_dir->name, $self->top_dir->name)) +} + sub get { my ($self, $spec) = @_; $spec->{path} or die "path is required to get"; @@ -26,7 +35,9 @@ sub get { die "multiple files found for ${\$spec->{path}}:\n".join "\n", @poss if @poss > 1; return undef unless @poss; - $self->${\"_inflate_${type}"}($spec->{path}, $poss[0]->all); + $self->${\"_inflate_${type}"}( + $self->rel_path->catdir($spec->{path}), $poss[0]->all + ); } sub map { @@ -37,10 +48,11 @@ sub map { sub flatten { my ($self) = @_; my %seen; + my $slash = io->dir('/'); map { my ($path, $type) = $_->name =~ /^(.*)${\$self->_types_re}$/; $self->${\"_inflate_${type}"}( - File::Spec->abs2rel($path, $self->base_dir->name), $_->all + $slash->catdir(File::Spec->abs2rel($path, $self->top_dir->name)), $_->all ); } io->dir($self->base_dir) ->filter(sub { $_->filename =~ /${\$self->_types_re}$/ }) diff --git a/lib/SCSite/SubListFilter.pm b/lib/SCSite/SubListFilter.pm index 8b6f99e..4246bd6 100644 --- a/lib/SCSite/SubListFilter.pm +++ b/lib/SCSite/SubListFilter.pm @@ -14,6 +14,7 @@ sub _filter_stream { $_->select('.entry.title')->replace_content($o->title) ->select('.entry.description')->replace_content($o->description) ->select('.entry.created')->replace_content($o->created) + ->select('.entry.link')->set_attribute(href => $o->path); } })); } diff --git a/t/pages/one/withkids.html b/t/pages/one/withkids.html index 2d85209..a92f08c 100644 --- a/t/pages/one/withkids.html +++ b/t/pages/one/withkids.html @@ -6,7 +6,7 @@

withkids test

-
+