.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Tenjin::Util 3pm"
.TH Tenjin::Util 3pm 2024-03-08 "perl v5.38.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
Tenjin::Util \- Utility methods for Tenjin.
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& # in your templates:
\&
\& # encode a URL
\& [== encode_url(\*(Aqhttp://www.google.com/search?q=tenjin&ie=utf\-8&oe=utf\-8&aq=t\*(Aq) =]
\& # returns http%3A//www.google.com/search%3Fq%3Dtenjin%26ie%3Dutf\-8%26oe%3Dutf\-8%26aq%3Dt
\&
\& # escape a string of lines of HTML code
\& You & Me\en
Me & You
\*(Aq; ?>
\& [== text2html($string) =]
\& # returns <h1>You & Me</h1>
\en<h2>Me & You</h2>
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
This module provides a few utility functions which can be used in your
templates for your convenience. These include functions to (un)escape
and (en/de)code URLs.
.SH METHODS
.IX Header "METHODS"
.ie n .SS "expand_tabs( $str, [$tabwidth] )"
.el .SS "expand_tabs( \f(CW$str\fP, [$tabwidth] )"
.IX Subsection "expand_tabs( $str, [$tabwidth] )"
Receives a string that might contain tabs in it, and replaces those
tabs with spaces, each tab with the number of spaces defined by \f(CW$tabwidth\fR,
or, if \f(CW$tabwidth\fR was not passed, with 8 spaces.
.ie n .SS "escape_xml( $str )"
.el .SS "escape_xml( \f(CW$str\fP )"
.IX Subsection "escape_xml( $str )"
Receives a string of XML (or (x)HTML) code and converts the characters
<>&\e' to HTML entities. This is the method that is invoked when you use
[= \f(CW$expression\fR =] in your templates.
.ie n .SS "unescape_xml( $str )"
.el .SS "unescape_xml( \f(CW$str\fP )"
.IX Subsection "unescape_xml( $str )"
Receives a string of escaped XML (or (x)HTML) code (for example, a string
that was escaped with the \fBescape_xml()\fR function,
and 'unescapes' all HTML entities back to their actual characters.
.ie n .SS "encode_url( $url )"
.el .SS "encode_url( \f(CW$url\fP )"
.IX Subsection "encode_url( $url )"
Receives a URL and encodes it by escaping 'non\-standard' characters.
.ie n .SS "decode_url( $url )"
.el .SS "decode_url( \f(CW$url\fP )"
.IX Subsection "decode_url( $url )"
Does the opposite of \fBencode_url()\fR.
.ie n .SS "checked( $val )"
.el .SS "checked( \f(CW$val\fP )"
.IX Subsection "checked( $val )"
Receives a value of some sort, and if it is a true value, returns the string
\&' checked="checked"' which can be appended to HTML checkboxes.
.ie n .SS "selected( $val )"
.el .SS "selected( \f(CW$val\fP )"
.IX Subsection "selected( $val )"
Receives a value of some sort, and if it is a true value, returns the string
\&' selected="selected"' which can be used in an option in an HTML select box.
.ie n .SS "disabled( $val )"
.el .SS "disabled( \f(CW$val\fP )"
.IX Subsection "disabled( $val )"
Receives a value of some sort, and if it is a true value, returns the string
\&' disabled="disabled"' which can be used in an HTML input.
.ie n .SS "nl2br( $text )"
.el .SS "nl2br( \f(CW$text\fP )"
.IX Subsection "nl2br( $text )"
Receives a string of text containing lines delimited by newline characters
(\en, or possibly \er\en) and appends an HTML line break (
) to every
line (the newline character is left untouched).
.ie n .SS "text2html( $text )"
.el .SS "text2html( \f(CW$text\fP )"
.IX Subsection "text2html( $text )"
Receives a string of text containing lines delimited by newline characters,
and possibly some XML (or (x)HTML) code, escapes that code with
\&\fBescape_xml()\fR and then appends an HTML line break
to every line with \fBnl2br()\fR.
.ie n .SS "tagattr( $name, $expr, [$value] )"
.el .SS "tagattr( \f(CW$name\fP, \f(CW$expr\fP, [$value] )"
.IX Subsection "tagattr( $name, $expr, [$value] )"
.ie n .SS "tagattrs( %attrs )"
.el .SS "tagattrs( \f(CW%attrs\fP )"
.IX Subsection "tagattrs( %attrs )"
.ie n .SS "new_cycle( @items )"
.el .SS "new_cycle( \f(CW@items\fP )"
.IX Subsection "new_cycle( @items )"
Creates a subroutine reference that can be used for cycling through the
items of the \f(CW@items\fR array. So, for example, you can:
.PP
.Vb 5
\& my $cycle = new_cycle(qw/red green blue/);
\& print $cycle\->(); # prints \*(Aqred\*(Aq
\& print $cycle\->(); # prints \*(Aqgreen\*(Aq
\& print $cycle\->(); # prints \*(Aqblue\*(Aq
\& print $cycle\->(); # prints \*(Aqred\*(Aq again
.Ve
.SH "INTERNAL(?) METHODS"
.IX Header "INTERNAL(?) METHODS"
.ie n .SS "_p( $expression )"
.el .SS "_p( \f(CW$expression\fP )"
.IX Subsection "_p( $expression )"
Wraps a Perl expression in a customized wrapper which will be processed
by the Tenjin preprocessor and replaced with the standard [== \f(CW$expression\fR =].
.ie n .SS "_P( $expression )"
.el .SS "_P( \f(CW$expression\fP )"
.IX Subsection "_P( $expression )"
Wrap a Perl expression in a customized wrapper which will be processed
by the Tenjin preprocessor and replaced with the standard [= \f(CW$expression\fR =],
which means the expression will be escaped.
.ie n .SS "_decode_params( $s )"
.el .SS "_decode_params( \f(CW$s\fP )"
.IX Subsection "_decode_params( $s )"
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Tenjin, Tenjin::Template, Tenjin::Context.
.SH "AUTHOR, LICENSE AND COPYRIGHT"
.IX Header "AUTHOR, LICENSE AND COPYRIGHT"
See Tenjin.