Commit b7b33273 authored by Jonas Smedegaard's avatar Jonas Smedegaard

Update upstream source from tag 'upstream/2.01'

Update to upstream version '2.01'
with Debian dir 7ed43047c37a3a5f792ef0d0baa24329742c54a6
parents 0a5ab90a cb7b6c88
Revision history for perl module Text::Hogan
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
......
......@@ -56,7 +56,7 @@
"web" : "http://github.com/kaoru/Text-Hogan"
}
},
"version" : "1.09",
"version" : "2.01",
"x_serialization_backend" : "Cpanel::JSON::XS version 3.0214"
}
......@@ -27,5 +27,5 @@ requires:
resources:
bugtracker: https://github.com/kaoru/Text-Hogan/issues
repository: git://github.com/kaoru/Text-Hogan
version: '1.09'
version: '2.01'
x_serialization_backend: 'YAML::Tiny version 1.69'
......@@ -28,7 +28,7 @@ my %WriteMakefileArgs = (
"Try::Tiny" => "0.22",
"YAML" => "1.13"
},
"VERSION" => "1.09",
"VERSION" => "2.01",
"test" => {
"TESTS" => "t/*.t"
}
......
This archive contains the distribution Text-Hogan,
version 1.09:
version 2.01:
Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
......
......@@ -34,10 +34,46 @@ L<Text::Hogan::Template|Text::Hogan::Template> for more details.
The template format is documented in
L<mustache(5)|https://mustache.github.io/mustache.5.html>.
=head1 AUTHOR
=head1 SEE ALSO
=head2 hogan.js
L<hogan.js|http://twitter.github.io/hogan.js/> 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<Text::Caml|Text::Caml> supports searching for partials by file name, by
default .caml but that can be configured.
=head2 Template::Mustache
L<Template::Mustache|Template::Mustache> 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<Mustache::Simple|Mustache::Simple> 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!
Alex Balhatchet (alex@balhatchet.net)
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Tom Hukins
Tony Finch
Yanick Champoux
=cut
name = Text-Hogan
version = 1.09
version = 2.01
abstract = Text::Hogan - A mustache templating engine statement-for-statement cloned from hogan.js
author = Alex Balhatchet
......
package Text::Hogan;
$Text::Hogan::VERSION = '1.09';
$Text::Hogan::VERSION = '2.01';
use strict;
use warnings;
......@@ -13,7 +13,7 @@ Text::Hogan - A mustache templating engine statement-for-statement cloned from h
=head1 VERSION
version 1.09
version 2.01
=head1 DESCRIPTION
......@@ -72,10 +72,19 @@ 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 AUTHOR
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Alex Balhatchet (alex@balhatchet.net)
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Tom Hukins
Tony Finch
Yanick Champoux
=cut
package Text::Hogan::Compiler;
$Text::Hogan::Compiler::VERSION = '1.09';
$Text::Hogan::Compiler::VERSION = '2.01';
use Text::Hogan::Template;
use 5.10.0;
......@@ -33,9 +33,10 @@ sub new {
}
sub scan {
my ($self, $text, $options) = @_;
my ($self, $text_orig, $options) = @_;
my $text = [ split //, $text_orig ];
my $len = length $text;
my $len = scalar(@$text);
my ($IN_TEXT, $IN_TAG_TYPE, $IN_TAG) = (0, 1, 2);
my $state = $IN_TEXT;
my $tag_type = undef;
......@@ -91,7 +92,8 @@ sub scan {
};
my $change_delimiters = sub {
my ($text, $index) = @_;
my ($text_orig, $index) = @_;
my $text = join('', @$text_orig);
my $close = '=' . $ctag;
my $close_index = index($text, $close, $index);
......@@ -301,7 +303,7 @@ sub stringify_substitutions {
push @items, sprintf('"%s" => sub { my ($self,$c,$p,$t,$i) = @_; %s }', esc($key), $obj->{$key});
}
return sprintf("{ %s }", join(", ", @items));
return sprintf("{ %s }", join(', ', @items));
}
sub stringify_partials {
......@@ -316,7 +318,7 @@ sub stringify_partials {
}
return sprintf('"partials" => { %s }, "subs" => %s',
join(",", @partials),
join(',', @partials),
stringify_substitutions($code_obj->{'subs'})
);
}
......@@ -401,7 +403,12 @@ sub esc {
sub char_at {
my ($text, $index) = @_;
return substr($text, $index, 1);
if (ref($text) eq 'ARRAY') {
return $text->[$index];
}
else {
return substr($text, $index, 1);
}
}
sub choose_method {
......@@ -516,7 +523,7 @@ 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));
return join('||', $text, !!$options->{'as_string'}, !!$options->{'numeric_string_as_string'}, !!$options->{'disable_lambda'}, ($options->{'delimiters'} || ""), ($options->{'allow_whitespace_before_hashmark'} || 0));
}
sub compile {
......@@ -555,7 +562,7 @@ Text::Hogan::Compiler - parse templates and output Perl code
=head1 VERSION
version 1.09
version 2.01
=head1 SYNOPSIS
......@@ -598,7 +605,7 @@ delimiter-switching functionality.
'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 });
my $tokens = Text::Hogan::Compiler->new->scan("Hello{{ # foo }}, again{{ / foo }}.", { allow_whitespace_before_hashmark => 1 });
=head2 parse
......@@ -667,20 +674,30 @@ 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.
However be aware that compilation is much slower when using character strings!
The tokenization does a lot of character-by-character operations using
substr(), length(), etc. which are much slower when operating on character
strings than byte strings.
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.
I would still recommend you use character strings for your own sanity of
course! Just be aware that you will gain a lot of performance by pre-compiling
your templates, either using the as_string option of compile or just using a
compile-once render-lots pattern in your code.
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 AUTHOR
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Alex Balhatchet (alex@balhatchet.net)
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Tom Hukins
Tony Finch
Yanick Champoux
=cut
package Text::Hogan::Template;
$Text::Hogan::Template::VERSION = '1.09';
$Text::Hogan::Template::VERSION = '2.01';
use strict;
use warnings;
......@@ -45,7 +45,7 @@ sub v {
my ($self, $str) = @_;
$str //= "";
my $re = join '', '[', ( sort keys %mapping ), ']';
my $re = join('', '[', ( sort keys %mapping ), ']');
$str =~ s/($re)/$mapping{$1}/ge;
......@@ -365,7 +365,7 @@ Text::Hogan::Template - represent and render compiled templates
=head1 VERSION
version 1.09
version 2.01
=head1 SYNOPSIS
......@@ -387,10 +387,19 @@ Optionally takes a hashref of partials.
say $template->render({ name => "Dino" }, { hello => "Hello, {{name}}!" });
=head1 AUTHOR
=head1 AUTHORS
Started out statement-for-statement copied from hogan.js by Twitter!
Alex Balhatchet (alex@balhatchet.net)
Initial translation by Alex Balhatchet (alex@balhatchet.net)
Further improvements from:
Ed Freyfogle
Mohammad S Anwar
Ricky Morse
Tom Hukins
Tony Finch
Yanick Champoux
=cut
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment