Skip to content

Commit 34a0be8

Browse files
committed
Add uri()
1 parent f72e1c0 commit 34a0be8

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ t/05-vars.t
1515
t/data1/in/index.html.md
1616
t/data1/in/static.txt
1717
t/data1/layouts/page
18+
t/data1/site.yml
1819
t/data2/in/index.html.md
1920
t/data2/in/static.txt
2021
t/data2/in/test.html.md

Makefile.PL

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ WriteMakefile(
2121
'Text::FrontMatter::YAML' => 0,
2222
'Path::Tiny' => 0,
2323
'YAML::XS' => 0,
24+
'Sys::Hostname' => 0,
25+
URI => 0,
2426
},
2527

2628
META_MERGE => {

lib/App/Aphra.pm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ use Getopt::Long;
3434
use Carp;
3535
use Clone 'clone';
3636
use YAML::XS 'LoadFile';
37+
use Sys::Hostname;
38+
use URI;
3739

3840
use App::Aphra::File;
3941

@@ -163,6 +165,27 @@ sub _build_template {
163165
);
164166
}
165167

168+
has uri => (
169+
isa => 'URI',
170+
is => 'ro',
171+
lazy_build => 1,
172+
);
173+
174+
sub _build_uri {
175+
my $self = shift;
176+
177+
return URI->new($self->site_vars->{uri}) if $self->site_vars->{uri};
178+
179+
my $host = $self->site_vars->{host} || hostname;
180+
my $protocol = $self->site_vars->{protocol} || 'https';
181+
182+
my $uri = "$protocol://$host";
183+
$uri .= ':' . $self->site_vars->{port} if $self->site_vars->{port};
184+
$uri .= '/';
185+
186+
return URI->new($uri);
187+
}
188+
166189
sub run {
167190
my $self = shift;
168191

lib/App/Aphra/File.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ sub process {
113113

114114
$self->app->template->process($template, {
115115
page => ($front_matter->frontmatter_hashref // {}),
116+
file => $self,
116117
}, $out)
117118
or croak $self->app->template->error;
118119
} else {

t/04-run.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ for ($outfile, $outfile2) {
2222
unlink $_ if -r $_;
2323
}
2424

25-
App::Aphra->new->run;
25+
my $app = App::Aphra->new;
26+
is($app->uri, 'https://example.com/', 'Correct URI');
27+
$app->run;
2628

2729
ok(-e $outfile, 'Got an output file');
2830
ok(-f $outfile, "... and it's a real file");

t/data1/site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uri : https://example.com/

0 commit comments

Comments
 (0)