App-Templer

 view release on metacpan or  search on metacpan

PLUGINS.md  view on Meta::CPAN

* `format`
    * Given some input text return the rendered content.
    * This method receives all the per-page and global variables.


### Filter Plugins

The template filter plugin is similar in use as the formatter one. The only
difference is at the level it operates. While a formatter plugin operates on
the content of the page, a filter one operates directly on the core template
engine allowing one to escape `HTML::Template` rigid syntax.

A standard input page-file might look like this:

    Title: My page title.
    template-filter: dollar
    ----
    This is a html page with a ${title}.

A standard template layout might look like this:

    <title>${title escape=html}</title>

When this page is rendered the Dollar plugin is created and is used to add a
filter to the `HTML::Template` object creation (through the `filter` property
of the `HTML::Template->new` method).

If the named filter is not present, or does not report itself as "enabled"
then the filter is just not used.  To be explicit any filter plugin must
implement only the following two methods:

* `available`

examples/breadcrumbs/layouts/default.layout  view on Meta::CPAN

<html>
 <head>
  <title><!-- tmpl_var name='title' escape='html' --></title>
 </head>
 <body>
  <div style="text-align: center; border: 1px solid black;">
   <h2><!-- tmpl_var name='title' escape='html' --></h2>
  </div>
<!-- tmpl_if name='breadcrumbs' -->
  <ul>
  <!-- tmpl_loop name='breadcrumbs' -->
  <li><a href="<!-- tmpl_var name='link' -->"><!-- tmpl_var name='title' --></a></li>
  <!-- /tmpl_loop name='breadcrumbs' -->
  </ul>
<!-- /tmpl_if -->
  <p>&nbsp;</p>
  <div style="border: 1px solid black; padding-left: 20px; padding-right: 20px;">

examples/complex/input/layout.skx  view on Meta::CPAN

----


<h2>A Layout</h2>
<blockquote>
<p>A layout is a simple HTML::Template file which contains place-holders for your
content to go into.  The most basic layout would look like this:</p>
<pre>
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;&lt;!-- tmpl_var name='title' escape='html' --&gt;&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;!-- tmpl_var name='content' --&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Templer will insert the contents of each page into the region named "<tt>content</tt>", and
in this example we've assumed that <a href="page.html">each page</a> will define the variable "<tt>title</tt>".  Together the content and the title complete the page.</p>
<p>You can be significantly more sophisticated than just replacing the content and the title of the output page though - by including optional components as we've done with this example.</p>
</blockquote>

examples/complex/layouts/default.layout  view on Meta::CPAN

<html>
 <head>
  <title><!-- tmpl_var name='title' escape='html' --></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <!-- tmpl_if name='stylesheet' -->
   <link rel="stylesheet" href="<!-- tmpl_var name='stylesheet' -->" type="text/css" />
  <!-- tmpl_else -->
   <link rel="stylesheet" href="style.css" type="text/css" />
  <!-- /tmpl_if -->
  <script src="jquery.min.js"></script>
  <script type="text/javascript">

 $(document).ready(function() {
   $("#src_toggle").click(function(event){
      $('#src').toggle();
      return false;
   });
  });
  </script>
 </head>
 <body>
  <div style="text-align: center;">
   <h1><!-- tmpl_var name='title' escape='html' --></h1>
  </div>
  <p>&nbsp;</p>
  <table width="100%">
   <tr>
    <td valign="top" width="300">
      <!-- tmpl_var name='sidebar' -->
    </td>
    <td valign="top">
      <!-- tmpl_var name='content' -->
    </td>
  </tr>
  </table>

 <hr />
 <p style="text-align: right;"> <a href="#" id="src_toggle">Show the source of this page</a>.</p>
  <div id="src" style="display:none;">
   <pre><!-- tmpl_var name='src' escape='html' --></pre>
  </div>
 </body>
</html>

examples/simple/layouts/default.layout  view on Meta::CPAN

<html>
 <head>
  <title><!-- tmpl_var name='title' escape='html' --></title>
 </head>
 <body>
  <div style="text-align: center; border: 1px solid black;">
   <h2><!-- tmpl_var name='title' escape='html' --></h2>
  </div>
  <p>&nbsp;</p>
  <div style="border: 1px solid black; padding-left: 20px; padding-right: 20px;">
   <!-- tmpl_var name='content' -->
  </div>
  <div style="text-align: right;">
   <p><!-- tmpl_var name='copyright' --> <!-- tmpl_var name='year' --></p>
  </div>
 </body>
</html>

lib/Templer/Plugin/Dollar.pm  view on Meta::CPAN

This class implements a layout template filter plugin for C<templer> which
allows template variables to be included using a dollar sign followed by an
open brace, the variable name and a closing brace.

This allows template such as this to be used

=for example begin

    <html>
      <head>
        <title>${title escape="html"}</title>
        <meta name='author' content='${author} ${email escape=url}'/>
      </head>
      <body>
      </body>
    </html>

=for example end

Everything between the variable name and the closing brace is used B<as is> in
the transformation. The third line of the example is for instance transformed
as

=for example begin

        <title><tmpl_var name="title" escape="html"></title>

=for example end

=cut

=head1 LICENSE

This module is free software; you can redistribute it and/or modify it
under the terms of either:

lib/Templer/Site/New.pm  view on Meta::CPAN

----
<p>This is my site, it was generated by <a href="https://github.com/skx/templer">templer</a>.</p>
EOF

file layouts/default.layout EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <!-- tmpl_if name='title' -->
   <title><!-- tmpl_var name='title' escape='html' --></title>
  <!-- tmpl_else -->
   <title>Untitled Page</title>
  <!-- /tmpl_if -->
 </head>
 <body>
  <!-- tmpl_var name='content' -->
  <p>This is site was generated by <a href="https://github.com/skx/templer">templer</a> on <!-- tmpl_var name='date' -->.</p>
 </body>
</html>
EOF

t/test-templer-plugin-filters.t  view on Meta::CPAN


#
#  Attempting to load a plugin with a missing name is an error.
#
dies_ok( sub {$factory->filter(undef)}, "Missing plugin-name causes die()" );
dies_ok( sub {$factory->filter("")},    "Missing plugin-name causes die()" );

#
#  Dollar filter testing
#
my $input = '${title escape=html} ${author} ${email escape="url"}';
my $h_out = $factory->filter("dollar")->filter($input);
my $h_exp =
  '<tmpl_var name="title" escape=html> <tmpl_var name="author"> <tmpl_var name="email" escape="url">';

ok( $factory->filter("dollar")->available(),
    "Dollar Filter is always available" );
is( $h_out, $h_exp, "Dollar filter make correct change" );

#
#  Strict filter testing
#
$input = '<tmpl_var name="title"/> <tmpl_else/> <tmpl_include NAME="foo"/>';
$h_out = $factory->filter("strict")->filter($input);

templer.cfg.sample  view on Meta::CPAN

# but generally we'd expect only one layout to exist.
#
# Here we specify both the path to the layout directory and the layout to use
# if none is specified:
#
#
# layout-path = ./layouts/
#
# layout      = default.layout
#
# Layout template can be filtered in order to escape HTML::Template rigid
# syntax which is annoying with some text-editor
#
# template-filter = dollar, strict
#
##




##



( run in 0.314 second using v1.01-cache-2.11-cpan-73692580452 )