OSDN Git Service

Plugin::NewslashHelpers: add page_type() and content_type() helper function
authorhylom <hylom@users.sourceforge.jp>
Fri, 29 Jun 2018 12:06:58 +0000 (21:06 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 29 Jun 2018 12:06:58 +0000 (21:06 +0900)
src/newslash_web/lib/Newslash/Plugin/NewslashHelpers.pm
src/newslash_web/templates/common/sidebar.html.tt2

index 5b47526..8ea380c 100644 (file)
@@ -1,18 +1,41 @@
 package Newslash::Plugin::NewslashHelpers;
 use Mojo::Base 'Mojolicious::Plugin';
 use Mojo::JSON qw(to_json from_json);
-
+use Mojo::Util qw(decamelize);
 use Template;
 
 sub register {
     my ($self, $app, $conf) = @_;
     $self->{app} = $app;
 
-    for my $k (qw[boxes format_timestamp]) {
+    for my $k (qw[boxes format_timestamp page_type content_type]) {
         $app->helper($k => $self->can("_$k"))
     }
 }
 
+sub _page_type {
+    my $c = shift;
+    if ($c->stash("page")) {
+        return $c->stash("page")->{type};
+    }
+
+    my $cls = ref($c);
+    if ($cls =~ /^Newslash::Web::Controller::/) {
+        $cls =~ s/^Newslash::Web::Controller:://;
+        $cls = decamelize($cls);
+        return $cls;
+    }
+    return;
+}
+
+sub _content_type {
+    my $c = shift;
+    if ($c->stash("page")) {
+        return $c->stash("page")->{content_type};
+    }
+    return;
+}
+
 sub _boxes {
     my $c = shift;
 
index 2f51b2d..c15466d 100644 (file)
@@ -1,6 +1,6 @@
 <div class="sidebar">
 
-  [%- IF page.type == "timeline" || page.type == "archive" || page.type == "tag" || page.type == "my" -%]
+  [%- IF page.type == "timeline" || page.type == "archive" || page.type == "tag" || helpers.page_type() == "my" -%]
   [%- helpers.ad_code("sidebar-top") -%]
   [%- FOREACH box IN helpers.boxes() -%]
   <div class="sidebar-item [% box.type %] [% box.name %]">