diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-02-23 22:10:37 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-02-23 22:10:37 +0000 |
commit | 3ef36c3c9b5393c78c0af59b9f4e3f4528472357 (patch) | |
tree | 74e1118ae16bdd0e7cbb9f206248883c59de51e0 /perllib/FixMyStreet/App.pm | |
parent | b6ef8d10c3ec7164c65d81b75ecf2662952aeb6d (diff) |
More work on the Cobrand and setting for request
test to see welsh about us page
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 870453b09..bc9bd7672 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -3,6 +3,10 @@ use Moose; use namespace::autoclean; use Catalyst::Runtime 5.80; +use FixMyStreet; +use FixMyStreet::Cobrand; +use Memcached; +use Problems; use Catalyst qw/ ConfigLoader @@ -13,11 +17,6 @@ extends 'Catalyst'; our $VERSION = '0.01'; -BEGIN { - use mySociety::Config; - mySociety::Config::set_file( __PACKAGE__->path_to("conf/general") ); -} - # Configure the application. # # Note that settings in fixmystreet_app.conf (or other external @@ -28,7 +27,9 @@ BEGIN { # local deployment. __PACKAGE__->config( - %{ mySociety::Config::get_list() }, + + # get the config from the core object + %{ FixMyStreet->config() }, name => 'FixMyStreet::App', @@ -37,7 +38,7 @@ __PACKAGE__->config( # Serve anything in web dir that is not a .cgi script static => { # - include_path => [ __PACKAGE__->path_to("web") . "" ], + include_path => [ FixMyStreet->path_to("web") . "" ], ignore_extensions => ['cgi'], } ); @@ -55,20 +56,67 @@ FixMyStreet::App - Catalyst based application =head1 DESCRIPTION -[enter your description here] +FixMyStreet.com codebase -=head1 SEE ALSO +=head1 METHODS -L<FixMyStreet::App::Controller::Root>, L<Catalyst> +=head2 cobrand + + $cobrand = $c->cobrand(); + +Returns the cobrand object. If not already determined this request finds it and +caches it to the stash. + +=cut + +sub cobrand { + my $c = shift; + return $c->stash->{cobrand} ||= $c->_get_cobrand(); +} + +sub _get_cobrand { + my $c = shift; + my $host = $c->req->uri->host; + my $cobrand_class = FixMyStreet::Cobrand->get_class_for_host($host); + return $cobrand_class->new( { request => $c->req } ); +} -=head1 AUTHOR +=head2 setup_cobrand -Edmund von der Burg,,, + $cobrand = $c->setup_cobrand(); -=head1 LICENSE +Work out which cobrand we should be using. Set the environment correctly - eg +template paths -This library is free software. You can redistribute it and/or modify -it under the same terms as Perl itself. +=cut + +sub setup_cobrand { + my $c = shift; + my $cobrand = $c->cobrand; + + # append the cobrand templates to the include path + $c->stash->{additional_template_paths} = + [ $cobrand->path_to_web_templates . '' ]; + + my $host = $c->req->uri->host; + my $lang = + $host =~ /^en\./ ? 'en-gb' + : $host =~ /cy/ ? 'cy' + : undef; + + # set the language and the translation file to use + $cobrand->set_lang_and_domain( $lang, 1 ); + + Problems::set_site_restriction_with_cobrand_object($cobrand); + + Memcached::set_namespace( FixMyStreet->config('BCI_DB_NAME') . ":" ); + + return $cobrand; +} + +=head1 SEE ALSO + +L<FixMyStreet::App::Controller::Root>, L<Catalyst> =cut |