From 0506335a52b9515d1ee95b857a56f01a39ab67ec Mon Sep 17 00:00:00 2001 From: swaggboi Date: Wed, 1 Nov 2023 00:52:19 -0400 Subject: [PATCH] Switched to Template::Mustache --- META6.json | 2 +- README.md | 2 -- lib/Hyperlink-Redirect.rakumod | 14 +++++++++----- templates/{footer.tt => footer.mustache} | 0 templates/{header.tt => header.mustache} | 4 ++-- templates/{index.tt => index.mustache} | 11 +++++------ 6 files changed, 17 insertions(+), 16 deletions(-) rename templates/{footer.tt => footer.mustache} (100%) rename templates/{header.tt => header.mustache} (52%) rename templates/{index.tt => index.mustache} (54%) diff --git a/META6.json b/META6.json index 3a7542d..eee8160 100644 --- a/META6.json +++ b/META6.json @@ -2,7 +2,7 @@ "name": "Hyperlink-Redirect", "depends": [ "Humming-Bird", - "Template6", + "Template::Mustache", "Base64", "Libarchive::Filter" ], diff --git a/README.md b/README.md index 3cbc673..60f9bc9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/Hyperlink-Redirect.rakumod b/lib/Hyperlink-Redirect.rakumod index 6bf09e5..6038103 100644 --- a/lib/Hyperlink-Redirect.rakumod +++ b/lib/Hyperlink-Redirect.rakumod @@ -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 diff --git a/templates/footer.tt b/templates/footer.mustache similarity index 100% rename from templates/footer.tt rename to templates/footer.mustache diff --git a/templates/header.tt b/templates/header.mustache similarity index 52% rename from templates/header.tt rename to templates/header.mustache index ee2f927..fef4347 100644 --- a/templates/header.tt +++ b/templates/header.mustache @@ -1,7 +1,7 @@ - [% title %] + {{title}} -

[% title %]

+

{{title}}

diff --git a/templates/index.tt b/templates/index.mustache similarity index 54% rename from templates/index.tt rename to templates/index.mustache index f0e5ad4..4aee31b 100644 --- a/templates/index.tt +++ b/templates/index.mustache @@ -1,12 +1,11 @@ -[% INCLUDE 'header' - title = 'Create new hyperlink' %] -[% IF hyperlink %] -

Your hyperlink is: [% hyperlink %]

-[% END %] +{{> header}} +{{#hyperlink}} +

Your hyperlink is: {{hyperlink}}

+{{/hyperlink}}
-[% INCLUDE 'footer' %] +{{> footer}}