.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
.\"
.\" 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
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. 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 turned on, 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 "2016-05-17" "perl v5.22.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 \s-1XML \s0(or (x)HTML) code and converts the characters
<>&\e' to \s-1HTML\s0 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 \s-1XML \s0(or (x)HTML) code (for example, a string
that was escaped with the \fIescape_xml()\fR function,
and 'unescapes' all \s-1HTML\s0 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 \s-1URL\s0 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 \fIencode_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=\*(L"checked\*(R"' which can be appended to \s-1HTML\s0 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=\*(L"selected\*(R"' which can be used in an option in an \s-1HTML\s0 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=\*(L"disabled\*(R"' which can be used in an \s-1HTML\s0 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 \s-1HTML\s0 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 \s-1XML \s0(or (x)HTML) code, escapes that code with
\&\fIescape_xml()\fR and then appends an \s-1HTML\s0 line break
to every line with \fInl2br()\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.