README

form auto generation

Example showing how to auto-generate form based on endpoint.

examples/users/App.rakumod

use HTML::Component;
use HTML::Component::Endpoint;
use HTML::Component::Boilerplate;
use User;

unit class App does HTML::Component;

method RENDER($_) {
  boilerplate
    :body{
      .a: :endpoint(User), { .add-child: "Create User" };
      .ol: {;
        for User.^all -> User:D $user {
          .li: {
            .add-child: $user
          }
        }
      }
    }
  ;
}

examples/users/User.rakumod

use HTML::Component;
use HTML::Component::Endpoint;
use Red;

unit model User does HTML::Component is endpoint;

has UInt $.id     is serial;
has Str  $.name   is unique;
has Str  $.email  is column;
has Bool $.active is column = True;

method LOAD(UInt() :$id) {
  self.^load: $id
}

multi method RENDER(::?CLASS:U: $_, $data = Nil) {
  .form: self.create-user, $data
}

multi method RENDER(::?CLASS:D: $_, %data) {
  self.WHAT.RENDER: $_, %data
}

multi method RENDER(::?CLASS:D: $_) {
  .ol: {
    .li: "name : { $!name }";
    .li: "email: { $!email }";
    .li: $!active ?? "ACTIVE" !! "INACTIVE"
  }
}

method create-user(
  Str()  :$name!  where *.chars > 0,     #= Username
  Str()  :$email! where *.contains("@"), #= New user's email
  Bool() :$active = True,
) is endpoint{
  :verb<POST>,
  :redirect</>,
  :on-error(-> $snippet, *%pars {
    self.RENDER: $snippet, %pars
  }),
} {
  ::?CLASS.^create: :$name, :$email, :$active
}

examples/users/users.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;
use User;
use Red;

red-defaults "SQLite";
# PROCESS::<$RED-DEBUG> = True;

schema(User).create;

User.^create(name => "John", email => "[email protected]");
User.^create(name => "Jane", email => "[email protected]");

my $app = Cro::HTTP::Server.new(
    host => '127.0.0.1',
    port => 10000,
    application => route {
        root-component App.new
    },
);

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

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

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.