Commit | Line | Data |
632f0e07 |
1 | package App::SCS::Plugin::Core; |
2 | |
0034f151 |
3 | use Module::Runtime qw(use_module); |
4 | use IO::All; |
632f0e07 |
5 | use Moo; |
6 | no warnings::illegalproto; |
7 | use Safe::Isa; |
8 | |
9 | with 'App::SCS::Role::Plugin'; |
10 | |
11 | has templates => (is => 'lazy'); |
12 | |
13 | sub _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 | |
23 | has includes => (is => 'lazy'); |
24 | |
25 | sub _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 | |
32 | sub page_plugins { |
33 | my ($self) = @_; |
34 | PageList => 'App::SCS::Plugin::Core::PagePlugin::PageList', |
e2e7175f |
35 | RemovePlugin => 'App::SCS::Plugin::Core::PagePlugin::RemovePlugin', |
632f0e07 |
36 | Template => { |
37 | class => 'App::SCS::Plugin::Core::PagePlugin::Template', |
0034f151 |
38 | config => sub { templates => $self->templates }, |
632f0e07 |
39 | }, |
40 | Include => { |
41 | class => 'App::SCS::Plugin::Core::PagePlugin::Include', |
0034f151 |
42 | config => sub { includes => $self->includes }, |
632f0e07 |
43 | }, |
0023adab |
44 | PageData => { |
45 | class => 'App::SCS::Plugin::Core::PagePlugin::PageData', |
46 | config => sub { static_dir => $self->app->share_dir->catdir('static') } |
47 | } |
632f0e07 |
48 | } |
49 | |
50 | sub default_page_plugins { |
51 | Template => { |
52 | name => 'layout', |
53 | }, |
54 | PageData => {}, |
55 | } |
56 | |
57 | sub page_dispatchers { |
58 | my ($self) = @_; |
59 | sub (/) { |
60 | $self->pages->get({ path => 'index' }); |
61 | }, |
62 | sub (/**) { |
63 | [ 302, [ 'Location' => "/$_[1]/" ], [] ] |
64 | }, |
65 | sub (/**:path/) { |
66 | $self->pages->get({ %_ }) |
67 | }, |
68 | sub () { |
69 | $self->pages |
70 | ->get({ path => 'error_404' }) |
71 | ->$_call_if_object(with_plugin_config => Status => 404); |
72 | }, |
73 | } |
74 | |
2f1cc197 |
75 | sub provides_pages { |
76 | my ($self) = @_; |
77 | "/", map "$_/", $self->pages->all_paths; |
78 | } |
79 | |
632f0e07 |
80 | 1; |