-package Newslash::Plugin::QuasiStaticContent;
+package Newslash::Plugin::Preprocessor;
use Mojo::Base 'Mojolicious::Plugin';
use File::Spec;
#my $contents = $self->{contents};
#$app->log->debug(dumper($contents));
- if ($app->config->{TT2Renderer}) {
- my $tt2r = $app->config->{TT2Renderer}->{self};
- my $get_content = sub {
- my ($c, $name) = @_;
- my $content = $self->get_cache($name);
- if ($content) {
- return $content->{path};
- }
- else {
- $self->{app}->log->debug("QSC: no cache found for '$name'");
- }
- return '';
- };
- $tt2r->add_NS_function('static_content', $get_content);
- $tt2r->add_NS_function('generated_content', $get_content);
- }
-
my $r = $app->routes;
$r->any('/static/*content_path' => sub {
my $c = shift;
$c->rendered(404);
});
- $app->helper(static_content => sub { state $static_content = $self; });
+ $app->helper(preprocessor => sub { state $preprocessor = $self; });
+}
+
+sub get_path {
+ my ($self, $name) = @_;
+ my $content = $self->get_cache($name);
+ if ($content) {
+ return $content->{path};
+ }
+ else {
+ $self->{app}->log->debug("QSC: no cache found for '$name'");
+ }
+ return;
}
sub _execute_cmd {
$app->plugin('Newslash::Plugin::AntiCsrf');
}
- # quasi-static content
- $app->plugin('Newslash::Plugin::QuasiStaticContent');
+ # contents preprocessor
+ $app->plugin('Newslash::Plugin::Preprocessor');
# javascript loader
$app->plugin('Newslash::Plugin::JavaScriptLoader');
acl2_types => \@acl2_types,
};
my $siteconfig = $app->tt2renderer->render($templ_name, $vars);
- $app->static_content->add_content("js/siteconfig.js", $siteconfig, "text/javascript; charset=utf-8");
+ $app->preprocessor->add_content("js/siteconfig.js", $siteconfig, "text/javascript; charset=utf-8");
############################################################
#
<!-- Latest compiled and minified CSS -->
<script src="/jquery/jquery-3.1.1.min.js"></script>
- <link rel="stylesheet" type="text/css" href="[% NS.static_content('css/bootstrap.css'); %]" />
- <link rel="stylesheet" type="text/css" media="screen, projection" href="[% NS.static_content('css/newslash.css'); %]" />
+ <link rel="stylesheet" type="text/css" href="[% helpers.preprocessor.get_path('css/bootstrap.css'); %]" />
+ <link rel="stylesheet" type="text/css" media="screen, projection" href="[% helpers.preprocessor.get_path('css/newslash.css'); %]" />
<script src="/bootstrap/js/bootstrap.min.js" ></script>
<script src="/js/newslash.js"></script>