8 package SCSite::Link; use Moo; has $_ => (is => 'ro') for qw(title to);
11 has _topbar => (is => 'ro', default => sub { [
12 map SCSite::Link->new(title => $_->[0], to => $_->[1] ),
13 map [ /^(.*?)\s+(\S+)$/ ],
14 split("\n", <<'ENDBAR')
20 Professional Services /services
26 has pages => (is => 'lazy');
28 has _layout_zoom => (is => 'lazy');
32 pages_dir => 'share/content',
33 template_dir => 'share/skin',
39 SCSite::PageSet->new(base_dir => $self->config->{pages_dir})
42 sub dispatch_request {
45 $self->_http_response(500 => 'text/plain' => 'Not implemented');
48 $self->_page_http_response(200 => $self->_find_page('index'));
51 [ 302, [ 'Location' => "/$_[1]/" ], [] ]
54 my ($code, $page) = map {
55 $_ ? (200, $_) : (404, $self->_error_page(404))
56 } $self->_find_page($_[1]);
57 $self->_page_http_response($code => $page);
62 my ($self, $code) = @_;
63 $self->_find_page("error_${code}");
67 my ($self, $path) = @_;
68 $self->pages->get({ path => $path });
72 my ($self, $code, $type, $content) = @_;
73 [ $code, [ 'Content-type' => $type ], [ $content ] ];
76 sub _page_http_response {
77 my ($self, $code, $page) = @_;
78 [ $code, [ 'Content-type' => 'text/html' ], $self->_render_page($page) ];
82 my ($self, $page) = @_;
83 my $zoom = $self->_layout_zoom;
84 $zoom->select('.title')->replace_content($page->title)
85 ->select('meta[name=description]')->replace_content($page->description)
86 ->select('meta[name=keywords]')->replace_content($page->keywords)
87 ->select('.topbar_entries')->repeat_content([
88 map { my $e = $_; sub {
89 $_->select('.entry')->replace_content($e->title)
90 ->then->set_attribute(href => $e->to)
93 ->select('.main')->replace_content(\$page->body)
97 sub _build__layout_zoom {
99 HTML::Zoom->from_file(
100 io->dir($self->config->{template_dir})->catfile('layout.html')
105 return $_[0]->to_psgi_app if caller(1);
107 my @config_keys = keys %{{$class->default_config}};
108 require Getopt::Long;
110 Getopt::Long::GetOptions(
111 map +("$_=s" => \$config{$_}), @config_keys
113 delete $config{$_} for grep !defined($config{$_}), keys %config;
114 my $new = $class->new(config => \%config);
118 __PACKAGE__->run_if_script;