OSDN Git Service

Plugin::NewslashHelpers: add "declare" and "insert_code" helper
authorhylom <hylom@users.sourceforge.jp>
Fri, 24 Aug 2018 12:28:52 +0000 (21:28 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 24 Aug 2018 12:28:52 +0000 (21:28 +0900)
src/newslash_web/lib/Newslash/Plugin/NewslashHelpers.pm

index 7306c32..d38bfaa 100644 (file)
@@ -8,11 +8,30 @@ sub register {
     my ($self, $app, $conf) = @_;
     $self->{app} = $app;
 
-    for my $k (qw[boxes format_timestamp page_type content_type site_config]) {
+    for my $k (qw[boxes format_timestamp page_type content_type site_config
+                  declare insert_code]) {
         $app->helper($k => $self->can("_$k"))
     }
 }
 
+use constant MARKERS => qw(begin_footer);
+my $marker_contents = {};
+
+sub _insert_code {
+    my ($c, $marker, $content) = @_;
+    if(!$marker_contents->{$marker}) {
+        $marker_contents->{$marker} = [];
+    }
+    push @{$marker_contents->{$marker}}, $content;
+}
+
+sub _declare {
+    my ($c, $name) = @_;
+    my $contents = $marker_contents->{$name} || [];
+
+    return join("\n", @$contents);
+}
+
 sub _generate_site_config {
     my $c = shift;
     my $epoch = $c->stash('epoch');