#!/usr/bin/env perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Handlebars;
render_ok(
<<'TEMPLATE',
{{title}}
{{#with author}}
By {{firstName}} {{lastName}}
{{/with}}
TEMPLATE
{
title => 'My first post!',
author => {
firstName => 'Charles',
lastName => 'Jolley',
},
},
<<'RENDERED',
My first post!
By Charles Jolley
RENDERED
"with helper"
);
render_ok(
<<'TEMPLATE',
{{#each people}}
- {{this}}
{{/each}}
TEMPLATE
{
people => [
"Yehuda Katz",
"Alan Johnson",
"Charles Jolley",
],
},
<<'RENDERED',
- Yehuda Katz
- Alan Johnson
- Charles Jolley
RENDERED
"each helper"
);
render_ok(
<<'TEMPLATE',
{{#each people}}
- {{last}}, {{first}}
{{/each}}
TEMPLATE
{
people => [
{ first => "Yehuda", last => "Katz" },
{ first => "Alan", last => "Johnson" },
{ first => "Charles", last => "Jolley" },
],
},
<<'RENDERED',
- Katz, Yehuda
- Johnson, Alan
- Jolley, Charles
RENDERED
"each helper"
);
render_ok(
<<'TEMPLATE',
{{#if author}}
{{firstName}} {{lastName}}
{{/if}}
TEMPLATE
{},
<<'RENDERED',
RENDERED
"if helper (false)"
);
render_ok(
<<'TEMPLATE',
{{#if author}}
{{firstName}} {{lastName}}
{{/if}}
TEMPLATE
{
author => 1,
firstName => "Yehuda",
lastName => "Katz",
},
<<'RENDERED',
Yehuda Katz
RENDERED
"if helper (true)"
);
render_ok(
<<'TEMPLATE',
{{#if author}}
{{firstName}} {{lastName}}
{{else}}
Unknown Author
{{/if}}
TEMPLATE
{},
<<'RENDERED',
Unknown Author
RENDERED
"if/else helper (false)"
);
render_ok(
<<'TEMPLATE',
{{#if author}}
{{firstName}} {{lastName}}
{{else}}
Unknown Author
{{/if}}
TEMPLATE
{
author => 1,
firstName => "Yehuda",
lastName => "Katz",
},
<<'RENDERED',
Yehuda Katz
RENDERED
"if/else helper (true)"
);
render_ok(
<<'TEMPLATE',
{{#unless license}}
WARNING: This entry does not have a license!
{{/unless}}
TEMPLATE
{},
<<'RENDERED',
WARNING: This entry does not have a license!
RENDERED
"unless helper (false)"
);
render_ok(
<<'TEMPLATE',
{{#unless license}}
WARNING: This entry does not have a license!
{{/unless}}
TEMPLATE
{
license => 1,
},
<<'RENDERED',
RENDERED
"unless helper (true)"
);
render_ok(
<<'TEMPLATE',
{{#each people}}
- {{../description}} {{this}}
{{/each}}
TEMPLATE
{
description => "The Wonderful",
people => [
"Yehuda Katz",
"Alan Johnson",
"Charles Jolley",
],
},
<<'RENDERED',
- The Wonderful Yehuda Katz
- The Wonderful Alan Johnson
- The Wonderful Charles Jolley
RENDERED
"each helper with ../"
);
done_testing;