Skip to content

Commit

Permalink
Merge pull request #6 from szabgab/documentation
Browse files Browse the repository at this point in the history
Documentation
  • Loading branch information
Tadeusz Sośnierz committed Feb 1, 2014
2 parents a03001d + a6f27e4 commit 43b7f46
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
10 changes: 10 additions & 0 deletions eg/complex.out
@@ -0,0 +1,10 @@
See t/02-complex.t how to generate complex.out from this template.

<h1>Perl 6 Links

<ul>
<li><a href="http://rakudo.org/">Rakudo</a></li>
<li><a href="http://perl6.org/">Perl 6</a></li>
</ul>


12 changes: 12 additions & 0 deletions eg/complex.tm
@@ -0,0 +1,12 @@
% my (%h) = @_;
See t/02-complex.t how to generate complex.out from this template.

<h1><%= %h<title> %>

<ul>
% for %h<pages>.values -> $p {
<li><a href="<%= $p<url> %>"><%= $p<title> %></a></li>
% }
</ul>


44 changes: 44 additions & 0 deletions lib/Template/Mojo.pm
Expand Up @@ -182,6 +182,50 @@ The value to that subroutione can be passed in the render call:
Fname: Foo
Lname: Bar
=head2 Complex examples
=head3 Template
% my (%h) = @_;
<h1><%= %h<title> %>
<ul>
% for %h<pages>.values -> $p {
<li><a href="<%= $p<url> %>"><%= $p<title> %></a></li>
% }
</ul>
=head3 Code
my %params = (
title => "Perl 6 Links",
pages => [
{
"title" => "Rakudo",
"url" => "http://rakudo.org/",
},
{
title => 'Perl 6',
url => 'http://perl6.org/',
}
],
);
my $fh = open 'eg/template.tm', :r;
my $tmpl = $fh.slurp;
my $t = Template::Mojo.new($tmpl);
$t.render(%params)
=head3 Output
<h1>Perl 6 Links
<ul>
<li><a href="http://rakudo.org/">Rakudo</a></li>
<li><a href="http://perl6.org/">Perl 6</a></li>
</ul>
=head1 Copyright
Tadeusz Sośnierz
Expand Down
41 changes: 41 additions & 0 deletions t/02-complex.t
@@ -0,0 +1,41 @@
use v6;
use Test;
use Template::Mojo;


my %params = (
title => "Perl 6 Links",
pages => [
{
"title" => "Rakudo",
"url" => "http://rakudo.org/",
},
{
title => 'Perl 6',
url => 'http://perl6.org/',
}
],
);

plan 1;

#diag %params.perl;

my $fh = open "eg/complex.tm", :r;
my $tmpl = $fh.slurp;
#diag $tmpl;
my $output = Template::Mojo.new($tmpl).render(%params);
#diag $output;

# After changing the template one can save it with this code,
# examine it, and if found correct, keep it as the new expected data
if 0 {
my $out = open "eg/complex.out", :w;
$out.print($output);
$out.close;
}

my $fh2 = open "eg/complex.out", :r;
my $expected = $fh2.slurp;
is $output, $expected, 'complex';

0 comments on commit 43b7f46

Please sign in to comment.