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
);
}
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";
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 {
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}$/ })
$_->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);
}
}));
}