4 # artemus - HTML (and other things) Preprocessor
6 # Copyright (C) 2000/2002 Angel Ortega <angel@triptico.com>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # http://www.triptico.com
30 $artemus_id="Artemus $VERSION";
32 # substitution variables
35 # substitution functions
38 # source and destination files
43 $config_file="artemus.conf";
45 # local configuration file
46 $local_config_file="local-artemus.conf";
51 # use cr/lf instead of lf
54 # append instead of overwrite output file
57 # send files using ftp
63 # create makefile template
69 # inverse substitutions
70 $inverse_config_file="artemus-inv.conf";
76 # include debugging info
79 # list of unresolved symbols
82 #####################################################################
85 usage() if(!GetOptions( "i|input=s" => \$src,
86 "o|output=s" => \$dst,
87 "c|conf=s" => \$config_file,
88 "p|paragraph=s" => \$para_sep,
89 "m|msdos" => \$use_cr_lf,
90 "a|append" => \$append,
91 "v|version-only" => \$version_only,
93 "k|makefile" => \$makefile_template,
94 "s|site-map" => \$site_map,
96 "l|include-path=s" => \$include_path,
98 "h|help" => \$help) or $help);
100 $dst=">-" if $dst eq "-";
102 version_only() if $version_only;
104 make_makefile() if $makefile_template;
106 build_site_map(@ARGV) if $site_map;
114 # read the configuration files
115 read_config($config_file) if -f $config_file;
116 read_config($local_config_file) if -f $local_config_file;
117 read_config($inverse_config_file,1) if -f $inverse_config_file;
119 ftp_send() if $use_ftp;
121 open F, $src or die "can't open '$src'";
132 $data="<meta name=\"generator\" content=\"$artemus_id\">\n".$data;
133 $data=sprintf("<!-- Date: %s -->\n",scalar(localtime)).$data;
134 $data="<!-- Built with $artemus_id Angel Ortega 2000/2002 -->\n".$data;
138 $funcs{"filesize"}=sub { -s $_[0] };
139 $funcs{"shell"}=sub { $_=`$_[0]`; chop; return $_ };
141 $data=artemus($data, "paragraph-separator" => $para_sep,
143 "inv-vars" => \%inv_vars,
145 "include-path" => $include_path,
146 "use-cr-lf" => $use_cr_lf,
148 "unresolved" => \@unresolved
153 open F, ($append?">":"").">$dst" or die "can't write '$dst'";
160 foreach my $e (@unresolved)
162 print STDERR "Unresolved: '$e'\n";
169 # #####################################################################
173 my ($conf,$inverse)=@_;
177 unless(open F, $conf)
182 { die "'$conf' bad config file"; }
193 ($key,$val)=split("=",$_,2);
200 elsif($val eq "<<EOF")
202 # 'document here' construction
212 elsif($key eq "\\INCLUDE")
219 $inv_vars{$key}=$val if($inverse);
229 print("$artemus_id - HTML (and other things) Preprocessor\n");
230 print("Copyright (C) 2000/2002 Angel Ortega <angel\@triptico.com>\n\n");
233 print(" artemus -i|--input={input file} -o|--output={output file}\n");
234 print(" [-c|--conf={config file}]\n");
235 print(" [-l|--include-path={path to includes}]\n");
236 print(" [-p|--paragraph={paragraph_separator}]\n");
237 print(" [-q|--quiet]\n");
238 print(" [-m|--msdos] [-a|--append] [-d|--debug]\n\n");
240 print(" artemus -f|--ftp {files to ftp...}\n\n");
242 print(" artemus -k|--makefile\n");
244 print(" artemus -s|--site-map\n");
258 # send files using ftp
266 print "Nothing to send.\n";
270 print "Connecting to $vars{'ftp.host'}...\n";
271 $ftp=Net::FTP->new($vars{'ftp.host'});
274 print "Logging in as $vars{'ftp.user'}...\n";
275 $ftp->login($vars{'ftp.user'},$vars{'ftp.passwd'})
276 or die "ftp login error";
279 if(defined($vars{'ftp.dir'}))
281 print "Chdir $vars{'ftp.dir'}...\n";
282 $ftp->cwd($vars{'ftp.dir'});
288 foreach my $f (@ARGV)
290 print "Sending $f...\n";
303 # makes a makefile template
307 # Makefile template created by $artemus_id
308 # for HTML projects (GNU Make)
310 # artemus (C) 2000/2002 Angel Ortega <angel\@triptico.com>
313 # make -- to build everything
314 # make file.html -- to build just file.html from file.artemus
315 # make clean -- to delete every rebuildable thing
316 # make ftp -- to upload using ftp
319 # Fill DEST with a list of the .html files created by artemus
320 # Use relative paths (e.g. misc/contact.html) if there are
321 # subdirectories. This paths will be the same when uploading;
322 # subdirs on ftp server must exist
324 DEST= index.html [MODIFY HERE]
326 # Add \$(DEST) to INET plus any other file/directory than will
327 # be uploaded but not built by this makefile.
328 # e.g.: download/* or images/*
330 INET=\$(DEST) images/* [MODIFY HERE]
332 # directories for the site map
339 # default rule. Artemus sources use the .artemus extension.
340 # Change if you use another
342 artemus -i \$< -o \$@
344 # site map. File sitemap/index.artemus must be included
345 # in DEST in order to be correctly remade.
347 artemus --site-map \$(DIRS) > sitemap/index.artemus
353 -rm \$(DEST) unresolved
355 # Last upload timestamp
359 # if any file is newer than the last upload,
360 # send it and recreate timestamp
372 # builds a site map from current directory to stdout
376 # special artemus token site-map-head
377 print "{-site-map-head}\n\n";
380 foreach my $dir (@dirs)
384 open F, "find $dir -name \"*.html\" -follow|" or next;
390 push(@l,$_) unless /index.html$/;
397 # the (supposed) index.html is put the first
398 unshift(@l,"$dir/index.html");
404 my ($size,$file,$title);
413 if ($file =~ /<title>([^<]*)/i)
422 print "<li><a href='../$i'>$title</a> [$i] $size bytes\n";
423 print "<ul>\n" unless $cnt;
432 # special artemus token site-map-foot
433 print "{-site-map-foot}\n";