first cut at generation to file code
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Core.pm
CommitLineData
632f0e07 1package App::SCS::Plugin::Core;
2
0034f151 3use Module::Runtime qw(use_module);
4use IO::All;
632f0e07 5use Moo;
6no warnings::illegalproto;
7use Safe::Isa;
8
9with 'App::SCS::Role::Plugin';
10
11has templates => (is => 'lazy');
12
13sub _build_templates {
14 my ($self) = @_;
15 return use_module('App::SCS::PageSet')->new(
0034f151 16 base_dir => io->dir($self->app->share_dir)->catdir('templates'),
17 plugin_config => {
18 plugin_map => $self->app->page_plugin_config->{plugin_map}
19 }
632f0e07 20 );
21}
22
23has includes => (is => 'lazy');
24
25sub _build_includes {
26 my ($self) = @_;
27 return use_module('App::SCS::PageSet')->new(
28 base_dir => io->dir($self->app->config->{share_dir})->catdir('includes'),
29 );
30}
31
32sub page_plugins {
33 my ($self) = @_;
34 PageList => 'App::SCS::Plugin::Core::PagePlugin::PageList',
35 Template => {
36 class => 'App::SCS::Plugin::Core::PagePlugin::Template',
0034f151 37 config => sub { templates => $self->templates },
632f0e07 38 },
39 Include => {
40 class => 'App::SCS::Plugin::Core::PagePlugin::Include',
0034f151 41 config => sub { includes => $self->includes },
632f0e07 42 },
43 PageData => 'App::SCS::Plugin::Core::PagePlugin::PageData',
44}
45
46sub default_page_plugins {
47 Template => {
48 name => 'layout',
49 },
50 PageData => {},
51}
52
53sub page_dispatchers {
54 my ($self) = @_;
55 sub (/) {
56 $self->pages->get({ path => 'index' });
57 },
58 sub (/**) {
59 [ 302, [ 'Location' => "/$_[1]/" ], [] ]
60 },
61 sub (/**:path/) {
62 $self->pages->get({ %_ })
63 },
64 sub () {
65 $self->pages
66 ->get({ path => 'error_404' })
67 ->$_call_if_object(with_plugin_config => Status => 404);
68 },
69}
70
2f1cc197 71sub provides_pages {
72 my ($self) = @_;
73 "/", map "$_/", $self->pages->all_paths;
74}
75
632f0e07 761;