From: Chris W. <la...@us...> - 2005-01-28 15:40:39
|
Update of /cvsroot/openinteract/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6465 Added Files: build_bricks Log Message: OIN-121: create initial script to generate the '::Bricks' subclasses that will hold the resource files used to build website/package --- NEW FILE: build_bricks --- #!/usr/bin/perl # $Id: build_bricks,v 1.1 2005/01/28 15:40:04 lachoy Exp $ # build_bricks # Generate the various OI2::Bricks::* classes formed by reading in # the various files used for creating a package/website. use strict; use Template; my %SPECS = ( 'sample/package' => [ 'Package', 'All resources used for creating a package', 'oi2_manage create_package --package=foo', 'This class just holds all the static resources used when creating a package.', ], 'sample/apache' => [ 'Apache', 'All resources used for creating Apache 1.x configurations in a new website', 'oi2_manage create_website --website_dir=/path/to/site', 'This class just holds all the static resources used for creating ' . 'Apache configuration files when creating a website.' ], 'sample/apache2' => [ 'Apache2', 'All resources used for creating Apache 2.x configurations in a new website', 'oi2_manage create_website --website_dir=/path/to/site', 'This class just holds all the static resources used for creating ' . 'Apache 2.x configuration files when creating a website.' ], 'sample/daemon' => [ 'Daemon', 'Configuration used for creating the standalone webserver', 'oi2_manage create_website --website_dir=/path/to/site', 'This class holds resources for configuring the standalone webserver daemon.', ], 'sample/website/cgi-bin' => [ 'CGI', 'Script for running OI2 as a CGI', 'oi2_manage create_website --website_dir=/path/to/site', 'This class holds the script for running OI2 as a CGI.', ], 'sample/website/conf' => [ 'WebsiteConfig', 'Various non-server-specific configuration files for OI2 website', 'oi2_manage create_website --website_dir=/path/to/site', 'This class holds various configuration files for running the OI2 website.', ], 'sample/website/msg' => [ 'Messages', 'All global localization messages', 'oi2_manage create_website --website_dir=/path/to/site', 'This class holds all global (non-package) localization messages.', ], 'sample/website/template' => [ 'Widgets', 'All global TT2 template files', 'oi2_manage create_website --website_dir=/path/to/site', 'This class holds all global (non-package) Template Toolkit templates, also known as "widgets".', ], ); { unless ( -d 'sample' ) { die "You must run this from the root of the OI2 source directory\n"; } my $oi2_version = read_version(); my $template = Template->new(); my $brick_template = join( '', <DATA> ); while ( my ( $brick_dir, $brick_info ) = each %SPECS ) { my @brick_files = read_brick_files( $brick_dir ); my $brick_name = $brick_info->[0]; my %params = ( brick_name => $brick_name, brick_summary => $brick_info->[1], brick_example => $brick_info->[2], brick_description => $brick_info->[3], oi2_version => $oi2_version, all_files => \@brick_files, ); my $output_file = "lib/OpenInteract2/Bricks/$brick_name.pm"; $template->process( \$brick_template, \%params, $output_file ) || die "Cannot process files from '$brick_dir' -> '$output_file': ", $template->error(); print "Generated $output_file ok\n"; } } sub read_brick_files { my ( $subdir ) = @_; my $filespec_path = "$subdir/FILES"; unless ( -f $filespec_path ) { die "Directory '$subdir' is not a valid sample directory -- it has no 'FILES' file\n"; } open( FILESPEC, '<', $filespec_path ) || die "Cannot read '$filespec_path': $!"; my @files = (); while ( <FILESPEC> ) { chomp; next if ( /^\s*#/ ); next if ( /^\s*$/ ); my ( $file, $destination ) = split /\s*\-\->\s*/, $_, 2; my $do_evaluate = ( $file =~ s/^\*// ) ? 'no' : 'yes'; my $file_path = "$subdir/$file"; open( FILE, '<', $file_path ) || die "Cannot read '$file_path': $!"; my $contents = join( '', <FILE> ); close( FILE ); my $inline_name = uc $file; $inline_name =~ s/\W//g; push @files, { name => $file, inline_name => $inline_name, destination => $destination, evaluatable => $do_evaluate, contents => $contents, }; } close( FILESPEC ); return @files; } sub read_version { open( VER, '<', 'VERSION' ) || die "Cannot open version doc: $!"; my $version = <VER>; chomp $version; close( VER ); $version =~ s/[^\d\_\.]//g; return $version; } __DATA__ package OpenInteract2::Bricks::[% brick_name %]; use strict; use base qw( OpenInteract2::Bricks ); use Inline::Files; sub get_resources { return ( [% FOREACH file_info = all_files -%] '[% file_info.name %]' => [ '[% file_info.inline_name %]', '[% file_info.destination %]', '[% file_info.evaluatable %]' ], [% END -%] ); } sub load { my ( $class, $name ) = @_; return join( '', <$name> ); } =pod =head1 NAME OpenInteract2::Bricks::[% brick_name %] - [% brick_summary %] =head1 SYNOPSIS [% brick_example | indent(2) %] =head1 DESCRIPTION [% brick_description %] =head1 COPYRIGHT Copyright (c) 2005 Chris Winters. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHORS Chris Winters E<lt>ch...@cw...E<gt> =cut [% FOREACH file_info = all_files %] __[% file_info.inline_name %]__ [% file_info.contents %] [% END %] |