This particular gallery will work by scanning a directory for images and displaying them in our gallery page. As such the task it will have to accomplish is scanning for the images and recording their urls for displaying them in the page. That's pretty much all it has to do so we should only need one plugin for it. Let's call our action plugin list_images. It will go in the plugins/action directory. and just like our example plugin it requires a certain set of methods and class variables. Besides those it will have to return a list of images in a form our tag handler will be able to handle. It's probably best to just have the run method return this for us so we stay with the standard. Lets get started shall we?
#---------------------------------------------
#
# File: list_images.pm
# Version: 0.1
# Author: Jeremy Wall
# Definition:
#
#---------------------------------------------
package list_images;
use lib::common::plugin;
use base qw(plugin);
our %MetaData = (Name => "list_images",
Type => "Action",
Author => "Author",
Version => "0.1",
URI => "http://someurl/",
);
sub run {
my $self = shift;
my @imagelist; # this will be our array of images
my $bk = $self->app(); # our bricklayer object
# for any bricklayer utilities
# we might need
#code to return a list of images in the gallery directory
}
return 1;
Now we have our plugin's skeleton all done. All we have to do is write our code to retrieve the array of images from the directory. We can use bricklayers filemanager object to do this. What we need is to take our directory request which we will probably want to get from a request variable found in our environment hash. Good thing we stored the bricklayer app object cause we are going to need it.
#---------------------------------------------
#
# File: list_images.pm
# Version: 0.1
# Author: Jeremy Wall
# Definition:
#
#---------------------------------------------
package list_images;
use lib::common::plugin;
use base qw(plugin);
our %MetaData = (Name => "list_images",
Type => "Action",
Author => "Author",
Version => "0.1",
URI => "http://someurl/",
);
sub run {
my $self = shift;
my @imagelist; # this will be our array of images
my $bk = $self->app(); # our bricklayer object
# for any bricklayer utilities
# we might need
# code to return a list of images
# in the gallery directory
my $directory = $bk->env()->{dir};
my $imagetype = $bk->env()->{imagetype};
my $fileobj = $bk->new_file_obj($directory);
@imagelist = $fileobj->view_files_of_type($imagetype);
$fileobj->close_object();
return \@imagelist;
}
return 1;
We recovered two items from the environment hash to tell us where the directory was and what kind of image files we were looking for. then we used the file manager object to retrieve the list for use and returned it making sure to close the file manager object before we do. Now we are ready to start working on our tag handlers.
Jeremy Wall
2006-08-21