package App::Followme::Initialize; use 5.008005; use strict; use warnings; use Cwd; use IO::File; use File::Spec::Functions qw(splitdir catfile); our $VERSION = "0.90"; our $modeline; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(initialize); #---------------------------------------------------------------------- # Initialize a new web site sub initialize { my ($directory) = @_; chdir($directory) if defined $directory; for (;;) { my ($file, $text) = next_file(); last unless defined $file; copy_file($file, $text); } return; } #---------------------------------------------------------------------- # Create a copy of the input file sub copy_file { my ($file, $text) = @_; my @dirs = split(/\//, $file); my $base = pop(@dirs); my $path = '.'; foreach my $dir (@dirs) { $path .= "/$dir"; if (! -d $path) { mkdir ($path) or die "Couldn't create $path: $!\n"; } } $path .= "/$base"; return if -e $path; my $out = IO::File->new($path, 'w') or die "Can't write $path"; print $out $text; close($out); return; } #---------------------------------------------------------------------- # Get the name and contents of the next file sub next_file { $modeline ||= ; return unless $modeline; my ($comment, $file) = split(' ', $modeline); die "Bad modeline: $modeline\n" unless defined $file; my $text = ''; $modeline = ''; while () { if (/^\#--\%X--\%X/) { $modeline = $_; last; } else { $text .= $_; } } my @dirs = split('/', $file); $file = catfile(@dirs); return ($file, $text); } 1; __DATA__ #--%X--%X followme.cfg module = App::Followme::FormatPages module = App::Followme::ConvertPages #--%X--%X archive/followme.cfg module = App::Followme::CreateNews module = App::Followme::CreateIndexes index_file = index.html news_file = ../blog.html exclude_files = index.html #--%X--%X templates/page.htm {{title}}

{{title}}

{{body}}
#--%X--%X templates/news.htm {{title}} #--%X--%X templates/index.htm {{title}}

{{title}}