App-Templer

 view release on metacpan or  search on metacpan

bin/templer  view on Meta::CPAN

# These are the default settings.
#
my %DEFAULTS = ( "in-place"     => 0,
                 "include-path" => "./includes",
                 "input"        => "./input/",
                 "layout"       => "default.layout",
                 "layout-path"  => "./layouts",
                 "output"       => "./output/",
                 "plugin-path"  => "./plugins",
                 "suffix"       => ".skx",
                 "verbose"      => ( $CONFIG{ 'verbose' } || 0 ),
                 "debug"        => ( $CONFIG{ 'debug' } || 0 ),
                 "force"        => ( $CONFIG{ 'force' } || 0 ),
                 "sync"         => ( $CONFIG{ 'sync' } || 0 ),
               );


#
#  The defaults will now be over-ridden by anything which is specified
# in the configuration file that we've loaded/parsed.
#
my %SITE = $cfg->fields();
foreach my $field ( keys %SITE )
{
    $DEFAULTS{ $field } = $SITE{ $field };
}

#
# We need to keep the global configuration file name to add it as a dependency
# for every page
#
$DEFAULTS{ 'config' } = $cnf;

#
#  Add in any definitions we've received.
#
if ( $CONFIG{ 'defines' } )
{
    my $defs = $CONFIG{ 'defines' };

    foreach my $kv (@$defs)
    {
        if ( $kv =~ /^([^=]+)=(.*)$/ )
        {
            my $key = $1;
            my $val = $2;
            $DEFAULTS{ lc $key } = $val;
        }
    }
}


#
#  If we're running a HTTP-server do it now, since we've got
# all the data we need.
#
runHTTPD() if ( $CONFIG{ 'serve' } );


#
#  Now we've setup the defaults, and updated them via the configuration
# file we're ready to actually build/rebuild the templer-site.
#
#  We'll create the Templer::Site object to do that, the init method
# will ensure we have the input directory, and create the output directory
# if it is missing and required.
#
my $site = Templer::Site->new(%DEFAULTS);
$site->init();


#
#  Execute any pre-build commands the user might have defined.
#
runCommands('pre-build');


#
#  Record the start time.
#
my $timer = Templer::Timer->new();


#
#  Build/rebuild the site.
#
my $rebuilt = $site->build();

#
#  Copy the assets into place.
#
$site->copyAssets();

#
#  Synchronize destination with input
#
$site->sync();

#
#  Run any post-build commands the user might have defined.
#
runCommands("post-build");




#
# All done.
#
my $duration = $timer->elapsed();
print "\nAll done: $rebuilt page(s) updated in $duration.\n"
  unless ( $CONFIG{ 'quiet' } );

exit(0);




#
#  Parse the command line
#
sub parseCommandLine
{
    my @defines;

    #
    #  Parse the command line.
    #
    exit
      if (
        !Getopt::Long::GetOptions(

            # Help options
            "help",   \$CONFIG{ 'help' },
            "manual", \$CONFIG{ 'manual' },

            # load the config file
            "config=s", \$CONFIG{ 'config' },

            # define a variable
            "define=s", \@defines,

            # force a rebuild
            "force", \$CONFIG{ 'force' },

            # undocumented.
            "serve=i", \$CONFIG{ 'serve' },

            # run quietly.
            "quiet", \$CONFIG{ 'quiet' },

            # run verbosely.
            "verbose", \$CONFIG{ 'verbose' },
            "version", \$CONFIG{ 'version' },
            "debug",   \$CONFIG{ 'debug' },
        ) );


    #
    #  Help/Manual handling.
    #
    Pod::Usage::pod2usage( -input => \*DATA, ) if ( $CONFIG{ 'help' } );
    Pod::Usage::pod2usage( -input => \*DATA, -verbose => 2 )
      if ( $CONFIG{ 'manual' } );


    #
    #  Show the release.
    #
    if ( $CONFIG{'version'} )
    {



( run in 0.615 second using v1.01-cache-2.11-cpan-39bf76dae61 )