Просмотр исходного кода

Fix various bugs with themed styles, allow print styles to be theme overridden

George Baugh 2 лет назад
Родитель
Сommit
1eef103b08
3 измененных файлов с 20 добавлено и 13 удалено
  1. 13 13
      lib/Trog/Routes/HTML.pm
  2. 4 0
      lib/Trog/Themes.pm
  3. 3 0
      www/templates/html/components/header.tx

+ 13 - 13
lib/Trog/Routes/HTML.pm

@@ -225,15 +225,10 @@ sub index ( $query, $content = '', $i_styles = [] ) {
     $content ||= Trog::Renderer->render( template => $to_render, data => $query, component => 1, contenttype => 'text/html' );
 
     my @styles = ('avatars.css');
-    if ($Trog::Themes::theme_dir) {
-        if ( $query->{embed} ) {
-            unshift( @styles, Trog::Themes::themed_style("embed.css") ) if -f 'www/' . Trog::Themes::themed_style("embed.css");
-        }
-        unshift( @styles, Trog::Themes::themed_style("screen.css") )    if -f 'www/' . Trog::Themes::themed_style("screen.css");
-        unshift( @styles, Trog::Themes::themed_style("print.css") )     if -f 'www/' . Trog::Themes::themed_style("print.css");
-        unshift( @styles, Trog::Themes::themed_style("structure.css") ) if -f 'www/' . Trog::Themes::themed_style("structure.css");
-    }
+    unshift( @styles, qw{embed.css}) if $query->{embed};
+    unshift( @styles, qw{screen.css structure.css});
     push( @styles, @$i_styles );
+    my @p_styles = qw{print.css};
 
     #TODO allow theming of print css
     my @series = _get_series(0);
@@ -262,6 +257,7 @@ sub index ( $query, $content = '', $i_styles = [] ) {
             footbar      => Trog::Renderer->render( template => $footbar,   data => $query, component => 1, contenttype => 'text/html' ),
             categories   => \@series,
             stylesheets  => \@styles,
+            print_styles => \@p_styles,
             show_madeby  => $Theme::show_madeby ? 1 : 0,
             embed        => $query->{embed}     ? 1 : 0,
             embed_video  => $query->{primary_post}{is_video},
@@ -1365,7 +1361,7 @@ sub manual ($query) {
 # basically a file rewrite rule for themes
 sub icon ($query) {
     my $path = $query->{route};
-    return Trog::FileHandler::serve("$Trog::Themes::td/img/icon/$path");
+    return Trog::FileHandler::serve(Trog::Themes::themed("img/icon/$path"));
 }
 
 # TODO make statics, abstract gzipped outputting & header handling
@@ -1400,12 +1396,16 @@ sub finish_render ( $template, $vars, %headers ) {
     $vars->{scripts}     //= [];
 
     # Theme-ize the paths
-    $vars->{stylesheets} = _build_themed_styles($vars->{stylesheets});
-    $vars->{scripts}     = _build_themed_scripts($vars->{scripts});
+    $vars->{stylesheets}  = [grep { -f "www/$_" } @{_build_themed_styles($vars->{stylesheets})}];
+    $vars->{print_styles} = [grep { -f "www/$_" } @{_build_themed_styles($vars->{p_styles})}];
+    $vars->{scripts}      = [grep { -f "www/$_" } @{_build_themed_scripts($vars->{scripts})}];
+
+    print Dumper($vars->{stylesheets});
 
     # Absolute-ize the paths for scripts & stylesheets
-    @{ $vars->{stylesheets} } = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{stylesheets} };
-    @{ $vars->{scripts} }     = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{scripts} };
+    @{ $vars->{stylesheets} }  = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{stylesheets} };
+    @{ $vars->{print_styles} } = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{print_styles} };
+    @{ $vars->{scripts} }      = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{scripts} };
 
     # TODO Smash together the stylesheets and minify
 

+ 4 - 0
lib/Trog/Themes.pm

@@ -39,6 +39,10 @@ sub _dir_for_resource ($resource) {
     return $theme_dir && -f "www/$theme_dir/$resource" ? $theme_dir : '';
 }
 
+sub themed ($resource) {
+    return _dir_for_resource("$resource") . "/$resource";
+}
+
 sub themed_style ($resource) {
     return _dir_for_resource("styles/$resource") . "/styles/$resource";
 }

+ 3 - 0
www/templates/html/components/header.tx

@@ -41,6 +41,9 @@
         : for $stylesheets -> $stylesheet {
         <link rel="stylesheet" type="text/css" href="<: $stylesheet :>" media="screen" />
         : }
+        : for $print_styles -> $print_style {
+        <link rel="stylesheet" type="text/css" href="<: $print_style :>" media="print" />
+        : }
         : for $scripts -> $script {
         <script type="text/javascript" src="<: $script :>"></script>
         : }