NAME
Templer::Site - An interface to a templer site.
SYNOPSIS
use strict;
use warnings;
use Templer::Site;
# Create the helper.
my $site = Templer::Site->new( suffix => ".skx" );
# Get the pages/assets.
my @pages = $site->pages();
my @assets = $site->assets();
DESCRIPTION
This class encapsulates a site. A site is comprised of "pages" and "assets".
- Pages
-
Pages are things which are template expanded. These are represented by instances of the
Templer::Site::Page
class. - Assets
-
Assets are files that are merely copied from the input directory to the output path. If we're running in "in-place" mode then they are ignored.
Assets are represented by instances of the
Templer::Site::Assets
class.
This class contains helpers for finding and returning arrays of both such objects, and the code necessary to work with them and build a site.
LICENSE
This module is free software; you can redistribute it and/or modify it under the terms of either:
a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or
b) the Perl "Artistic License".
AUTHOR
Steve Kemp <steve@steve.org.uk>
COPYRIGHT AND LICENSE
Copyright (C) 2012-2015 Steve Kemp <steve@steve.org.uk>.
This library is free software. You can modify and or distribute it under the same terms as Perl itself.
METHODS
new
Constructor, this should be given a hash of arguments for example:
- input
-
The input directory to process.
- output
-
The output directory to write to.
- suffix
-
The suffixe that will discover "Pages", for example '.skx', or '.tmplr'.
init
Ensure that the input directory exists.
Create the output directory if we're not running in-place.
Create array of destination files.
pages
A site comprises of a collection of pages and a collection of static resources which aren't touched/modified - these are "assets".
Return a Templer::Site::Page
object for each page we've found.
NOTE We don't process pages with a "." prefix, i.e. dotfiles.
assets
A site comprises of a collection of pages and a collection of static resources which aren't touched/modified - these are "assets".
Return a Templer::Site::Asset
object for each asset we find.
NOTE We include files which have a "." prefix here - to correctly copy files such as ".htpasswd", ".htaccess", etc.
_findFiles
Internal method to find files beneath the given directory and return a new object for each one.
We assume that the object constructor receives a hash as its sole argument with the key "file" containing the file path.
build
Build the site.
This is the method which does all the page-expansion, site-generation, etc.
The return value is the count of pages built.
copyAssets
Copy all assets from the input directory to the output directory.
This method will use tar to do so semi-efficiently.
sync
Delete all files from output directory which do not come from the input directory.
set
Store/update a key/value pair in our internal store.
This allows the values passed in the constructor to be updated/added to.
fields
Get all known key + value pairs from our store.
This is called to get all global variables for template interpolation as part of the build. (The global variables and the per-page variables are each fetched and expanded via plugins prior to getting sent to the HTML::Template object.).
get
Get a single value from our store of variables.