vti / text-caml Goto Github PK
View Code? Open in Web Editor NEWA mustache-like template engine for Perl
License: Other
A mustache-like template engine for Perl
License: Other
The following code removes the trailing line break after the section:
my $view = Text::Caml->new;
print $view->render_file('template', { abc => "Test" }) . "\n";
Template:
{{#abc}}
This is a test.
{{/abc}}
ABC
The output is This is a test.ABC
.
I would have expected a new line before ABC
.
Am I wrong?
Thanks!
It does not seem to be possible to set the template path via the constructor. In line 36+37 the expression after unless
may be incorrect:
currently:
$self->set_templates_path('.')
unless $self->templates_path;
but should be:
$self->set_templates_path('.')
unless $self->{templates_path};
i.e. the curly braces are missing. The workaround is of course to use the method set_template_path on the constructed object.
I often like to use a space when writing partials and sections in Mustache templates in order to provide a resting spot for your eye:
{{# section}}
{{> partial}}
{{/ section}}
The Mustache spec shows that whitespace should indeed be ignored:
https://github.com/mustache/spec/blob/master/specs/partials.yml (starting line 104)
https://github.com/mustache/spec/blob/master/specs/sections.yml (starting line 252)
Let's consider the hash my %hash = ( foo => { a => 42, b => 43, c => 44 } );
It would be interesting to implement something that allows to iterate over hash keys
{{#hash.keys}}
{{.}}
{{/hash}}
In case of more complex data we can still imaging using the same kind of syntax:
{{#hash.keys}}
{{.}} {{name}} {{genre}}
{{/hash.keys}}
Or even a full nested hash support:
{{#animals.keys}}
{{.}}:
{{#mammal.keys}}
{{.}} -> {{name}}
{{/mammal.keys
{{/hash.keys}}
What do you think?
What do you think about adding configuration option to set default behavior as non-escaping? Some templates are used in HTML documents and current behavior is appropriate. But sometimes it's required to use templates for other types of documents.
'&' usage of course solves this issue but making non-escaping behavior default for such cases looks more handy.
my $view = Text::Caml->new(do_no_escape => 1);
'&' can be switcher in this case:
my $do_not_escape = $self->{do_not_escape};
if ($tag =~ s/\A \&//xms) {
$do_not_escape = !$do_not_escape;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.