HTML::Component

is the beginning of components (WiP)

Still very early stage of development

NAME

HTML::Component - is the beginning of components (WiP)

SYNOPSIS

# examples/todo/Todo.rakumod
use HTML::Component;
use HTML::Component::Endpoint;

unit class Todo does HTML::Component;

my @todos;

has UInt   $.id = ++$;
has Str()  $.description is required;
has Bool() $.done = False;

submethod TWEAK(|) {
  @todos[$!id - 1] := self;
}

method LOAD(UInt() :$id) {
  @todos[$id - 1]
}

multi method new($description) { self.new: :$description, |%_ }

method RENDER($_) {
  .li:
    :htmx-endpoint(self.toggle),
    :hx-swap<outerHTML>,
    :class<todo>,
    {
      .input-checkbox:
        :checked($!done),
      ;
      if $!done {
        .del: $!description
      } else {
        .add-child: $!description
      }
    }
  ;
}

method toggle is endpoint{ :return-component } {
  $!done .= not
}
# examples/todo/TodoList.rakumod
use HTML::Component::Endpoint;
use HTML::Component;
use HTML::Component::Boilerplate;
use HTML::Component::Traits;
use Todo;

unit class TodoList does HTML::Component;

method new(|)  { $ //= self.bless }
method LOAD(|) { self.new }

has UInt $.id = ++$;
has Todo @.todos;

method RENDER($_) {
  .ol: {
    .add-children: @!todos;
  }
  .form: self.new-todo;
}

method new-todo(
  Str :$description! is no-label, #= What should be done?
) is endpoint{ :verb<POST>, :redirect</> } {
  @!todos.push: Todo.new: :$description;
}
# examples/todo/App.rakumod
use TodoList;
use HTML::Component;
use HTML::Component::Boilerplate;
unit class App does HTML::Component;

method RENDER($) {
  boilerplate
    :title("My TODO list"),
    :body{
      .script: :src<https://unpkg.com/[email protected]>;
      .add-child: TodoList.new;
    }
  ;
}
# examples/todo/cro-todo.raku
use Cro::HTTP::Log::File;
use Cro::HTTP::Server;
use Cro::HTTP::Router;
use HTML::Component::CroRouter;
use Cro::HTTP::Log::File;
use lib "examples";
use App;

my $route = route {
    root-component App.new
}

my $app = Cro::HTTP::Server.new(
    host => '127.0.0.1',
    port => 10000,
    application => $route,
    after => [
        Cro::HTTP::Log::File.new(logs => $*OUT, errors => $*ERR)
    ],
  );

  $app.start;
  say "Listening at http://127.0.0.1:10000";

  react whenever signal(SIGINT) {
      $app.stop;
      exit;
  }

DESCRIPTION

HTML::Component is coming...

AUTHOR

Fernando CorrĂȘa de Oliveira [email protected]

COPYRIGHT AND LICENSE

Copyright 2023 Fernando CorrĂȘa de Oliveira

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

HTML::Component v0.0.1

is the beginning of components (WiP)

Authors

  • Fernando CorrĂȘa

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • HTML::Component
  • HTML::Component::Boilerplate
  • HTML::Component::CroRouter
  • HTML::Component::Encode
  • HTML::Component::Endpoint
  • HTML::Component::EndpointList
  • HTML::Component::Enums
  • HTML::Component::HTMLAttr
  • HTML::Component::Helpers
  • HTML::Component::Tag
  • HTML::Component::Tag::A
  • HTML::Component::Tag::BASE
  • HTML::Component::Tag::BODY
  • HTML::Component::Tag::BR
  • HTML::Component::Tag::DEL
  • HTML::Component::Tag::FORM
  • HTML::Component::Tag::HEAD
  • HTML::Component::Tag::HTML
  • HTML::Component::Tag::INPUT
  • HTML::Component::Tag::LABEL
  • HTML::Component::Tag::LI
  • HTML::Component::Tag::LINK
  • HTML::Component::Tag::Leaf
  • HTML::Component::Tag::META
  • HTML::Component::Tag::Methods::BODY
  • HTML::Component::Tag::Methods::HEAD
  • HTML::Component::Tag::Methods::HTML
  • HTML::Component::Tag::Methods::OL
  • HTML::Component::Tag::Node
  • HTML::Component::Tag::OL
  • HTML::Component::Tag::Role::Head
  • HTML::Component::Tag::SCRIPT
  • HTML::Component::Tag::SNIPPET
  • HTML::Component::Tag::SPAN
  • HTML::Component::Tag::TITLE
  • HTML::Component::Tag::Text
  • HTML::Component::Traits

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.