Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Renderer::Backend
Source

Index


NAME ^

Newcomen::Renderer::Backend - Base class for renderer backends.

SYNOPSIS ^

package Newcomen::Renderer::MyBackend;

use namespace::autoclean;
use Moose;

extends 'Newcomen::Renderer::Backend';

override '_do_render' => sub {

   my $self    = shift;
   my $page    = shift;
   my $options = shift;

   # Render page...

   return $rendered;

};

__PACKAGE__ -> meta () -> make_immutable ();

1;

DESCRIPTION ^

This is the base class to be extended by renderer backends. It does not define any attributes. It does define the methods render() and _do_render(). render() will call the _do_render() method, which has to be overridden by the actual backend implementation (see SYNOPSIS). The _do_render() method of the base class will simply die()!

CLASS METHODS ^

new

my $backend = Newcomen::Renderer::MyBackend -> new ();

Constructor, expects no parameters. new() will be called once for every (!) backend found. A backend does not have to be actually used to be instantiated! If it is actually used, render() will be called. The one backend instance will be used to render all pages.

INSTANCE METHODS ^

render

Toggle source:   render

sub render {

   my $self = shift;
   my $page = shift;
   my $opts = shift // Newcomen::Data -> new ();

   confess 'Usage: render($page,$options)' unless
      is_a ($page, 'Newcomen::Page') and is_a ($opts, 'Newcomen::Data') and not @_;

   my $text = $self -> _do_render ($page, $opts);
   confess 'No string returned by renderer backend' unless defined $text and ref $text eq '';

   return $text;

}
$rendered = $backend -> render ($page, $backend_options);

The render() method of a backend will be called when a page should be rendered. It will return the rendered content. The page to be rendered (an Newcomen::Page instance) must be passed as first parameter. The backend options must be passed as second parameter. This must be an Newcomen::Data instance or undef. The render() method must not be overridden by a backend implementation!

MISCELLANEOUS ^

_do_render

Toggle source:   _do_render

sub _do_render { confess '_do_render() not implemented by backend' }

The actual backends must implement a _do_render() method, _do_render() of this base class will die(). The page to be rendered (an Newcomen::Page instance) will be the first parameter of this method, the Newcomen::Data instance containing the options (or a newly created empty one, if no options were supplied) will be the second parameter. _do_render() has to return a string containing the rendered content.

SEE ALSO ^

Newcomen::Data, Newcomen::Page, Newcomen::Renderer

VERSION ^

This is version 2014052501.

AUTHOR ^

Stefan Goebel - newcomen {at} subtype {dot} de

COPYRIGHT AND LICENSE ^

Copyright 2013-2014 Stefan Goebel.

This file is part of Newcomen.

Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.