Permalink
Browse files

Placeholders work, yay!

  • Loading branch information...
1 parent f0c1e3d commit 08513d92be1ee857bf66ce344b66985ef46510ad Timothy Totten committed Apr 12, 2013
Showing with 30 additions and 17 deletions.
  1. +6 −3 README.md
  2. +13 −12 lib/Web/App/Ballet.pm6
  3. +11 −2 test/simple.p6
View
@@ -69,8 +69,13 @@ has wrapper classes for. The currently supported libraries are:
get '/perl6' => 'http://perl6.org/'; ## A redirect statement.
+ get '/hello/:name' => sub ($c) {
+ my $name = $c.get(':name'); ## get the placeholder path.
+ $c.send(template('hello', :$name)); ## Explicit template output.
+ }
+
get '/about' => sub ($c) {
- template 'about.tt', { :ver<1.0.0> }; ## Implicit output.
+ template 'about', :ver<1.0.0>; ## Implicit template output.
}
dance; ## Start the process.
@@ -79,9 +84,7 @@ has wrapper classes for. The currently supported libraries are:
## TODO
- * Add examples using templates.
* Add testing ability once Web::App has testing support added.
- * Add pathname placeholder support: get '/users/:username'
## Author
View
@@ -28,25 +28,21 @@ sub set-template-engine (Str $name, Str $path = './views') is export
sub use-template6 (Str $path = './views') is export
{
-# require Web::Template::Template6;
set-template-engine('Template6', $path);
}
sub use-mojo (Str $path = './views') is export
{
-# require Web::Template::Mojo;
set-template-engine('Mojo', $path);
}
sub use-tal (Str $path = './views') is export
{
-# require Web::Template::TAL;
set-template-engine('TAL', $path);
}
sub use-html (Str $path = './views') is export
{
-# require Web::Template::HTML;
set-template-engine('HTML', $path);
}
@@ -86,16 +82,21 @@ sub app is export
return $app-object;
}
-sub add-route (*%rules) is export
-{
- app.add(|%rules);
-}
-
sub handle-route (Pair $route, $method?)
{
- ## TODO: if a path is detected, let's handle it properly.
-
- my %rules = { :path($route.key) };
+ my %rules;
+ my $path = $route.key;
+ if $path eq '*' {
+ %rules<default> = True;
+ }
+ elsif $path eq '/' {
+ %rules<path> = $path;
+ }
+ else
+ {
+ %rules<matchpath> = $path;
+ }
+
my $target = $route.value;
if $target ~~ Str
{
View
@@ -6,21 +6,30 @@ use Web::App::Ballet;
use-template6 './test/views';
+## The main page.
get '/' => sub ($c)
{
$c.content-type: 'text/plain';
my $name = $c.get(:default<World>, 'name');
$c.send("Hello $name");
}
-get '/test/' => sub ($c)
+## A path with a placeholder.
+get '/test/:name' => sub ($c)
{
- my $who = $c.get(:default<Bob>, 'who');
+ my $who = $c.get(':name');
### There is a bug, we should be able to do the following line:
#template 'help', :$who;
### But until implicit content is working again, we have to use this:
$c.send(template('help', :$who));
}
+## The default response if nothing else matches.
+get '*' => sub ($c)
+{
+ $c.content-type: 'text/plain';
+ $c.send("Web::App::Ballet test script.");
+}
+
dance;

0 comments on commit 08513d9

Please sign in to comment.