diff options
author | Marius Halden <marius.h@lden.org> | 2016-03-28 20:38:28 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-03-28 20:38:28 +0200 |
commit | 6c1118dbf2c4b15bcfcd77600d36f2389428c75e (patch) | |
tree | da81756a344a89502df5479b860b6f4a24b6ed92 /perllib/FixMyStreet/App/Controller/About.pm | |
parent | a2d67ca6de255ff04badb7cb5a62f7d3df3ce293 (diff) | |
parent | 4345263c9de752454795ad57323e684e41e702a8 (diff) |
Merge tag 'v1.8.1' into fiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/About.pm')
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/About.pm | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/About.pm b/perllib/FixMyStreet/App/Controller/About.pm new file mode 100755 index 000000000..78e548c5f --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/About.pm @@ -0,0 +1,67 @@ +package FixMyStreet::App::Controller::About; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::About - Catalyst Controller + +=head1 DESCRIPTION + +About pages Catalyst Controller. + +=head1 METHODS + +=cut + +my %found; + +sub page : Path("/about") : Args(1) { + my ( $self, $c, $page ) = @_; + my $template = $c->forward('find_template'); + $c->detach('/page_error_404_not_found', []) unless $template; + $c->stash->{template} = $template; +} + +sub index : Path("/about") : Args(0) { + my ( $self, $c ) = @_; + $c->forward('page', [ 'about' ]); +} + +# We have multiple possibilities to try, and we want to cache where we find it +sub find_template : Private { + my ( $self, $c, $page ) = @_; + + return $found{$page} if !FixMyStreet->config('STAGING_SITE') && exists $found{$page}; + + my $lang_code = $c->stash->{lang_code}; + foreach my $dir_templates (@{$c->stash->{additional_template_paths}}, @{$c->view('Web')->paths}) { + foreach my $dir_static (static_dirs($page, $dir_templates)) { + foreach my $file ("$page-$lang_code.html", "$page.html") { + if (-e "$dir_templates/$dir_static/$file") { + $found{$page} = "$dir_static/$file"; + return $found{$page}; + } + } + } + } + # Cache that the page does not exist, so we don't look next time + $found{$page} = undef; + return $found{$page}; +} + +sub static_dirs { + my ($page, $dir_templates) = @_; + my @v = ("about"); + # If legacy directories exist, check for templates there too; + # The FAQ page used to be in its own directory + push @v, "static" if -d "$dir_templates/static"; + push @v, "faq" if -d "$dir_templates/faq" && $page =~ /faq/; + return @v; +} + +__PACKAGE__->meta->make_immutable; + +1; |