Template-Swig
view release on metacpan or search on metacpan
lib/Template/Swig.pm view on Meta::CPAN
=head2 compileFromFile($f)
Will compile a file from the filesystem. C<$f> may be either a scalar filename,
or a reference to a hash with at least one key, C<filename>.
=head2 compile($string)
Will compile data supplied in the scalar C<$string>.
=head2 render($template_name, $data)
Render a template, given a name and a reference to a hash of data to interpolate.
=head1 TEMPLATE EXAMPLES
Iterate through a list:
{% for image in images %}
<img src="{{ image.src }}" width="{{ image.width }}" height="{{ image.height }}">
{% else %}
<div class="message">No images to show</div>
{% endfor %}
Custom helpers / filters:
{{ created|date('r') }}
=head3 Inheritance:
In main.html:
{% block 'greeting' %}
Hi, there.
{% endblock %}
In custom.html:
{% extends 'main.html' %}
{% block 'greeting' %}
Welcome, {{ name }}
{% endblock %}
=head1 SEE ALSO
L<Dotiac::DTL>, L<Text::Caml>, L<Template::Toolkit>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2012, David Chester
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
=cut
__DATA__
var templates = {};
/*! Swig https://paularmstrong.github.com/swig | https://github.com/paularmstrong/swig/blob/master/LICENSE */
/*! Cross-Browser Split 1.0.1 (c) Steven Levithan <stevenlevithan.com>; MIT License An ECMA-compliant, uniform cross-browser split method */
/*! Underscore.js (c) 2011 Jeremy Ashkenas | https://github.com/documentcloud/underscore/blob/master/LICENSE */
/*! DateZ (c) 2011 Tomo Universalis | https://github.com/TomoUniversalis/DateZ/blob/master/LISENCE */(function () {
var str = '{{ a }}',
splitter;
if (str.split(/(\{\{.*?\}\})/).length === 0) {
/** Repurposed from Steven Levithan's
* Cross-Browser Split 1.0.1 (c) Steven Levithan <stevenlevithan.com>; MIT License An ECMA-compliant, uniform cross-browser split method
*/
splitter = function (str, separator, limit) {
if (Object.prototype.toString.call(separator) !== '[object RegExp]') {
return splitter._nativeSplit.call(str, separator, limit);
}
var output = [],
lastLastIndex = 0,
flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.sticky ? 'y' : ''),
separator2,
match,
lastIndex,
lastLength;
separator = RegExp(separator.source, flags + 'g');
str = str.toString();
if (!splitter._compliantExecNpcg) {
separator2 = RegExp('^' + separator.source + '$(?!\\s)', flags);
}
if (limit === undefined || limit < 0) {
limit = Infinity;
} else {
limit = Math.floor(+limit);
if (!limit) {
return [];
}
}
function fixExec() {
var i = 1;
for (i; i < arguments.length - 2; i += 1) {
if (arguments[i] === undefined) {
match[i] = undefined;
}
}
}
match = separator.exec(str);
while (match) {
lastIndex = match.index + match[0].length;
if (lastIndex > lastLastIndex) {
output.push(str.slice(lastLastIndex, match.index));
if (!splitter._compliantExecNpcg && match.length > 1) {
match[0].replace(separator2, fixExec);
}
if (match.length > 1 && match.index < str.length) {
Array.prototype.push.apply(output, match.slice(1));
}
lastLength = match[0].length;
lastLastIndex = lastIndex;
if (output.length >= limit) {
break;
}
( run in 1.067 second using v1.01-cache-2.11-cpan-71847e10f99 )