Skip to content

Commit

Permalink
redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Corrêa de Oliveira committed Nov 7, 2023
1 parent 9f73780 commit 89a4236
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 37 deletions.
31 changes: 22 additions & 9 deletions README.md
Expand Up @@ -51,9 +51,7 @@ has Todo @.todos;

method RENDER($_) {
.ol: {
for @!todos -> Todo $todo {
.add-child: $todo
}
.add-children: @!todos;
}
.form:
:endpoint(self.new-todo),
Expand All @@ -66,40 +64,55 @@ method RENDER($_) {
method new-todo(Str :$description!)
is endpoint{
:path</bla>,
:return(-> | { boilerplate :title("My TODO list"), { .add-child: TodoList.new } })
:redirect</>,
} {
@!todos.push: Todo.new: :$description;
}
```

```raku
# humming-bird-todo.raku
# examples/App.rakumod
use TodoList;
use HTML::Component;
use HTML::Component::Boilerplate;
unit class App does HTML::Component;

method RENDER($?) {
boilerplate
:title("My TODO list"),
*.add-child: TodoList.new
}
```

```raku
# examples/humming-bird-todo.raku
use v6.d;

use Humming-Bird::Core;
use HTML::Component::Boilerplate;
use lib "examples";
use TodoList;
use Todo;
use App;
use HTML::Component::Endpoint;

my $index = boilerplate :title("My TODO list"), { .add-child: TodoList.new }
my $index = App.new.RENDER;
my $html = $index.HTML;

get('/', -> $request, $response {
$response.html($html);
$response.html(App.new.RENDER.HTML);
});

for HTML::Component::Endpoint.endpoints {
if .verb.uc eq "GET" {
get .path, -> $request, $response {
$response.html: .run-defined(Any, |$request.query<>)
$response.html: .run-defined(Any, |$request.query<>).Str;
$response.redirect: $_ with .redirect;
}
}
}

listen(12345);

```

# DESCRIPTION
Expand Down
10 changes: 10 additions & 0 deletions examples/App.rakumod
@@ -0,0 +1,10 @@
use TodoList;
use HTML::Component;
use HTML::Component::Boilerplate;
unit class App does HTML::Component;

method RENDER($?) {
boilerplate
:title("My TODO list"),
*.add-child: TodoList.new
}
6 changes: 2 additions & 4 deletions examples/TodoList.rakumod
Expand Up @@ -12,9 +12,7 @@ has Todo @.todos;

method RENDER($_) {
.ol: {
for @!todos -> Todo $todo {
.add-child: $todo
}
.add-children: @!todos;
}
.form:
:endpoint(self.new-todo),
Expand All @@ -27,7 +25,7 @@ method RENDER($_) {
method new-todo(Str :$description!)
is endpoint{
:path</bla>,
:return(-> | { boilerplate :title("My TODO list"), { .add-child: TodoList.new } })
:redirect</>,
} {
@!todos.push: Todo.new: :$description;
}
8 changes: 5 additions & 3 deletions examples/humming-bird-todo.raku
Expand Up @@ -5,19 +5,21 @@ use HTML::Component::Boilerplate;
use lib "examples";
use TodoList;
use Todo;
use App;
use HTML::Component::Endpoint;

my $index = boilerplate :title("My TODO list"), { .add-child: TodoList.new }
my $index = App.new.RENDER;
my $html = $index.HTML;

get('/', -> $request, $response {
$response.html($html);
$response.html(App.new.RENDER.HTML);
});

for HTML::Component::Endpoint.endpoints {
if .verb.uc eq "GET" {
get .path, -> $request, $response {
$response.html: .run-defined(Any, |$request.query<>)
$response.html: .run-defined(Any, |$request.query<>).Str;
$response.redirect: $_ with .redirect;
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions lib/HTML/Component.rakumod
Expand Up @@ -5,28 +5,8 @@ sub html(|c) is export {
::("HTML::Component::Tag::HTML").new: |c;
}

# sub body(&func, *%_ where { .keys.all ~~ BODY.&all-html-attrs.any }) is export {
# my $body = BODY.new: |%_;
# $body.&func;
# $body
# }

#class SNIPPET does OnOl does OnBody does OnHTML does OnHead does Node {}

# sub snippet(&func) is export {
# #do given func SNIPPET.new { .children.head }
# func SNIPPET.new # for now
# }

method HTML {
my $*HTML-COMPONENT-RENDERING = True;
$.RENDER: CALLERS::<self>;
Empty
}

# method render-root {
# html -> HTML::Component $root { self.RENDER: $root }
# }
# method render {
# snippet(-> HTML::Components $root { self.RENDER: $root }).RENDER
# }
2 changes: 1 addition & 1 deletion lib/HTML/Component/Endpoint.rakumod
Expand Up @@ -13,6 +13,7 @@ has $.load-meth = "LOAD";
has Bool $.undefined = &!method.signature.params.first.modifier ne ":D";
has Bool $.defined = &!method.signature.params.first.modifier ne ":U";
has &.return = -> :$component, :$method-output { $method-output };
has $.redirect;

submethod TWEAK(|) {
@endpoints.push: self
Expand Down Expand Up @@ -48,4 +49,3 @@ multi trait_mod:<is>(Method $method, :%endpoint (Str() :$path!, |)) is export {
nextsame
}
}

8 changes: 8 additions & 0 deletions lib/HTML/Component/Tag/Node.rakumod
Expand Up @@ -12,6 +12,14 @@ multi method new(&body, *%_) {
$obj
}

multi method add-children(+@components) {
$.add-child: $_ for @components
}

multi method add-child(@components) {
$.add-child: $_ for @components
}

multi method add-child(HTML::Component $comp) {
@!children.push: $comp;
$comp
Expand Down

0 comments on commit 89a4236

Please sign in to comment.