From: Errietta Kostala Date: Thu, 7 Aug 2014 15:31:58 +0000 (+0100) Subject: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0023adab790eca5ebd095f3309eb3678c297b106;p=scpubgit%2FApp-SCS.git = a loading a css file named after the current page. --- diff --git a/lib/App/SCS/Plugin/Core.pm b/lib/App/SCS/Plugin/Core.pm index 7d9dfc6..faf49ba 100644 --- a/lib/App/SCS/Plugin/Core.pm +++ b/lib/App/SCS/Plugin/Core.pm @@ -41,7 +41,10 @@ sub page_plugins { class => 'App::SCS::Plugin::Core::PagePlugin::Include', config => sub { includes => $self->includes }, }, - PageData => 'App::SCS::Plugin::Core::PagePlugin::PageData', + PageData => { + class => 'App::SCS::Plugin::Core::PagePlugin::PageData', + config => sub { static_dir => $self->app->share_dir->catdir('static') } + } } sub default_page_plugins { diff --git a/lib/App/SCS/Plugin/Core/PagePlugin/PageData.pm b/lib/App/SCS/Plugin/Core/PagePlugin/PageData.pm index daf529f..a35d2f4 100644 --- a/lib/App/SCS/Plugin/Core/PagePlugin/PageData.pm +++ b/lib/App/SCS/Plugin/Core/PagePlugin/PageData.pm @@ -4,9 +4,14 @@ use Moo; with 'App::SCS::Role::PagePlugin'; +has static_dir => (is => 'ro', required => 1); + sub filter_content_zoom { my ($self, $zoom) = @_; + my $page = $self->page; + my $static_dir = $self->static_dir; + $zoom->select('.page.title')->replace_content($page->title) ->select('.page.subtitle')->${\sub { $page->subtitle @@ -19,7 +24,14 @@ sub filter_content_zoom { ->select('meta[name=keywords]') ->set_attribute(content => $page->keywords) ->select('meta[name=created]') - ->set_attribute(content => $page->created); + ->set_attribute(content => $page->created) + ->select('link[data-cur-page-css]')->${\sub { + if (-f $static_dir . "/page-css/" . $page->path . ".css") { + $_[0]->set_attribute(href => "/static/page-css/" . $page->path . ".css"); + } else { + $_[0]->replace(''); + } + }} } 1;