Switched to Template::Mustache

This commit is contained in:
swagg boi 2023-11-01 00:52:19 -04:00
parent 2f440817c4
commit 0506335a52
6 changed files with 17 additions and 16 deletions

View file

@ -2,7 +2,7 @@
"name": "Hyperlink-Redirect",
"depends": [
"Humming-Bird",
"Template6",
"Template::Mustache",
"Base64",
"Libarchive::Filter"
],

View file

@ -42,8 +42,6 @@ A "useful" tool for turning hyperlinks into redirects in the name of shortening
## TODO
1. Switch templates to
[Template::Mustache](https://github.com/softmoth/raku-Template-Mustache)
1. Make button to do a [meta element redirect]
(https://www.w3docs.com/snippets/html/how-to-redirect-a-web-page-in-html.html)
1. Why does Libarchive choke on strings like

View file

@ -1,7 +1,7 @@
use Humming-Bird::Core;
use Humming-Bird::Middleware;
use Humming-Bird::Advice;
use Template6;
use Template::Mustache;
use Base64;
use Libarchive::Filter :gzip;
@ -9,8 +9,7 @@ use Libarchive::Filter :gzip;
# what not but keeping it simple for now...
# Set things up (config stuff would go here?)
my $templates = Template6.new;
$templates.add-path: 'templates';
my $template = Template::Mustache.new: :from<../templates>;
# Logging
middleware &middleware-logger;
@ -20,7 +19,9 @@ advice &advice-logger;
my $router = Router.new(root => '/');
$router.get(-> $request, $response {
$response.html($templates.process: 'index');
my Str %stash = title => 'Create new hyperlink';
$response.html($template.render: 'index', %stash);
});
$router.post(-> $request, $response {
@ -29,8 +30,11 @@ $router.post(-> $request, $response {
my Str $url-host = $request.headers.{'Host'};
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
my Str %stash =
title => 'New hyperlink created',
hyperlink => $hyperlink;
$response.html($templates.process: 'index', :$hyperlink);
$response.html($template.render: 'index', %stash);
});
# Try a wildcard to catch 'all' path

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>[% title %]</title>
<title>{{title}}</title>
</head>
<body>
<h1>[% title %]</h1>
<h1>{{title}}</h1>

View file

@ -1,12 +1,11 @@
[% INCLUDE 'header'
title = 'Create new hyperlink' %]
[% IF hyperlink %]
<p>Your hyperlink is: <a href="[% hyperlink %]">[% hyperlink %]</a></p>
[% END %]
{{> header}}
{{#hyperlink}}
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
{{/hyperlink}}
<form method="post">
<label for="hyperlink">Hyperlink</label>
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
maxlength="2097152" required>
<button type="submit">Process</button>
</form>
[% INCLUDE 'footer' %]
{{> footer}}