Source

vim-begin / vim-begin / jekyll-prototype / process.pl

#!/usr/bin/perl

use strict;
use warnings;

use Template;
use File::Find::Object;

use File::Path qw( mkpath );
use File::Spec;
use File::Copy qw( copy );

my $template = Template->new(
    {
        INCLUDE_PATH => ".",
        POST_CHOMP => 1,
        RELATIVE => 1,
        ENCODING => 'utf8',
    }
);

my $vars = {};

my $tree = File::Find::Object->new({}, './src');

while (my $result = $tree->next_obj())
{
    if ($result->is_dir())
    {
        if ($result->path() eq './dest')
        {
            $tree->prune();
        }
        else
        {
            mkpath(File::Spec->catdir(
                    File::Spec->curdir(), "dest", @{$result->full_components()}
                )
            );
        }
    }
    else
    {
        my $basename = $result->basename;
        if ($basename =~ s/\.html\.tt2\z/.html/)
        {
            $template->process($result->path(), $vars,
                File::Spec->catfile(File::Spec->curdir(), "dest",
                    @{$result->dir_components()}, $basename),
                binmode => ':utf8',
            )
                or die $template->error();
        }
        elsif (
            $basename !~ /~\z/
            && ( !($basename =~ /\A\./ && $basename =~ /\.swp\z/) )
            && ($basename ne 'process.pl')
        )
        {
            copy($result->path,
                File::Spec->catfile(File::Spec->curdir(), "dest",
                    @{$result->dir_components()}, $basename),
            );
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.