Skip to content

Commit

Permalink
Merge branch 'templates'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Jan 5, 2012
2 parents f6de046 + d8574ae commit bd30419
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/app.pl
Expand Up @@ -3,11 +3,11 @@
# simple cases
get '/' => sub {
"hello world"
};
}

get '/about' => sub {
"about me"
};
}

get '/hello/:name' => sub ($name) {
"Hello $name!"
Expand All @@ -27,4 +27,9 @@
"junctions are cool"
}

# templates!
get / ^ '/template/' (.+) $ / => sub ($x) {
template 'tmpl.tt', { name => $x }
}

baile;
8 changes: 8 additions & 0 deletions examples/views/tmpl.tt
@@ -0,0 +1,8 @@
<html>
<head>
<title>A greeting for [%! name %]</title>
</head>
<body>
<h1>Hello [%! name %]!</h1>
</body>
</html>
7 changes: 7 additions & 0 deletions lib/Bailador.pm
@@ -1,6 +1,7 @@
module Bailador;
use Bailador::Request;
use Bailador::Response;
use Ratel;
use HTTP::Easy::PSGI;

my %routes;
Expand All @@ -9,6 +10,7 @@ my %routes;

my $current-request = Bailador::Request.new;
my $current-response = Bailador::Response.new;
my $template-engine = Ratel.new;

sub route_to_regex($route) {
$route.split('/').map({
Expand Down Expand Up @@ -52,6 +54,11 @@ sub status(Int $code) is export {
$current-response.code = $code;
}

sub template(Str $tmpl, %params) is export {
$template-engine.load("views/$tmpl");
return $template-engine.render(|%params);
}

sub dispatch($env) {
my $res = '';

Expand Down

0 comments on commit bd30419

Please sign in to comment.