View on
Alan Haggai Alavi > StaticVolt-0.03 > StaticVolt



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source   Latest Release: StaticVolt-1.00


StaticVolt - Static website generator


version 0.03


    use StaticVolt;

    my $staticvolt = StaticVolt->new;  # Default configuration



Accepts an optional hash with the following parametres:

    # Override configuration (parametres set explicitly)
    my $staticvolt = StaticVolt->new(
        'includes'    => '_includes',
        'layouts'     => '_layouts',
        'source'      => '_source',
        'destination' => '_destination',


Each file in the "source" directory is checked to see if it has a registered convertor as well as a YAML configuration at the beginning. All such files are compiled considering the "YAML Configuration Keys" and the compiled output is placed in the "destination" directory. The rest of the files are copied over to the "destination" without compiling.

YAML Configuration Keys

"YAML Configuration Keys" should be placed at the beginning of the file and should be enclosed within a pair of ---.

Example of using a layout along with a custom key and compiling a markdown "source" file:

"layout" file - main.html:

    <!DOCTYPE html>
            [% content %]

"source" file - index.markdown:

    layout: main.html
    drink : water
    Drink **plenty** of [% drink %].

"destination" (output/compiled) file - index.html:

    <!DOCTYPE html>
            <p>Drink <strong>plenty</strong> of water.</p>


Walkthrough ^

Consider the source file index.markdown which contains:

    layout : main.html
    title  : Just an example title
    heading: StaticVolt Example

    StaticVolt Example

    This is an **example** page.

Let main.html which is a wrapper or layout contain:

    <!DOCTYPE html>
            <title>[% title %]</title>
            [% content %]

During compilation, all variables defined as "YAML Configuration Keys" at the beginning of the file will be processed and be replaced by their values in the output file index.html. A registered convertor (StaticVolt::Convertor::Markdown) is used to convert the markdown text to HTML.

Compiled output file index.html contains:

    <!DOCTYPE html>
            <title>Just an example title</title>
            <h1>StaticVolt Example</h1>
            <p>This is an <strong>example</strong> page.</p>


Default Convertors ^

How to build a convertor? ^

The convertor should inherit from StaticVolt::Convertor. Define a subroutine named "convert" in StaticVolt::Convertor that takes a single argument. This argument should be converted to HTML and returned.

Register filename extensions by calling the register method inherited from StaticVolt::Convertor. register accepts a list of filename extensions.

A convertor template that implements conversion from a hypothetical format FooBar:

    package StaticVolt::Convertor::FooBar;

    use strict;
    use warnings;

    use base qw( StaticVolt::Convertor );

    use Foo::Bar qw( foobar );

    sub convert {
        my $content = shift;
        return foobar $content;

    # Handle files with the extensions:
    #   .foobar, .fb, .fbar, .foob
    __PACKAGE__->register(qw/ foobar fb fbar foob /);

Inspiration ^

StaticVolt is inspired by Tom Preston-Werner's Jekyll.

Acknowledgements ^

Shlomi Fish for suggesting change of licence.

See Also ^

Template Toolkit


Alan Haggai Alavi <>


This software is Copyright (c) 2011 by Alan Haggai Alavi.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: