Rand Stats

HTML::Functional

zef:librasteve

HTML::Functional

DESCRIPTION

Provides a Functional interface style for HTML tags and attributes.

Best practice is to HTML::Escape all tag inner text, two equivalent options are provided for this:

IMPORTANT: HTML::Escape is not applied by default to inner tags, so that Raku quoting constructs such as {strong 'DMI'} (as shown in the synopsis) can be fully utilized. Therefore care must be taken to always apply HTML::Escape particularly where this is stored in a variable and/or comes from tainted user input.

Contributions welcome - by PR please.

TODOS

SYNOPSIS

#!/usr/bin/env raku
use v6.d;

use HTML::Functional;

my $head = head [
    meta :charset<utf-8>;
    meta :name<viewport>, :content<width=device-width, initial-scale=1>;
    meta :name<description>, :content<raku does htmx>;

    title "Raku HTML::Functional";

    script :src<https://unpkg.com/htmx.org@1.7.0">;
    link :rel<stylesheet>, :href<https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>;

    style
            q:to/END/;
        .jumbotron {
            background-color: #e6ffe6;
            text-align: center;
        }
        END
];

my $body = body [
    div :class<jumbotron>, [
        h1 "Welcome to Dunder Mifflin!";                                    #use ; to stop <h1> slurping <p>
        p  "Dunder Mifflin Inc. (stock symbol {strong 'DMI'}) " ~
                q:to/END/;
            is a micro-cap regional paper and office
            supply distributor with an emphasis on servicing
            small-business clients.
            END
    ];

    p :hx-get<https://v2.jokeapi.dev/joke/Any?format=txt&safe-mode>,
            "Click Me";

    p ^'<div class="content">Escaped & Raw HTML!</div>';
];

my $html = html :lang<en>, [
    $head,
    $body,
];

say "<!doctype html>$html";

Inspired by https://elmprogramming.com/building-a-simple-page-in-elm.html

AUTHOR

librasteve librasteve@furnival.net

COPYRIGHT AND LICENSE

Copyright (c) 2024 Henley Cloud Consulting Ltd.

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.