Text-Hogan-2.03/ 0000775 0001750 0001750 00000000000 13576247216 012077 5 ustar alex alex Text-Hogan-2.03/lib/ 0000775 0001750 0001750 00000000000 13576247216 012645 5 ustar alex alex Text-Hogan-2.03/lib/Text/ 0000775 0001750 0001750 00000000000 13576247216 013571 5 ustar alex alex Text-Hogan-2.03/lib/Text/Hogan/ 0000775 0001750 0001750 00000000000 13576247216 014625 5 ustar alex alex Text-Hogan-2.03/lib/Text/Hogan/Compiler.pm 0000644 0001750 0001750 00000046435 13576247216 016747 0 ustar alex alex package Text::Hogan::Compiler;
$Text::Hogan::Compiler::VERSION = '2.03';
use Text::Hogan::Template;
use 5.10.0;
use strict;
use warnings;
use Ref::Util qw( is_arrayref );
use Text::Trim 'trim';
my $r_is_whitespace = qr/\S/;
my $r_quot = qr/"/;
my $r_newline = qr/\n/;
my $r_cr = qr/\r/;
my $r_slash = qr/\\/;
my $linesep = "\u{2028}";
my $paragraphsep = "\u{2029}";
my $r_linesep = qr/\Q$linesep\E/;
my $r_paragraphsep = qr/\Q$paragraphsep\E/;
my %tags = (
'#' => 1, '^' => 2, '<' => 3, '$' => 4,
'/' => 5, '!' => 6, '>' => 7, '=' => 8, '_v' => 9,
'{' => 10, '&' => 11, '_t' => 12
);
my $Template = Text::Hogan::Template->new();
sub new {
my $class = shift;
return bless {}, $class;
}
sub scan {
my ($self, $text_orig, $options) = @_;
my $text = [ split //, $text_orig ];
my $len = scalar(@$text);
my ($IN_TEXT, $IN_TAG_TYPE, $IN_TAG) = (0, 1, 2);
my $state = $IN_TEXT;
my $tag_type = undef;
my $tag = undef;
my $buf = "";
my @tokens;
my $seen_tag = 0;
my $i = 0;
my $line_start = 0;
my ($otag, $ctag) = ('{{', '}}');
my $add_buf = sub {
if (length $buf > 0) {
push @tokens, { 'tag' => '_t', 'text' => $buf };
$buf = "";
}
};
my $line_is_whitespace = sub {
my $is_all_whitespace = 1;
for (my $j = $line_start; $j < @tokens; $j++) {
$is_all_whitespace =
($tags{$tokens[$j]{'tag'}} < $tags{'_v'}) ||
($tokens[$j]{'tag'} eq '_t' && $tokens[$j]{'text'} !~ $r_is_whitespace);
if (!$is_all_whitespace) {
return 0;
}
}
return $is_all_whitespace;
};
my $filter_line = sub {
my ($have_seen_tag, $no_new_line) = @_;
$add_buf->();
if ($have_seen_tag && $line_is_whitespace->()) {
for (my $j = $line_start, my $next; $j < @tokens; $j++) {
if ($tokens[$j]{'text'}) {
if (($next = $tokens[$j+1]) && $next->{'tag'} eq '>') {
$next->{'indent'} = "".$tokens[$j]{'text'};
}
splice(@tokens,$j,1);
}
}
}
elsif (!$no_new_line) {
push @tokens, { 'tag' => "\n" };
}
$seen_tag = 0;
$line_start = scalar @tokens;
};
my $change_delimiters = sub {
my ($text_orig, $index) = @_;
my $text = join('', @$text_orig);
my $close = '=' . $ctag;
my $close_index = index($text, $close, $index);
my $offset = index($text, '=', $index) + 1;
my @delimiters = (
split ' ', trim(
# WARNING
#
# JavaScript substring and Perl substring functions differ!
#
# JavaScript's length parameter always goes from the beginning
# of the string, whereas Perl's goes from the offset parameter!
#
# node> "{{=<% %>=}}".substring(3, 8)
# '<% %>'
#
# perl> substr("{{=<% %>=}}", 3, 8);
# <% %>=}}
#
#
substr($text, $offset, $close_index - $offset)
)
);
$otag = $delimiters[0];
$ctag = $delimiters[-1];
return $close_index + length($close) - 1;
};
if ($options->{'delimiters'}) {
my @delimiters = split ' ', $options->{'delimiters'};
$otag = $delimiters[0];
$ctag = $delimiters[1];
}
for (my $i = 0; $i < $len; $i++) {
if ($state eq $IN_TEXT) {
if (tag_change($otag, $text, $i)) {
--$i;
$add_buf->();
$state = $IN_TAG_TYPE;
}
else {
if (char_at($text, $i) eq "\n") {
$filter_line->($seen_tag);
}
else {
$buf .= char_at($text, $i);
}
}
}
elsif ($state eq $IN_TAG_TYPE) {
$i += length($otag) - 1;
$i += 1 while($options->{'allow_whitespace_before_hashmark'} and (char_at($text, $i+1) eq ' '));
$tag = $tags{char_at($text,$i + 1)};
$tag_type = $tag ? char_at($text, $i + 1) : '_v';
if ($tag_type eq '=') {
$i = $change_delimiters->($text, $i);
$state = $IN_TEXT;
}
else {
if ($tag) {
$i++;
}
$state = $IN_TAG;
}
$seen_tag = $i;
}
else {
if (tag_change($ctag, $text, $i)) {
push @tokens, {
'tag' => $tag_type,
'n' => trim($buf),
'otag' => $otag,
'ctag' => $ctag,
'i' => (($tag_type eq '/') ? $seen_tag - length($otag) : $i + length($ctag)),
};
$buf = "";
$i += length($ctag) - 1;
$state = $IN_TEXT;
if ($tag_type eq '{') {
if ($ctag eq '}}') {
$i++;
}
else {
clean_triple_stache($tokens[-1]);
}
}
}
else {
$buf .= char_at($text, $i);
}
}
}
$filter_line->($seen_tag, 1);
return \@tokens;
}
sub clean_triple_stache {
my ($token) = @_;
if (substr($token->{'n'}, length($token->{'n'}) - 1) eq '}') {
$token->{'n'} = substr($token->{'n'}, 0, length($token->{'n'}) - 1);
}
return;
}
sub tag_change {
my ($tag, $text, $index) = @_;
if (char_at($text, $index) ne char_at($tag, 0)) {
return 0;
}
for (my $i = 1, my $l = length($tag); $i < $l; $i++) {
if (char_at($text, $index + $i) ne char_at($tag, $i)) {
return 0;
}
}
return 1;
}
my %allowed_in_super = (
'_t' => 1,
"\n" => 1,
'$' => 1,
'/' => 1,
);
sub build_tree {
my ($tokens, $kind, $stack, $custom_tags) = @_;
my (@instructions, $opener, $tail, $token);
$tail = $stack->[-1];
while (@$tokens > 0) {
$token = shift @$tokens;
if ($tail && ($tail->{'tag'} eq '<') && !$allowed_in_super{$token->{'tag'}}) {
die "Illegal content in < super tag.";
}
if ($tags{$token->{'tag'}} && ($tags{$token->{'tag'}} <= $tags{'$'} || is_opener($token, $custom_tags))) {
push @$stack, $token;
$token->{'nodes'} = build_tree($tokens, $token->{'tag'}, $stack, $custom_tags);
}
elsif ($token->{'tag'} eq '/') {
if (!@$stack) {
die "Closing tag without opener: /$token->{'n'}";
}
$opener = pop @$stack;
if ($token->{'n'} ne $opener->{'n'} && !is_closer($token->{'n'}, $opener->{'n'}, $custom_tags)) {
die "Nesting error: $opener->{'n'} vs $token->{'n'}";
}
$opener->{'end'} = $token->{'i'};
return \@instructions;
}
elsif ($token->{'tag'} eq "\n") {
$token->{'last'} = (@$tokens == 0) || ($tokens->[0]{'tag'} eq "\n");
}
push @instructions, $token;
}
if (@$stack) {
die "Missing closing tag: ", pop(@$stack)->{'n'};
}
return \@instructions;
}
sub is_opener {
my ($token, $tags) = @_;
for (my $i = 0, my $l = scalar(@$tags); $i < $l; $i++) {
if ($tags->[$i]{'o'} eq $token->{'n'}) {
$token->{'tag'} = '#';
return 1;
}
}
return 0;
}
sub is_closer {
my ($close, $open, $tags) = @_;
for (my $i = 0, my $l = scalar(@$tags); $i < $l; $i++) {
if (($tags->[$i]{'c'} eq $close) && ($tags->[$i]{'o'} eq $open)) {
return 1;
}
}
return 0;
}
sub stringify_substitutions {
my $obj = shift;
my @items;
for my $key (sort keys %$obj) {
push @items, sprintf('"%s" => sub { my ($self,$c,$p,$t,$i) = @_; %s }', esc($key), $obj->{$key});
}
return sprintf("{ %s }", join(', ', @items));
}
sub stringify_partials {
my $code_obj = shift;
my @partials;
for my $key (sort keys %{ $code_obj->{'partials'} }) {
push @partials, sprintf('"%s" => { "name" => "%s", %s }', $key,
esc($code_obj->{'partials'}{$key}{'name'}),
stringify_partials($code_obj->{'partials'}{$key})
);
}
return sprintf('"partials" => { %s }, "subs" => %s',
join(',', @partials),
stringify_substitutions($code_obj->{'subs'})
);
}
sub stringify {
my ($self,$code_obj, $text, $options) = @_;
return sprintf('{ code => sub { my ($t,$c,$p,$i) = @_; %s }, %s }',
wrap_main($code_obj->{'code'}),
stringify_partials($code_obj)
);
}
my $serial_no = 0;
sub generate {
my ($self, $tree, $text, $options) = @_;
$serial_no = 0;
my $context = { 'code' => "", 'subs' => {}, 'partials' => {} };
walk($tree, $context);
if ($options->{'as_string'}) {
return $self->stringify($context, $text, $options);
}
return $self->make_template($context, $text, $options);
}
sub wrap_main {
my ($code) = @_;
return sprintf('$t->b($i = $i || ""); %s return $t->fl();', $code);
}
sub make_template {
my $self = shift;
my ($code_obj, $text, $options) = @_;
my $template = make_partials($code_obj);
$template->{'code'} = eval sprintf("sub { my (\$t, \$c, \$p, \$i) = \@_; %s }", wrap_main($code_obj->{'code'}));
return $Template->new($template, $text, $self, $options);
}
sub make_partials {
my ($code_obj) = @_;
my $key;
my $template = {
'subs' => {},
'partials' => $code_obj->{'partials'},
'name' => $code_obj->{'name'},
};
for my $key (sort keys %{ $template->{'partials'} }) {
$template->{'partials'}{$key} = make_partials($template->{'partials'}{$key});
}
for my $key (sort keys %{ $code_obj->{'subs'} }) {
$template->{'subs'}{$key} = eval "sub { my (\$t, \$c, \$p, \$t, \$i) = \@_; $code_obj->{subs}{$key}; }";
}
return $template;
}
sub esc {
my $s = shift;
# standard from hogan.js
$s =~ s/$r_slash/\\\\/g;
$s =~ s/$r_quot/\\\"/g;
$s =~ s/$r_newline/\\n/g;
$s =~ s/$r_cr/\\r/g;
$s =~ s/$r_linesep/\\u2028/g;
$s =~ s/$r_paragraphsep/\\u2029/g;
# specific for Text::Hogan / Perl
$s =~ s/\$/\\\$/g;
$s =~ s/\@/\\@/g;
$s =~ s/\%/\\%/g;
return $s;
}
sub char_at {
my ($text, $index) = @_;
if (is_arrayref($text)) {
return $text->[$index];
}
return substr($text, $index, 1);
}
sub choose_method {
my ($s) = @_;
return $s =~ m/[.]/ ? "d" : "f";
}
sub create_partial {
my ($node, $context) = @_;
my $prefix = "<" . ($context->{'prefix'} || "");
my $sym = $prefix . $node->{'n'} . $serial_no++;
$context->{'partials'}{$sym} = {
'name' => $node->{'n'},
'partials' => {},
};
$context->{'code'} .= sprintf('$t->b($t->rp("%s",$c,$p,"%s"));',
esc($sym),
($node->{'indent'} || "")
);
return $sym;
}
my %codegen = (
'#' => sub {
my ($node, $context) = @_;
$context->{'code'} .= sprintf('if($t->s($t->%s("%s",$c,$p,1),$c,$p,0,%s,%s,"%s %s")) { $t->rs($c,$p,sub { my ($c,$p,$t) = @_;',
choose_method($node->{'n'}),
esc($node->{'n'}),
@{$node}{qw/ i end otag ctag /},
);
walk($node->{'nodes'}, $context);
$context->{'code'} .= '}); pop @$c;}';
},
'^' => sub {
my ($node, $context) = @_;
$context->{'code'} .= sprintf('if (!$t->s($t->%s("%s",$c,$p,1),$c,$p,1,0,0,"")){',
choose_method($node->{'n'}),
esc($node->{'n'})
);
walk($node->{'nodes'}, $context);
$context->{'code'} .= "};";
},
'>' => \&create_partial,
'<' => sub {
my ($node, $context) = @_;
my $ctx = { 'partials' => {}, 'code' => "", 'subs' => {}, 'in_partial' => 1 };
walk($node->{'nodes'}, $ctx);
my $template = $context->{'partials'}{create_partial($node, $context)};
$template->{'subs'} = $ctx->{'subs'};
$template->{'partials'} = $ctx->{'partials'};
},
'$' => sub {
my ($node, $context) = @_;
my $ctx = { 'subs' => {}, 'code' => "", 'partials' => $context->{'partials'}, 'prefix' => $node->{'n'} };
walk($node->{'nodes'}, $ctx);
$context->{'subs'}{$node->{'n'}} = $ctx->{'code'};
if (!$context->{'in_partial'}) {
$context->{'code'} += sprintf('$t->sub("%s",$c,$p,$i);',
esc($node->{'n'})
);
}
},
"\n" => sub {
my ($node, $context) = @_;
$context->{'code'} .= twrite(sprintf('"\n"%s', ($node->{'last'} ? "" : ' . $i')));
},
'_v' => sub {
my ($node, $context) = @_;
$context->{'code'} .= twrite(sprintf('$t->v($t->%s("%s",$c,$p,0))',
choose_method($node->{'n'}),
esc($node->{'n'})
));
},
'_t' => sub {
my ($node, $context) = @_;
$context->{'code'} .= twrite(sprintf('"%s"', esc($node->{'text'})));
},
'{' => \&triple_stache,
'&' => \&triple_stache,
);
sub triple_stache {
my ($node, $context) = @_;
$context->{'code'} .= sprintf('$t->b($t->t($t->%s("%s",$c,$p,0)));',
choose_method($node->{'n'}),
esc($node->{'n'})
);
}
sub twrite { sprintf '$t->b(%s);', @_ }
sub walk {
my ($nodelist, $context) = @_;
for my $node (@$nodelist) {
my $func = $codegen{$node->{'tag'}} or next;
$func->($node, $context);
}
return $context;
}
sub parse {
my ($self, $tokens, $text, $options) = @_;
$options ||= {};
return build_tree($tokens, "", [], $options->{'section_tags'} || []);
}
my %cache;
sub cache_key {
my ($text, $options) = @_;
return join('||', $text, !!$options->{'as_string'}, !!$options->{'numeric_string_as_string'}, !!$options->{'disable_lambda'}, ($options->{'delimiters'} || ""), ($options->{'allow_whitespace_before_hashmark'} || 0));
}
sub compile {
my ($self, $text, $options) = @_;
$options ||= {};
$text //= "";
my $key = cache_key($text, $options);
my $template = $cache{$key};
if ($template) {
my $partials = $template->{'partials'};
for my $name (sort keys %{ $template->{'partials'} }) {
delete $partials->{$name}{'instance'};
}
return $template;
}
$template = $self->generate(
$self->parse(
$self->scan($text, $options), $text, $options
), $text, $options
);
return $cache{$key} = $template;
}
1;
__END__
=head1 NAME
Text::Hogan::Compiler - parse templates and output Perl code
=head1 VERSION
version 2.03
=head1 SYNOPSIS
use Text::Hogan::Compiler;
my $compiler = Text::Hogan::Compiler->new;
my $text = "Hello, {{name}}!";
my $tokens = $compiler->scan($text);
my $tree = $compiler->parse($tokens, $text);
my $template = $compiler->generate($tree, $text);
say $template->render({ name => "Alex" });
=head1 METHODS
=head2 new
Takes nothing, returns a Compiler object.
my $compiler = Text::Hogan::Compiler->new;
=cut
=head2 scan
Takes template text and returns an arrayref which is a list of tokens.
my $tokens = $compiler->scan("Hello, {{name}}!");
Optionally takes a hashref with options. 'delimiters' is a string which
represents different delimiters, split by white-space. You should never
need to pass this directly, it it used to implement the in-template
delimiter-switching functionality.
# equivalent to the above call with mustaches
my $tokens = Text::Hogan::Compiler->new->scan("Hello, <% name %>!", { delimiters => "<% %>" });
'allow_whitespace_before_hashmark' is a boolean. If true,tags are allowed
to have space(s) between the delimiters and the opening sigil ('#', '/', '^', '<', etc.).
my $tokens = Text::Hogan::Compiler->new->scan("Hello{{ # foo }}, again{{ / foo }}.", { allow_whitespace_before_hashmark => 1 });
=head2 parse
Takes the tokens returned by scan, along with the original text, and returns a
tree structure ready to be turned into Perl code.
my $tree = $compiler->parse($tokens, $text);
Optionally takes a hashref that can have a key called "section_tags" which
should be an arrayref. I don't know what it does. Probably something internal
related to recursive calls that you don't need to worry about.
Note that a lot of error checking on your input gets done in this method, and
it is pretty much the only place exceptions might be thrown. Exceptions which
may be thrown include: "Closing tag without opener", "Missing closing tag",
"Nesting error" and "Illegal content in < super tag".
=head2 generate
Takes the parsed tree and the original text and returns a Text::Hogan::Template
object that you can call render on.
my $template = $compiler->generate($tree, $text);
Optionally takes a hashref that can have
- a key "as_string". If that is passed then instead of getting a template object
back you get some stringified Perl code that you can cache somewhere on
disk as part of your build process.
my $perl_code_as_string = $compiler->generate($tree, $text, { 'as_string' => 1 });
- a key "numeric_string_as_string". If that is passed output that looks like a number
is NOT converted into a number (ie "01234" is NOT converted to "1234")
my $perl_code_as_string = $compiler->generate($tree, $text, { 'numeric_string_as_string' => 1 });
The options hashref can have other keys which will be passed to
Text::Hogan::Template::new among other places.
=head2 compile
Takes a template string and calls scan, parse and generate on it and returns
you the Text::Hogan::Template object.
my $template = $compiler->compile("Hello, {{name}}!");
Also caches templates by a sensible cache key, which can be useful if you're
not stringifying and storing on disk or in memory anyway.
Optionally takes a hashref that will be passed on to scan, parse, and generate.
my $perl_code_as_string = $compiler->compile(
$text,
{
delimiters => "<% %>",
as_string => 1,
allow_whitespace_before_hashmark => 1,
},
);
=head1 ENCODING
As long as you are consistent with your use of encoding in your template
variables and your context variables, everything should just work. You can use
byte strings or character strings and you'll get what you expect.
The only danger would be if you use byte strings of a multi-byte encoding and
you happen to get a clash with your delimiters, eg. if your 4 byte kanji
character happens to contain the ASCII '<' and '%' characters next to each
other. I have no idea what the likelihood of that is, but hopefully if you're
working with non-ASCII character sets you're also using Perl's unicode
character strings features.
Compiling long character string inputs with Text::Hogan used to be extremely
slow but an optimisation added in version 2.00 has made the overhead much more
manageable.
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Jerrad Pierce
Tom Hukins
Tony Finch
Yanick Champoux
=cut
Text-Hogan-2.03/lib/Text/Hogan/Template.pm 0000644 0001750 0001750 00000022614 13576247216 016741 0 ustar alex alex package Text::Hogan::Template;
$Text::Hogan::Template::VERSION = '2.03';
use strict;
use warnings;
use Clone qw(clone);
use Ref::Util qw( is_ref is_arrayref is_coderef is_hashref);
use Scalar::Util qw(looks_like_number);
sub new {
my ($orig, $code_obj, $text, $compiler, $options) = @_;
$code_obj ||= {};
return bless {
r => $code_obj->{'code'} || (is_hashref($orig) && $orig->{'r'}),
c => $compiler,
buf => "",
options => $options || {},
text => $text || "",
partials => $code_obj->{'partials'} || {},
subs => $code_obj->{'subs'} || {},
numeric_string_as_string => !!$options->{'numeric_string_as_string'},
}, ref($orig) || $orig;
}
sub r {
my ($self, $context, $partials, $indent) = @_;
if ($self->{'r'}) {
return $self->{'r'}->($self, $context, $partials, $indent);
}
return "";
}
my %mapping = (
'&' => '&',
'<' => '<',
'>' => '>',
q{'} => ''',
'"' => '"',
);
# create regex once
my $mapping_re = join('', '[', ( sort keys %mapping ), ']');
sub v {
my ($self, $str) = @_;
$str //= "";
$str =~ s/($mapping_re)/$mapping{$1}/ge;
return $str;
}
sub t {
my ($self, $str) = @_;
return defined($str) ? $str : "";
}
sub render {
my ($self, $context, $partials, $indent) = @_;
return $self->ri([ $context ], $partials || {}, $indent);
}
sub ri {
my ($self, $context, $partials, $indent) = @_;
return $self->r($context, $partials, $indent);
}
sub ep {
my ($self, $symbol, $partials) = @_;
my $partial = $self->{'partials'}{$symbol};
# check to see that if we've instantiated this partial before
my $template = $partials->{$partial->{'name'}};
if ($partial->{'instance'} && $partial->{'base'} eq $template) {
return $partial->{'instance'};
}
if (! is_ref($template) ) {
die "No compiler available" unless $self->{'c'};
$template = $self->{'c'}->compile($template, $self->{'options'});
}
return undef unless $template;
$self->{'partials'}{$symbol}{'base'} = $template;
if ($partial->{'subs'}) {
# make sure we consider parent template now
$partials->{'stack_text'} ||= {};
for my $key (sort keys %{ $partial->{'subs'} }) {
if (!$partials->{'stack_text'}{$key}) {
$partials->{'stack_text'}{$key} =
$self->{'active_sub'} && $partials->{'stack_text'}{$self->{'active_sub'}}
? $partials->{'stack_text'}{$self->{'active_sub'}}
: $self->{'text'};
}
}
$template = create_specialized_partial($template, $partial->{'subs'}, $partial->{'partials'}, $self->{'stack_subs'}, $self->{'stack_partials'}, $self->{'stack_text'});
}
$self->{'partials'}{$symbol}{'instance'} = $template;
return $template;
}
# tries to find a partial in the current scope and render it
sub rp {
my ($self, $symbol, $context, $partials, $indent) = @_;
my $partial = $self->ep($symbol, $partials) or return "";
return $partial->ri($context, $partials, $indent);
}
# render a section
sub rs {
my ($self, $context, $partials, $section) = @_;
my $tail = $context->[-1];
if (! is_arrayref($tail) ) {
$section->($context, $partials, $self);
return;
}
for my $t (@$tail) {
push @$context, $t;
$section->($context, $partials, $self);
pop @$context;
}
}
# maybe start a section
sub s {
my ($self, $val, $ctx, $partials, $inverted, $start, $end, $tags) = @_;
my $pass;
return 0 if (is_arrayref($val)) && !@$val;
if (is_coderef($val)) {
$val = $self->ms($val, $ctx, $partials, $inverted, $start, $end, $tags);
}
$pass = !!$val;
if (!$inverted && $pass && $ctx) {
push @$ctx, (is_arrayref($val) || is_hashref($val)) ? $val : $ctx->[-1];
}
return $pass;
}
# find values with dotted names
sub d {
my ($self, $key, $ctx, $partials, $return_found) = @_;
my $found;
# JavaScript split is super weird!!
#
# GOOD:
# > "a.b.c".split(".")
# [ 'a', 'b', 'c' ]
#
# BAD:
# > ".".split(".")
# [ '', '' ]
#
my @names = $key eq '.' ? ( '' ) x 2 : split /\./, $key;
my $val = $self->f($names[0], $ctx, $partials, $return_found);
my $cx;
if ($key eq '.' && is_arrayref($ctx->[-2])) {
$val = $ctx->[-1];
}
else {
for my $name (@names[1..$#names] ) {
$found = find_in_scope($name, $val);
if (defined $found) {
$cx = $val;
$val = $found;
}
else {
$val = "";
}
}
}
return 0 if $return_found && !$val;
if (!$return_found && is_coderef($val)) {
push @$ctx, $cx;
$val = $self->mv($val, $ctx, $partials);
pop @$ctx;
}
return $self->_check_for_num($val);
}
# handle numerical interpolation for decimal numbers "properly"...
#
# according to the mustache spec 1.210 should render as 1.21
#
# unless the optional numeric_string_as_string was passed
sub _check_for_num {
my $self = shift;
my $val = shift;
return $val if ($self->{'numeric_string_as_string'} == 1);
$val += 0 if looks_like_number($val);
return $val;
}
# find values with normal names
sub f {
my ($self, $key, $ctx, $partials, $return_found) = @_;
my ( $val, $found ) = ( 0 );
for my $v ( reverse @$ctx ) {
$val = find_in_scope($key, $v);
next unless defined $val;
$found = 1;
last;
}
return $return_found ? 0 : "" unless $found;
if (!$return_found && is_coderef($val)) {
$val = $self->mv($val, $ctx, $partials);
}
return $self->_check_for_num($val);
}
# higher order templates
sub ls {
my ($self, $func, $cx, $ctx, $partials, $text, $tags) = @_;
my $old_tags = $self->{'options'}{'delimiters'};
$self->{'options'}{'delimiters'} = $tags;
$self->b($self->ct($func->($text), $cx, $partials));
$self->{'options'}{'delimiters'} = $old_tags;
return 0;
}
# compile text
sub ct {
my ($self, $text, $cx, $partials) = @_;
die "Lambda features disabled"
if $self->{'options'}{'disable_lambda'};
return $self->{'c'}->compile($text, $self->{'options'})->render($cx, $partials);
}
# template result buffering
sub b {
my ($self, $s) = @_;
$self->{'buf'} .= $s;
}
sub fl {
my ($self) = @_;
my $r = $self->{'buf'};
$self->{'buf'} = "";
return $r;
}
# method replace section
sub ms {
my ($self, $func, $ctx, $partials, $inverted, $start, $end, $tags) = @_;
return 1 if $inverted;
my $text_source = ($self->{'active_sub'} && $self->{'subs_text'} && $self->{'subs_text'}{$self->{'active_sub'}})
? $self->{'subs_text'}{$self->{'active_sub'}}
: $self->{'text'};
my $s = substr($text_source,$start,($end-$start));
$self->ls($func, $ctx->[-1], $ctx, $partials, $s, $tags);
return 0;
}
# method replace variable
sub mv {
my ($self, $func, $ctx, $partials) = @_;
my $cx = $ctx->[-1];
my $result = $func->($self,$cx);
return $self->ct($result, $cx, $partials);
}
sub sub {
my ($self, $name, $context, $partials, $indent) = @_;
my $f = $self->{'subs'}{$name} or return;
$self->{'active_sub'} = $name;
$f->($context,$partials,$self,$indent);
$self->{'active_sub'} = 0;
}
################################################
sub find_in_scope {
my ($key, $scope) = @_;
return eval { $scope->{$key} };
}
sub create_specialized_partial {
my ($instance, $subs, $partials, $stack_subs, $stack_partials, $stack_text) = @_;
my $Partial = clone($instance);
$Partial->{'buf'} = "";
$stack_subs ||= {};
$Partial->{'stack_subs'} = $stack_subs;
$Partial->{'subs_text'} = $stack_text;
for my $key (sort keys %$subs) {
if (!$stack_subs->{$key}) {
$stack_subs->{$key} = $subs->{$key};
}
}
for my $key (sort keys %$stack_subs) {
$Partial->{'subs'}{$key} = $stack_subs->{$key};
}
$stack_partials ||= {};
$Partial->{'stack_partials'} = $stack_partials;
for my $key (sort keys %$partials) {
if (!$stack_partials->{$key}) {
$stack_partials->{$key} = $partials->{$key};
}
}
for my $key (sort keys %$stack_partials) {
$Partial->{'partials'}{$key} = $stack_partials->{$key};
}
return $Partial;
}
sub coerce_to_string {
my ($str) = @_;
return defined($str) ? $str : "";
}
1;
__END__
=head1 NAME
Text::Hogan::Template - represent and render compiled templates
=head1 VERSION
version 2.03
=head1 SYNOPSIS
Use Text::Hogan::Compiler to create Template objects.
Then call render passing in a hashref for context.
use Text::Hogan::Compiler;
my $template = Text::Hogan::Compiler->new->compile("Hello, {{name}}!");
say $template->render({ name => $_ }) for (qw(Fred Wilma Barney Betty));
Optionally takes a hashref of partials.
use Text::Hogan::Compiler;
my $template = Text::Hogan::Compiler->new->compile("{{>hello}}");
say $template->render({ name => "Dino" }, { hello => "Hello, {{name}}!" });
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Jerrad Pierce
Tom Hukins
Tony Finch
Yanick Champoux
=cut
Text-Hogan-2.03/lib/Text/Hogan.pm 0000644 0001750 0001750 00000004471 13576247216 015167 0 ustar alex alex package Text::Hogan;
$Text::Hogan::VERSION = '2.03';
use strict;
use warnings;
1;
__END__
=head1 NAME
Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
=head1 VERSION
version 2.03
=head1 DESCRIPTION
Text::Hogan is a statement-for-statement rewrite of
L in Perl.
It is a L templating engine which
supports pre-compilation of your templates into pure Perl code, which then
renders very quickly.
It passes the full L.
=head1 SYNOPSIS
use Text::Hogan::Compiler;
my $text = "Hello, {{name}}!";
my $compiler = Text::Hogan::Compiler->new;
my $template = $compiler->compile($text);
say $template->render({ name => "Alex" });
See L and
L for more details.
=head1 TEMPLATE FORMAT
The template format is documented in
L.
=head1 SEE ALSO
=head2 hogan.js
L is the original library that
Text::Hogan is based on. It was written and is maintained by Twitter. It runs
on Node.js and pre-compiles templates to pure JavaScript.
=head2 Text::Caml
L supports searching for partials by file name, by
default .caml but that can be configured.
=head2 Template::Mustache
L is used by Dancer::Template::Mustache
and Dancer2::Template::Mustache. It supports compile once, render many times,
but does not allow dumping the compiled form to disk.
=head2 Mustache::Simple
L largely supports the Mustache spec, but
skips the whitespace and decimal tests (its behaviour with decimals is the same
as Text::Hogan with 'numeric_string_as_string' option enabled.) It supports
passing objects with getters to the context hash, so that {{name}} can be
rendered from $object->name if $object->can('name') returns true.
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Jerrad Pierce
Tom Hukins
Tony Finch
Yanick Champoux
=cut
Text-Hogan-2.03/t/ 0000775 0001750 0001750 00000000000 13576247216 012342 5 ustar alex alex Text-Hogan-2.03/t/synopsis_text_hogan_template.t 0000644 0001750 0001750 00000001654 13576247216 020535 0 ustar alex alex #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Text::Hogan::Compiler;
{
my $template = Text::Hogan::Compiler->new->compile("Hello, {{name}}!");
for (qw(Fred Wilma Barney Betty)) {
is
$template->render({ name => $_ }),
"Hello, $_!",
"Text::Hogan::Template synopsis works - $_";
}
}
{ my $template = Text::Hogan::Compiler->new->compile("{{>hello}}");
is
$template->render({ name => "Dino" }, { hello => "Hello, {{name}}!" }),
"Hello, Dino!",
"Text::Hogan::Template synopsis works - Dino (partial)";
}
{
my $template = Text::Hogan::Compiler->new->compile("Hello, {{name}}!", {'numeric_string_as_string' => 1});
for (qw(01234)) {
is
$template->render({ name => $_ }),
"Hello, $_!",
"Text::Hogan::Template synopsis works - $_ (numeric_string_as_string)";
}
}
done_testing();
Text-Hogan-2.03/t/synopsis_text_hogan_compiler.t 0000644 0001750 0001750 00000001734 13576247216 020533 0 ustar alex alex #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Text::Hogan::Compiler;
my $compiler = Text::Hogan::Compiler->new;
my $text = "Hello, {{name}}!";
my $tokens = $compiler->scan($text);
my $tree = $compiler->parse($tokens, $text);
my $template = $compiler->generate($tree, $text);
is $template->render({ name => "Alex" }), "Hello, Alex!", "Text::Hogan::Compiler synopsis works";
# whitespace testing
my $ws_template = '{{ # foo }}do not render if whitespace allowed{{ / foo }}';
my $ws_data = { foo => 0 };
my $ws_compiler = Text::Hogan::Compiler->new();
is $ws_compiler->compile( $ws_template, { 'allow_whitespace_before_hashmark' => 0 } )->render($ws_data),
"do not render if whitespace allowed",
"Text::Hogan::Compiler doesn't allow whitespace between delimeters and tag type ...";
is $ws_compiler->compile( $ws_template, { 'allow_whitespace_before_hashmark' => 1 } )->render($ws_data),
"",
"... unless specified in the options";
done_testing();
Text-Hogan-2.03/t/release-cpan-changes.t 0000644 0001750 0001750 00000000472 13576247216 016475 0 ustar alex alex #!perl
BEGIN {
unless ($ENV{RELEASE_TESTING}) {
print qq{1..0 # SKIP these tests are for release candidate testing\n};
exit
}
}
use strict;
use warnings;
use Test::More 0.96 tests => 2;
use_ok('Test::CPAN::Changes');
subtest 'changes_ok' => sub {
changes_file_ok('Changes');
};
done_testing();
Text-Hogan-2.03/t/synopsis_text_hogan.t 0000644 0001750 0001750 00000000474 13576247216 016641 0 ustar alex alex #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Text::Hogan::Compiler;
my $text = "Hello, {{name}}!";
my $compiler = Text::Hogan::Compiler->new;
my $template = $compiler->compile($text);
is $template->render({ name => "Alex" }), "Hello, Alex!", "Text::Hogan synopsis works";
done_testing();
Text-Hogan-2.03/t/author-pod-syntax.t 0000644 0001750 0001750 00000000454 13576247216 016136 0 ustar alex alex #!perl
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
print qq{1..0 # SKIP these tests are for testing by the author\n};
exit
}
}
# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests.
use strict; use warnings;
use Test::More;
use Test::Pod 1.41;
all_pod_files_ok();
Text-Hogan-2.03/t/specs/ 0000775 0001750 0001750 00000000000 13576247216 013457 5 ustar alex alex Text-Hogan-2.03/t/specs/interpolation.yml 0000644 0001750 0001750 00000020164 13576247216 017072 0 ustar alex alex overview: |
Interpolation tags are used to integrate dynamic content into the template.
The tag's content MUST be a non-whitespace character sequence NOT containing
the current closing delimiter.
This tag's content names the data to replace the tag. A single period (`.`)
indicates that the item currently sitting atop the context stack should be
used; otherwise, name resolution is as follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object, the data is the value returned by the
method with the given name.
5) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
Data should be coerced into a string (and escaped, if appropriate) before
interpolation.
The Interpolation tags MUST NOT be treated as standalone.
tests:
- name: No Interpolation
desc: Mustache-free templates should render as-is.
data: { }
template: |
Hello from {Mustache}!
expected: |
Hello from {Mustache}!
- name: Basic Interpolation
desc: Unadorned tags should interpolate content into the template.
data: { subject: "world" }
template: |
Hello, {{subject}}!
expected: |
Hello, world!
- name: HTML Escaping
desc: Basic interpolation should be HTML escaped.
data: { forbidden: '& " < >' }
template: |
These characters should be HTML escaped: {{forbidden}}
expected: |
These characters should be HTML escaped: & " < >
- name: Triple Mustache
desc: Triple mustaches should interpolate without HTML escaping.
data: { forbidden: '& " < >' }
template: |
These characters should not be HTML escaped: {{{forbidden}}}
expected: |
These characters should not be HTML escaped: & " < >
- name: Ampersand
desc: Ampersand should interpolate without HTML escaping.
data: { forbidden: '& " < >' }
template: |
These characters should not be HTML escaped: {{&forbidden}}
expected: |
These characters should not be HTML escaped: & " < >
- name: Basic Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{mph}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Triple Mustache Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{{mph}}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Ampersand Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{&mph}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Basic Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{power}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
- name: Triple Mustache Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{{power}}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
- name: Ampersand Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{&power}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
# Context Misses
- name: Basic Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{cannot}}) be seen!"
expected: "I () be seen!"
- name: Triple Mustache Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{{cannot}}}) be seen!"
expected: "I () be seen!"
- name: Ampersand Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{&cannot}}) be seen!"
expected: "I () be seen!"
# Dotted Names
- name: Dotted Names - Basic Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Triple Mustache Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{{person.name}}}" == "{{#person}}{{{name}}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Ampersand Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{&person.name}}" == "{{#person}}{{&name}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Arbitrary Depth
desc: Dotted names should be functional to any level of nesting.
data:
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
template: '"{{a.b.c.d.e.name}}" == "Phil"'
expected: '"Phil" == "Phil"'
- name: Dotted Names - Broken Chains
desc: Any falsey value prior to the last part of the name should yield ''.
data:
a: { }
template: '"{{a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Broken Chain Resolution
desc: Each part of a dotted name should resolve only against its parent.
data:
a: { b: { } }
c: { name: 'Jim' }
template: '"{{a.b.c.name}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Initial Resolution
desc: The first part of a dotted name should resolve as any other name.
data:
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
b: { c: { d: { e: { name: 'Wrong' } } } }
template: '"{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil"'
expected: '"Phil" == "Phil"'
- name: Dotted Names - Context Precedence
desc: Dotted names should be resolved against former resolutions.
data:
a: { b: { } }
b: { c: 'ERROR' }
template: '{{#a}}{{b.c}}{{/a}}'
expected: ''
# Whitespace Sensitivity
- name: Interpolation - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{string}} |'
expected: '| --- |'
- name: Triple Mustache - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{{string}}} |'
expected: '| --- |'
- name: Ampersand - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{&string}} |'
expected: '| --- |'
- name: Interpolation - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{string}}\n"
expected: " ---\n"
- name: Triple Mustache - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{{string}}}\n"
expected: " ---\n"
- name: Ampersand - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{&string}}\n"
expected: " ---\n"
# Whitespace Insensitivity
- name: Interpolation With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{ string }}|'
expected: '|---|'
- name: Triple Mustache With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{{ string }}}|'
expected: '|---|'
- name: Ampersand With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{& string }}|'
expected: '|---|'
Text-Hogan-2.03/t/specs/delimiters.yml 0000644 0001750 0001750 00000007332 13576247216 016346 0 ustar alex alex overview: |
Set Delimiter tags are used to change the tag delimiters for all content
following the tag in the current compilation unit.
The tag's content MUST be any two non-whitespace sequences (separated by
whitespace) EXCEPT an equals sign ('=') followed by the current closing
delimiter.
Set Delimiter tags SHOULD be treated as standalone when appropriate.
tests:
- name: Pair Behavior
desc: The equals sign (used on both sides) should permit delimiter changes.
data: { text: 'Hey!' }
template: '{{=<% %>=}}(<%text%>)'
expected: '(Hey!)'
- name: Special Characters
desc: Characters with special meaning regexen should be valid delimiters.
data: { text: 'It worked!' }
template: '({{=[ ]=}}[text])'
expected: '(It worked!)'
- name: Sections
desc: Delimiters set outside sections should persist.
data: { section: true, data: 'I got interpolated.' }
template: |
[
{{#section}}
{{data}}
|data|
{{/section}}
{{= | | =}}
|#section|
{{data}}
|data|
|/section|
]
expected: |
[
I got interpolated.
|data|
{{data}}
I got interpolated.
]
- name: Inverted Sections
desc: Delimiters set outside inverted sections should persist.
data: { section: false, data: 'I got interpolated.' }
template: |
[
{{^section}}
{{data}}
|data|
{{/section}}
{{= | | =}}
|^section|
{{data}}
|data|
|/section|
]
expected: |
[
I got interpolated.
|data|
{{data}}
I got interpolated.
]
- name: Partial Inheritence
desc: Delimiters set in a parent template should not affect a partial.
data: { value: 'yes' }
partials:
include: '.{{value}}.'
template: |
[ {{>include}} ]
{{= | | =}}
[ |>include| ]
expected: |
[ .yes. ]
[ .yes. ]
- name: Post-Partial Behavior
desc: Delimiters set in a partial should not affect the parent template.
data: { value: 'yes' }
partials:
include: '.{{value}}. {{= | | =}} .|value|.'
template: |
[ {{>include}} ]
[ .{{value}}. .|value|. ]
expected: |
[ .yes. .yes. ]
[ .yes. .|value|. ]
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Surrounding whitespace should be left untouched.
data: { }
template: '| {{=@ @=}} |'
expected: '| |'
- name: Outlying Whitespace (Inline)
desc: Whitespace should be left untouched.
data: { }
template: " | {{=@ @=}}\n"
expected: " | \n"
- name: Standalone Tag
desc: Standalone lines should be removed from the template.
data: { }
template: |
Begin.
{{=@ @=}}
End.
expected: |
Begin.
End.
- name: Indented Standalone Tag
desc: Indented standalone lines should be removed from the template.
data: { }
template: |
Begin.
{{=@ @=}}
End.
expected: |
Begin.
End.
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{= @ @ =}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{=@ @=}}\n="
expected: "="
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: "=\n {{=@ @=}}"
expected: "=\n"
# Whitespace Insensitivity
- name: Pair with Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { }
template: '|{{= @ @ =}}|'
expected: '||'
Text-Hogan-2.03/t/specs/comments.yml 0000644 0001750 0001750 00000004677 13576247216 016043 0 ustar alex alex overview: |
Comment tags represent content that should never appear in the resulting
output.
The tag's content may contain any substring (including newlines) EXCEPT the
closing delimiter.
Comment tags SHOULD be treated as standalone when appropriate.
tests:
- name: Inline
desc: Comment blocks should be removed from the template.
data: { }
template: '12345{{! Comment Block! }}67890'
expected: '1234567890'
- name: Multiline
desc: Multiline comments should be permitted.
data: { }
template: |
12345{{!
This is a
multi-line comment...
}}67890
expected: |
1234567890
- name: Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{! Comment Block! }}
End.
expected: |
Begin.
End.
- name: Indented Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{! Indented Comment Block! }}
End.
expected: |
Begin.
End.
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{! Standalone Comment }}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{! I'm Still Standalone }}\n!"
expected: "!"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: "!\n {{! I'm Still Standalone }}"
expected: "!\n"
- name: Multiline Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{!
Something's going on here...
}}
End.
expected: |
Begin.
End.
- name: Indented Multiline Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{!
Something's going on here...
}}
End.
expected: |
Begin.
End.
- name: Indented Inline
desc: Inline comments should not strip whitespace
data: { }
template: " 12 {{! 34 }}\n"
expected: " 12 \n"
- name: Surrounding Whitespace
desc: Comment removal should preserve surrounding whitespace.
data: { }
template: '12345 {{! Comment Block! }} 67890'
expected: '12345 67890'
Text-Hogan-2.03/t/specs/partials.yml 0000644 0001750 0001750 00000006341 13576247216 016023 0 ustar alex alex overview: |
Partial tags are used to expand an external template into the current
template.
The tag's content MUST be a non-whitespace character sequence NOT containing
the current closing delimiter.
This tag's content names the partial to inject. Set Delimiter tags MUST NOT
affect the parsing of a partial. The partial MUST be rendered against the
context stack local to the tag. If the named partial cannot be found, the
empty string SHOULD be used instead, as in interpolations.
Partial tags SHOULD be treated as standalone when appropriate. If this tag
is used standalone, any whitespace preceding the tag should treated as
indentation, and prepended to each line of the partial before rendering.
tests:
- name: Basic Behavior
desc: The greater-than operator should expand to the named partial.
data: { }
template: '"{{>text}}"'
partials: { text: 'from partial' }
expected: '"from partial"'
- name: Failed Lookup
desc: The empty string should be used when the named partial is not found.
data: { }
template: '"{{>text}}"'
partials: { }
expected: '""'
- name: Context
desc: The greater-than operator should operate within the current context.
data: { text: 'content' }
template: '"{{>partial}}"'
partials: { partial: '*{{text}}*' }
expected: '"*content*"'
- name: Recursion
desc: The greater-than operator should properly recurse.
data: { content: "X", nodes: [ { content: "Y", nodes: [] } ] }
template: '{{>node}}'
partials: { node: '{{content}}<{{#nodes}}{{>node}}{{/nodes}}>' }
expected: 'X>'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: The greater-than operator should not alter surrounding whitespace.
data: { }
template: '| {{>partial}} |'
partials: { partial: "\t|\t" }
expected: "| \t|\t |"
- name: Inline Indentation
desc: Whitespace should be left untouched.
data: { data: '|' }
template: " {{data}} {{> partial}}\n"
partials: { partial: ">\n>" }
expected: " | >\n>\n"
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{>partial}}\r\n|"
partials: { partial: ">" }
expected: "|\r\n>|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{>partial}}\n>"
partials: { partial: ">\n>"}
expected: " >\n >>"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: ">\n {{>partial}}"
partials: { partial: ">\n>" }
expected: ">\n >\n >"
- name: Standalone Indentation
desc: Each line of the partial should be indented before rendering.
data: { content: "<\n->" }
template: |
\
{{>partial}}
/
partials:
partial: |
|
{{{content}}}
|
expected: |
\
|
<
->
|
/
# Whitespace Insensitivity
- name: Padding Whitespace
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: true }
template: "|{{> partial }}|"
partials: { partial: "[]" }
expected: '|[]|'
Text-Hogan-2.03/t/specs/~lambdas.yml 0000644 0001750 0001750 00000014636 13576247216 016013 0 ustar alex alex overview: |
Lambdas are a special-cased data type for use in interpolations and
sections.
When used as the data value for an Interpolation tag, the lambda MUST be
treatable as an arity 0 function, and invoked as such. The returned value
MUST be rendered against the default delimiters, then interpolated in place
of the lambda.
When used as the data value for a Section tag, the lambda MUST be treatable
as an arity 1 function, and invoked as such (passing a String containing the
unprocessed section contents). The returned value MUST be rendered against
the current delimiters, then interpolated in place of the section.
tests:
- name: Interpolation
desc: A lambda's return value should be interpolated.
data:
lambda: !code
ruby: 'proc { "world" }'
perl: 'sub { "world" }'
js: 'function() { return "world" }'
php: 'return "world";'
python: 'lambda: "world"'
clojure: '(fn [] "world")'
lisp: '(lambda () "world")'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"
- name: Interpolation - Expansion
desc: A lambda's return value should be parsed.
data:
planet: "world"
lambda: !code
ruby: 'proc { "{{planet}}" }'
perl: 'sub { "{{planet}}" }'
js: 'function() { return "{{planet}}" }'
php: 'return "{{planet}}";'
python: 'lambda: "{{planet}}"'
clojure: '(fn [] "{{planet}}")'
lisp: '(lambda () "{{planet}}")'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"
- name: Interpolation - Alternate Delimiters
desc: A lambda's return value should parse with the default delimiters.
data:
planet: "world"
lambda: !code
ruby: 'proc { "|planet| => {{planet}}" }'
perl: 'sub { "|planet| => {{planet}}" }'
js: 'function() { return "|planet| => {{planet}}" }'
php: 'return "|planet| => {{planet}}";'
python: 'lambda: "|planet| => {{planet}}"'
clojure: '(fn [] "|planet| => {{planet}}")'
lisp: '(lambda () "|planet| => {{planet}}")'
template: "{{= | | =}}\nHello, (|&lambda|)!"
expected: "Hello, (|planet| => world)!"
- name: Interpolation - Multiple Calls
desc: Interpolated lambdas should not be cached.
data:
lambda: !code
ruby: 'proc { $calls ||= 0; $calls += 1 }'
perl: 'sub { no strict; $calls += 1 }'
js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }'
php: 'global $calls; return ++$calls;'
python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls'
clojure: '(def g (atom 0)) (fn [] (swap! g inc))'
lisp: '(let ((g 0)) (lambda () (incf g)))'
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
expected: '1 == 2 == 3'
- name: Escaping
desc: Lambda results should be appropriately escaped.
data:
lambda: !code
ruby: 'proc { ">" }'
perl: 'sub { ">" }'
js: 'function() { return ">" }'
php: 'return ">";'
python: 'lambda: ">"'
clojure: '(fn [] ">")'
lisp: '(lambda () ">")'
template: "<{{lambda}}{{{lambda}}}"
expected: "<>>"
- name: Section
desc: Lambdas used for sections should receive the raw section string.
data:
x: 'Error!'
lambda: !code
ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }'
perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }'
js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }'
php: 'return ($text == "{{x}}") ? "yes" : "no";'
python: 'lambda text: text == "{{x}}" and "yes" or "no"'
clojure: '(fn [text] (if (= text "{{x}}") "yes" "no"))'
lisp: '(lambda (text) (if (string= text "{{x}}") "yes" "no"))'
template: "<{{#lambda}}{{x}}{{/lambda}}>"
expected: ""
- name: Section - Expansion
desc: Lambdas used for sections should have their results parsed.
data:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}}#{text}" }'
perl: 'sub { $_[0] . "{{planet}}" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}}" + txt }'
php: 'return $text . "{{planet}}" . $text;'
python: 'lambda text: "%s{{planet}}%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}}" text))'
lisp: '(lambda (text) (format nil "~a{{planet}}~a" text text))'
template: "<{{#lambda}}-{{/lambda}}>"
expected: "<-Earth->"
- name: Section - Alternate Delimiters
desc: Lambdas used for sections should parse with the current delimiters.
data:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }'
perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }'
php: 'return $text . "{{planet}} => |planet|" . $text;'
python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}} => |planet|" text))'
lisp: '(lambda (text) (format nil "~a{{planet}} => |planet|~a" text text))'
template: "{{= | | =}}<|#lambda|-|/lambda|>"
expected: "<-{{planet}} => Earth->"
- name: Section - Multiple Calls
desc: Lambdas used for sections should not be cached.
data:
lambda: !code
ruby: 'proc { |text| "__#{text}__" }'
perl: 'sub { "__" . $_[0] . "__" }'
js: 'function(txt) { return "__" + txt + "__" }'
php: 'return "__" . $text . "__";'
python: 'lambda text: "__%s__" % (text)'
clojure: '(fn [text] (str "__" text "__"))'
lisp: '(lambda (text) (format nil "__~a__" text))'
template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}'
expected: '__FILE__ != __LINE__'
- name: Inverted Section
desc: Lambdas used for inverted sections should be considered truthy.
data:
static: 'static'
lambda: !code
ruby: 'proc { |text| false }'
perl: 'sub { 0 }'
js: 'function(txt) { return false }'
php: 'return false;'
python: 'lambda text: 0'
clojure: '(fn [text] false)'
lisp: '(lambda (text) (declare (ignore text)) nil)'
template: "<{{^lambda}}{{static}}{{/lambda}}>"
expected: "<>"
Text-Hogan-2.03/t/specs/sections.yml 0000644 0001750 0001750 00000020330 13576247216 016025 0 ustar alex alex overview: |
Section tags and End Section tags are used in combination to wrap a section
of the template for iteration
These tags' content MUST be a non-whitespace character sequence NOT
containing the current closing delimiter; each Section tag MUST be followed
by an End Section tag with the same content within the same section.
This tag's content names the data to replace the tag. Name resolution is as
follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object and the method with the given name has an
arity of 1, the method SHOULD be called with a String containing the
unprocessed contents of the sections; the data is the value returned.
5) Otherwise, the data is the value returned by calling the method with
the given name.
6) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
If the data is not of a list type, it is coerced into a list as follows: if
the data is truthy (e.g. `!!data == true`), use a single-element list
containing the data, otherwise use an empty list.
For each element in the data list, the element MUST be pushed onto the
context stack, the section MUST be rendered, and the element MUST be popped
off the context stack.
Section and End Section tags SHOULD be treated as standalone when
appropriate.
tests:
- name: Truthy
desc: Truthy sections should have their contents rendered.
data: { boolean: true }
template: '"{{#boolean}}This should be rendered.{{/boolean}}"'
expected: '"This should be rendered."'
- name: Falsey
desc: Falsey sections should have their contents omitted.
data: { boolean: false }
template: '"{{#boolean}}This should not be rendered.{{/boolean}}"'
expected: '""'
- name: Context
desc: Objects and hashes should be pushed onto the context stack.
data: { context: { name: 'Joe' } }
template: '"{{#context}}Hi {{name}}.{{/context}}"'
expected: '"Hi Joe."'
- name: Deeply Nested Contexts
desc: All elements on the context stack should be accessible.
data:
a: { one: 1 }
b: { two: 2 }
c: { three: 3 }
d: { four: 4 }
e: { five: 5 }
template: |
{{#a}}
{{one}}
{{#b}}
{{one}}{{two}}{{one}}
{{#c}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{#d}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{#e}}
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
{{/e}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{/d}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{/c}}
{{one}}{{two}}{{one}}
{{/b}}
{{one}}
{{/a}}
expected: |
1
121
12321
1234321
123454321
1234321
12321
121
1
- name: List
desc: Lists should be iterated; list items should visit the context stack.
data: { list: [ { item: 1 }, { item: 2 }, { item: 3 } ] }
template: '"{{#list}}{{item}}{{/list}}"'
expected: '"123"'
- name: Empty List
desc: Empty lists should behave like falsey values.
data: { list: [ ] }
template: '"{{#list}}Yay lists!{{/list}}"'
expected: '""'
- name: Doubled
desc: Multiple sections per template should be permitted.
data: { bool: true, two: 'second' }
template: |
{{#bool}}
* first
{{/bool}}
* {{two}}
{{#bool}}
* third
{{/bool}}
expected: |
* first
* second
* third
- name: Nested (Truthy)
desc: Nested truthy sections should have their contents rendered.
data: { bool: true }
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A B C D E |"
- name: Nested (Falsey)
desc: Nested falsey sections should be omitted.
data: { bool: false }
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A E |"
- name: Context Misses
desc: Failed context lookups should be considered falsey.
data: { }
template: "[{{#missing}}Found key 'missing'!{{/missing}}]"
expected: "[]"
# Implicit Iterators
- name: Implicit Iterator - String
desc: Implicit iterators should directly interpolate strings.
data:
list: [ 'a', 'b', 'c', 'd', 'e' ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(a)(b)(c)(d)(e)"'
- name: Implicit Iterator - Integer
desc: Implicit iterators should cast integers to strings and interpolate.
data:
list: [ 1, 2, 3, 4, 5 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1)(2)(3)(4)(5)"'
- name: Implicit Iterator - Decimal
desc: Implicit iterators should cast decimals to strings and interpolate.
data:
list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"'
- name: Implicit Iterator - Array
desc: Implicit iterators should allow iterating over nested arrays.
data:
list: [ [1, 2, 3], ['a', 'b', 'c'] ]
template: '"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}"'
expected: '"(123)(abc)"'
# Dotted Names
- name: Dotted Names - Truthy
desc: Dotted names should be valid for Section tags.
data: { a: { b: { c: true } } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == "Here"'
expected: '"Here" == "Here"'
- name: Dotted Names - Falsey
desc: Dotted names should be valid for Section tags.
data: { a: { b: { c: false } } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Broken Chains
desc: Dotted names that cannot be resolved should be considered falsey.
data: { a: { } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
expected: '"" == ""'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Sections should not alter surrounding whitespace.
data: { boolean: true }
template: " | {{#boolean}}\t|\t{{/boolean}} | \n"
expected: " | \t|\t | \n"
- name: Internal Whitespace
desc: Sections should not alter internal whitespace.
data: { boolean: true }
template: " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
expected: " | \n | \n"
- name: Indented Inline Sections
desc: Single-line sections should not alter surrounding whitespace.
data: { boolean: true }
template: " {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n"
expected: " YES\n GOOD\n"
- name: Standalone Lines
desc: Standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{#boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Indented Standalone Lines
desc: Indented standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{#boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { boolean: true }
template: "|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { boolean: true }
template: " {{#boolean}}\n#{{/boolean}}\n/"
expected: "#\n/"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { boolean: true }
template: "#{{#boolean}}\n/\n {{/boolean}}"
expected: "#\n/\n"
# Whitespace Insensitivity
- name: Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: true }
template: '|{{# boolean }}={{/ boolean }}|'
expected: '|=|'
Text-Hogan-2.03/t/specs/inverted.yml 0000644 0001750 0001750 00000014614 13576247216 016026 0 ustar alex alex overview: |
Inverted Section tags and End Section tags are used in combination to wrap a
section of the template.
These tags' content MUST be a non-whitespace character sequence NOT
containing the current closing delimiter; each Inverted Section tag MUST be
followed by an End Section tag with the same content within the same
section.
This tag's content names the data to replace the tag. Name resolution is as
follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object and the method with the given name has an
arity of 1, the method SHOULD be called with a String containing the
unprocessed contents of the sections; the data is the value returned.
5) Otherwise, the data is the value returned by calling the method with
the given name.
6) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
If the data is not of a list type, it is coerced into a list as follows: if
the data is truthy (e.g. `!!data == true`), use a single-element list
containing the data, otherwise use an empty list.
This section MUST NOT be rendered unless the data list is empty.
Inverted Section and End Section tags SHOULD be treated as standalone when
appropriate.
tests:
- name: Falsey
desc: Falsey sections should have their contents rendered.
data: { boolean: false }
template: '"{{^boolean}}This should be rendered.{{/boolean}}"'
expected: '"This should be rendered."'
- name: Truthy
desc: Truthy sections should have their contents omitted.
data: { boolean: true }
template: '"{{^boolean}}This should not be rendered.{{/boolean}}"'
expected: '""'
- name: Context
desc: Objects and hashes should behave like truthy values.
data: { context: { name: 'Joe' } }
template: '"{{^context}}Hi {{name}}.{{/context}}"'
expected: '""'
- name: List
desc: Lists should behave like truthy values.
data: { list: [ { n: 1 }, { n: 2 }, { n: 3 } ] }
template: '"{{^list}}{{n}}{{/list}}"'
expected: '""'
- name: Empty List
desc: Empty lists should behave like falsey values.
data: { list: [ ] }
template: '"{{^list}}Yay lists!{{/list}}"'
expected: '"Yay lists!"'
- name: Doubled
desc: Multiple inverted sections per template should be permitted.
data: { bool: false, two: 'second' }
template: |
{{^bool}}
* first
{{/bool}}
* {{two}}
{{^bool}}
* third
{{/bool}}
expected: |
* first
* second
* third
- name: Nested (Falsey)
desc: Nested falsey sections should have their contents rendered.
data: { bool: false }
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A B C D E |"
- name: Nested (Truthy)
desc: Nested truthy sections should be omitted.
data: { bool: true }
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A E |"
- name: Context Misses
desc: Failed context lookups should be considered falsey.
data: { }
template: "[{{^missing}}Cannot find key 'missing'!{{/missing}}]"
expected: "[Cannot find key 'missing'!]"
# Dotted Names
- name: Dotted Names - Truthy
desc: Dotted names should be valid for Inverted Section tags.
data: { a: { b: { c: true } } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Falsey
desc: Dotted names should be valid for Inverted Section tags.
data: { a: { b: { c: false } } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
expected: '"Not Here" == "Not Here"'
- name: Dotted Names - Broken Chains
desc: Dotted names that cannot be resolved should be considered falsey.
data: { a: { } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
expected: '"Not Here" == "Not Here"'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Inverted sections should not alter surrounding whitespace.
data: { boolean: false }
template: " | {{^boolean}}\t|\t{{/boolean}} | \n"
expected: " | \t|\t | \n"
- name: Internal Whitespace
desc: Inverted should not alter internal whitespace.
data: { boolean: false }
template: " | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
expected: " | \n | \n"
- name: Indented Inline Sections
desc: Single-line sections should not alter surrounding whitespace.
data: { boolean: false }
template: " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n"
expected: " NO\n WAY\n"
- name: Standalone Lines
desc: Standalone lines should be removed from the template.
data: { boolean: false }
template: |
| This Is
{{^boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Indented Lines
desc: Standalone indented lines should be removed from the template.
data: { boolean: false }
template: |
| This Is
{{^boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { boolean: false }
template: "|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { boolean: false }
template: " {{^boolean}}\n^{{/boolean}}\n/"
expected: "^\n/"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { boolean: false }
template: "^{{^boolean}}\n/\n {{/boolean}}"
expected: "^\n/\n"
# Whitespace Insensitivity
- name: Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: false }
template: '|{{^ boolean }}={{/ boolean }}|'
expected: '|=|'
Text-Hogan-2.03/t/specs/README 0000644 0001750 0001750 00000000147 13576247216 014337 0 ustar alex alex https://github.com/mustache/spec
This should be a Git submodule or something but I'm not cool enough.
Text-Hogan-2.03/t/spec_test.t 0000644 0001750 0001750 00000002673 13576247216 014526 0 ustar alex alex #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use YAML;
use Path::Tiny;
use Try::Tiny;
use Data::Visitor::Callback;
use Text::Hogan::Compiler;
my $data_fixer = Data::Visitor::Callback->new(
hash => sub {
my ($self, $rh) = @_;
# Handle lambdas in the ~lambdas.yml spec file
for my $k (keys %$rh) {
if ($k eq 'perl') {
$_ = eval $rh->{'perl'};
return;
}
}
# Handle true/false values
for my $v (values %$rh) {
if ($v eq 'true') { $v = 1 }
elsif ($v eq 'false') { $v = 0 }
elsif (ref($v) eq 'HASH') { $self->visit($v) }
}
}
);
my @spec_files = path("t", "specs")->children(qr/[.]yml$/);
for my $file (sort @spec_files) {
my $yaml = $file->slurp_utf8;
my $specs = YAML::Load($yaml);
note "----- $file ", ("-" x (70-length($file)));
for my $test (@{ $specs->{tests} }) {
#
# Handle true/false values
# Handle lambdas in the ~lambdas.yml spec file
#
$data_fixer->visit($test->{data});
my $parser = Text::Hogan::Compiler->new();
my $rendered;
try {
$rendered = $parser->compile($test->{template})->render($test->{data}, $test->{partials});
};
is(
$rendered,
$test->{expected},
"$test->{name} - $test->{desc}"
);
}
}
done_testing();
Text-Hogan-2.03/Makefile.PL 0000644 0001750 0001750 00000002716 13576247216 014055 0 ustar alex alex # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008.
use strict;
use warnings;
use 5.010000;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js",
"AUTHOR" => "Alex Balhatchet",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Text-Hogan",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.010000",
"NAME" => "Text::Hogan",
"PREREQ_PM" => {
"Clone" => "0.37",
"Ref::Util" => "0.204",
"Scalar::Util" => "1.41",
"Text::Trim" => "1.02"
},
"TEST_REQUIRES" => {
"Data::Visitor::Callback" => "0.30",
"Path::Tiny" => "0.059",
"Test::More" => "1.001008",
"Try::Tiny" => "0.22",
"YAML" => "1.13"
},
"VERSION" => "2.03",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"Clone" => "0.37",
"Data::Visitor::Callback" => "0.30",
"Path::Tiny" => "0.059",
"Ref::Util" => "0.204",
"Scalar::Util" => "1.41",
"Test::More" => "1.001008",
"Text::Trim" => "1.02",
"Try::Tiny" => "0.22",
"YAML" => "1.13"
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
Text-Hogan-2.03/README.pod 0000644 0001750 0001750 00000004304 13576247216 013537 0 ustar alex alex =pod
=head1 NAME
Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
=head1 DESCRIPTION
Text::Hogan is a statement-for-statement rewrite of
L in Perl.
It is a L templating engine which
supports pre-compilation of your templates into pure Perl code, which then
renders very quickly.
It passes the full L.
=head1 SYNOPSIS
use Text::Hogan::Compiler;
my $text = "Hello, {{name}}!";
my $compiler = Text::Hogan::Compiler->new;
my $template = $compiler->compile($text);
say $template->render({ name => "Alex" });
See L and
L for more details.
=head1 TEMPLATE FORMAT
The template format is documented in
L.
=head1 SEE ALSO
=head2 hogan.js
L is the original library that
Text::Hogan is based on. It was written and is maintained by Twitter. It runs
on Node.js and pre-compiles templates to pure JavaScript.
=head2 Text::Caml
L supports searching for partials by file name, by
default .caml but that can be configured.
=head2 Template::Mustache
L is used by Dancer::Template::Mustache
and Dancer2::Template::Mustache. It supports compile once, render many times,
but does not allow dumping the compiled form to disk.
=head2 Mustache::Simple
L largely supports the Mustache spec, but
skips the whitespace and decimal tests (its behaviour with decimals is the same
as Text::Hogan with 'numeric_string_as_string' option enabled.) It supports
passing objects with getters to the context hash, so that {{name}} can be
rendered from $object->name if $object->can('name') returns true.
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Jerrad Pierce
Tom Hukins
Tony Finch
Yanick Champoux
=cut
Text-Hogan-2.03/META.json 0000644 0001750 0001750 00000003174 13576247216 013523 0 ustar alex alex {
"abstract" : "Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js",
"author" : [
"Alex Balhatchet"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "Text-Hogan",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0",
"perl" : "v5.10.0"
}
},
"develop" : {
"requires" : {
"Test::CPAN::Changes" : "0.19",
"Test::Pod" : "1.41"
}
},
"runtime" : {
"requires" : {
"Clone" : "0.37",
"Ref::Util" : "0.204",
"Scalar::Util" : "1.41",
"Text::Trim" : "1.02",
"perl" : "v5.10.0"
}
},
"test" : {
"requires" : {
"Data::Visitor::Callback" : "0.30",
"Path::Tiny" : "0.059",
"Test::More" : "1.001008",
"Try::Tiny" : "0.22",
"YAML" : "1.13",
"perl" : "v5.10.0"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/kaoru/Text-Hogan/issues"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/kaoru/Text-Hogan",
"web" : "http://github.com/kaoru/Text-Hogan"
}
},
"version" : "2.03",
"x_serialization_backend" : "Cpanel::JSON::XS version 3.0214"
}
Text-Hogan-2.03/MANIFEST 0000644 0001750 0001750 00000001054 13576247216 013226 0 ustar alex alex # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.008.
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
README.pod
dist.ini
lib/Text/Hogan.pm
lib/Text/Hogan/Compiler.pm
lib/Text/Hogan/Template.pm
t/author-pod-syntax.t
t/release-cpan-changes.t
t/spec_test.t
t/specs/README
t/specs/comments.yml
t/specs/delimiters.yml
t/specs/interpolation.yml
t/specs/inverted.yml
t/specs/partials.yml
t/specs/sections.yml
t/specs/~lambdas.yml
t/synopsis_text_hogan.t
t/synopsis_text_hogan_compiler.t
t/synopsis_text_hogan_template.t
Text-Hogan-2.03/META.yml 0000644 0001750 0001750 00000001531 13576247216 013346 0 ustar alex alex ---
abstract: 'Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js'
author:
- 'Alex Balhatchet'
build_requires:
Data::Visitor::Callback: '0.30'
Path::Tiny: '0.059'
Test::More: '1.001008'
Try::Tiny: '0.22'
YAML: '1.13'
perl: v5.10.0
configure_requires:
ExtUtils::MakeMaker: '0'
perl: v5.10.0
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Text-Hogan
requires:
Clone: '0.37'
Ref::Util: '0.204'
Scalar::Util: '1.41'
Text::Trim: '1.02'
perl: v5.10.0
resources:
bugtracker: https://github.com/kaoru/Text-Hogan/issues
repository: git://github.com/kaoru/Text-Hogan
version: '2.03'
x_serialization_backend: 'YAML::Tiny version 1.69'
Text-Hogan-2.03/dist.ini 0000644 0001750 0001750 00000002171 13576247216 013542 0 ustar alex alex name = Text-Hogan
version = 2.03
abstract = Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
author = Alex Balhatchet
license = Perl_5
copyright_holder = Alex Balhatchet
[Prereqs / RuntimeRequires]
Clone = 0.37
Ref::Util = 0.204
Scalar::Util = 1.41
Text::Trim = 1.02
[Prereqs / TestRequires]
Test::More = 1.001008
YAML = 1.13
Data::Visitor::Callback = 0.30
Try::Tiny = 0.22
Path::Tiny = 0.059
[MetaResources]
repository.web = http://github.com/kaoru/Text-Hogan
repository.url = git://github.com/kaoru/Text-Hogan
repository.type = git
bugtracker.web = https://github.com/kaoru/Text-Hogan/issues
[GatherDir]
[ManifestSkip]
[MetaYAML]
[MetaJSON]
[License]
[Readme]
[PkgVersion]
[PodVersion]
[PodSyntaxTests]
[ExtraTests]
[Test::CPAN::Changes]
[Git::Tag]
tag_format = v%v
tag_message = ; use lightweight tags
[FileFinder::Filter / MyTestsSkipYML]
finder = :TestFiles
skip = .yml$
skip = README
[MinimumPerl]
test_finder = MyTestsSkipYML
[ExecDir]
[ShareDir]
[MakeMaker]
[Manifest]
[ConfirmRelease]
[UploadToCPAN]
Text-Hogan-2.03/LICENSE 0000644 0001750 0001750 00000043666 13576247216 013121 0 ustar alex alex This software is copyright (c) 2019 by Alex Balhatchet.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2019 by Alex Balhatchet.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2019 by Alex Balhatchet.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
Text-Hogan-2.03/Changes 0000644 0001750 0001750 00000004773 13576247216 013403 0 ustar alex alex Revision history for perl module Text::Hogan
2.03 2019-12-17
* Use Ref::Util, which will use Ref::Util::XS where available, thanks to Ed Freyfogle and opencagedata.com
2.02 2019-03-10
* Add Jerrad Pierce to the list of contributors. He inspired Ricky Morse's optimisation after a conversation they had at a Boston.pm meetup.
2.01 2019-03-02
* The inevitable tiny point release after the 2.0 to fix a typo in the docs :)
2.00 2019-03-02
* Small change with a big effect: Ricky Morse added an optimiation to the compile stage which makes the handling of large input files of character strings much more efficient. Compilation around 10x faster for a 20KB file of Japanese text.
1.09 2019-02-23
* Loads of great Perlish refactors from Yanick Champoux <3
1.08 2019-02-23
* Use Dist::Zilla::Plugin::Git::Tag for automatic git tags (just for jonassmedegaard :-))
1.07 2018-12-21
* Variable $key and $Key typo (thanks Yanick Champoux!)
1.06 2018-09-30
* Update SEE ALSO section in POD (thanks Mohammad S Anwar :-))
1.05 2018-09-29
* Bug fixes for as_string (thanks Tony Finch for catching 3 different bugs!)
1.04 2016-11-02
* Prefer array over arrayref (thanks Tom Hukins!)
* Add copyright_holder to dist.ini (thanks Tom Hukins!)
1.03 2016-05-07
* SEE ALSO documentation update
1.02 2016-03-03
* Transfer ownership from company to individual
* Add allow_whitespace_before_hashmark feature
Thanks to Ricky Morse (remorse on Github)
1.01 2015-07-13
* Add numeric_string_as_string feature
1.00 2015-07-12
* Implemented lambda sections
... We now pass the whole mustache spec! Time for a 1.0 release :-)
* Removed "model_get" hold-over from hogan.js
* Add synopsis tests
* Small spec_test.t improvements
* Small POD improvements
0.09 2015-06-25
* Document the link to hogan.js much more clearly
0.08 2015-06-24
* Further POD improvements
0.07 2015-06-23
* Documentation! POD! Woo!
0.06 2015-06-22
* Small performance improvements
* Die on lambda section to make very clear they are not supported
* Use custom MinimumPerl test_finder to skip YAML spec files
0.05 2015-06-19
* use Github as a bug tracker rather than rt.cpan.org
0.04 2015-06-19
* add Minimum Perl version to dist.ini
* don't use defined-or to support Perl 5.6 and 5.8
0.03 2015-06-18
* remove un-used "use DDP;" from spec_test.t
0.02 2015-06-18
* drop boolean.pm as a requirement
0.01 2015-06-18
* initial release based on hogan.js 3.0.2
Text-Hogan-2.03/README 0000644 0001750 0001750 00000000650 13576247216 012756 0 ustar alex alex
This archive contains the distribution Text-Hogan,
version 2.03:
Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
This software is copyright (c) 2019 by Alex Balhatchet.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
This README file was generated by Dist::Zilla::Plugin::Readme v6.008.