* Added an index.html and favicon as well as a very basic 'home' cgi script which will allow the web development to start. Signed-off-by: Digimer <digimer@alteeve.ca>main
parent
b571fa043e
commit
0ee84cd31e
7 changed files with 328 additions and 1 deletions
@ -0,0 +1,236 @@ |
|||||||
|
package AN::Tools::Template; |
||||||
|
# |
||||||
|
# This module contains methods used to handle templates. |
||||||
|
# |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use Data::Dumper; |
||||||
|
|
||||||
|
our $VERSION = "3.0.0"; |
||||||
|
my $THIS_FILE = "Template.pm"; |
||||||
|
|
||||||
|
### Methods; |
||||||
|
# get |
||||||
|
|
||||||
|
=pod |
||||||
|
|
||||||
|
=encoding utf8 |
||||||
|
|
||||||
|
=head1 NAME |
||||||
|
|
||||||
|
AN::Tools::Template |
||||||
|
|
||||||
|
Provides all methods related to template handling. |
||||||
|
|
||||||
|
=head1 SYNOPSIS |
||||||
|
|
||||||
|
use AN::Tools; |
||||||
|
|
||||||
|
# Template a common object handle on all AN::Tools modules. |
||||||
|
my $an = AN::Tools->new(); |
||||||
|
|
||||||
|
# Access to methods using '$an->Template->X'. |
||||||
|
# |
||||||
|
# Example using '()'; |
||||||
|
|
||||||
|
|
||||||
|
=head1 METHODS |
||||||
|
|
||||||
|
Methods in this module; |
||||||
|
|
||||||
|
=cut |
||||||
|
sub new |
||||||
|
{ |
||||||
|
my $class = shift; |
||||||
|
my $self = { |
||||||
|
SKIN => { |
||||||
|
HTML => "", |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
bless $self, $class; |
||||||
|
|
||||||
|
return ($self); |
||||||
|
} |
||||||
|
|
||||||
|
# Get a handle on the AN::Tools object. I know that technically that is a sibling module, but it makes more |
||||||
|
# sense in this case to think of it as a parent. |
||||||
|
sub parent |
||||||
|
{ |
||||||
|
my $self = shift; |
||||||
|
my $parent = shift; |
||||||
|
|
||||||
|
$self->{HANDLE}{TOOLS} = $parent if $parent; |
||||||
|
|
||||||
|
return ($self->{HANDLE}{TOOLS}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
############################################################################################################# |
||||||
|
# Public methods # |
||||||
|
############################################################################################################# |
||||||
|
|
||||||
|
=head2 get |
||||||
|
|
||||||
|
This method takes a template file name and a template section name and returns that body template. |
||||||
|
|
||||||
|
my $body = $an->Template->get({file => "foo.html", name => "bar"})) |
||||||
|
|
||||||
|
=head2 Parameters; |
||||||
|
|
||||||
|
=head3 file (required) |
||||||
|
|
||||||
|
This is the name of the template file containing the template section you want to read. |
||||||
|
|
||||||
|
=head3 name (required) |
||||||
|
|
||||||
|
This is the name of the template section, bounded by 'C<< <!-- start foo --> >>' and 'C<< <!-- end food --> >>' to read in from the file. |
||||||
|
|
||||||
|
=head3 skin (optional) |
||||||
|
|
||||||
|
By default, the |
||||||
|
|
||||||
|
=cut |
||||||
|
sub get |
||||||
|
{ |
||||||
|
my $self = shift; |
||||||
|
my $parameter = shift; |
||||||
|
my $an = $self->parent; |
||||||
|
|
||||||
|
my $file = defined $parameter->{file} ? $parameter->{file} : ""; |
||||||
|
my $name = defined $parameter->{name} ? $parameter->{name} : ""; |
||||||
|
my $skin = defined $parameter->{skin} ? $parameter->{skin} : ""; |
||||||
|
my $template = ""; |
||||||
|
my $source = ""; |
||||||
|
|
||||||
|
my $error = 0; |
||||||
|
if (not $file) |
||||||
|
{ |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Error ] - No template file passed to Template->get().\n"; |
||||||
|
$error = 1; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
# Make sure the file exists. |
||||||
|
if ($skin) |
||||||
|
{ |
||||||
|
$source = $an->data->{path}{source}{skins}."/".$skin."/".$file; |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Debug ] - source: [$source]\n"; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
$source = $an->Template->skin."/".$file; |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Debug ] - source: [$source]\n"; |
||||||
|
} |
||||||
|
if (not -e $source) |
||||||
|
{ |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Error ] - No requested template file: [".$source."] does not exist. Is it missing in the active skin?\n"; |
||||||
|
$error = 1; |
||||||
|
} |
||||||
|
elsif (not -r $source) |
||||||
|
{ |
||||||
|
my $user_name = getpwuid($<); |
||||||
|
$user_name = $< if not $user_name; |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Error ] - The requested template file: [".$source."] is not readable. Please check that it is readable by the webserver user: [$user_name]\n"; |
||||||
|
$error = 1; |
||||||
|
} |
||||||
|
} |
||||||
|
if (not $name) |
||||||
|
{ |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Error ] - No template file passed to Template->get().\n"; |
||||||
|
$error = 1; |
||||||
|
} |
||||||
|
|
||||||
|
if (not $error) |
||||||
|
{ |
||||||
|
my $in_template = 0; |
||||||
|
my $shell_call = $source; |
||||||
|
open(my $file_handle, "<$shell_call") or warn $THIS_FILE." ".__LINE__."; Failed to read: [$shell_call], error was: $!\n"; |
||||||
|
while(<$file_handle>) |
||||||
|
{ |
||||||
|
chomp; |
||||||
|
my $line = $_; |
||||||
|
if ($line =~ /^<!-- start $name -->/) |
||||||
|
{ |
||||||
|
$in_template = 1; |
||||||
|
} |
||||||
|
if ($in_template) |
||||||
|
{ |
||||||
|
if ($line =~ /^<!-- end $name -->/) |
||||||
|
{ |
||||||
|
$in_template = 0; |
||||||
|
last; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
$template .= $line."\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
close $file_handle; |
||||||
|
} |
||||||
|
|
||||||
|
return($template); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
=head2 skin |
||||||
|
|
||||||
|
This sets or returns the active skin used when rendering web output. |
||||||
|
|
||||||
|
The default skin is set via 'C<< defaults::template::html >>' and it must be the same as the directory name under 'C<< /var/www/html/skins/ >>'. |
||||||
|
|
||||||
|
Get the active skin; |
||||||
|
|
||||||
|
my $skin = $an->Template->skin; |
||||||
|
|
||||||
|
Set the active skin to 'C<< foo >>'. |
||||||
|
|
||||||
|
$an->Template->skin({set => "foo"}); |
||||||
|
|
||||||
|
Disable sensitive log entry recording. |
||||||
|
|
||||||
|
$an->Log->secure(0); |
||||||
|
|
||||||
|
=cut |
||||||
|
sub skin |
||||||
|
{ |
||||||
|
my $self = shift; |
||||||
|
my $parameter = shift; |
||||||
|
my $an = $self->parent; |
||||||
|
|
||||||
|
my $set = defined $parameter->{skin} ? $parameter->{skin} : ""; |
||||||
|
|
||||||
|
if ($set) |
||||||
|
{ |
||||||
|
my $skin_directory = $an->data->{path}{source}{skins}."/".$set; |
||||||
|
if (-d $skin_directory) |
||||||
|
{ |
||||||
|
$self->{SKIN}{HTML} = $skin_directory |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
print $THIS_FILE." ".__LINE__."; [ Warning ] - Asked to set the skin: [$set], but the source directory: [$skin_directory] doesn't exist. Ignoring.\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (not $self->{SKIN}{HTML}) |
||||||
|
{ |
||||||
|
$self->{SKIN}{HTML} = $an->data->{path}{source}{skins}."/".$an->data->{defaults}{template}{html}; |
||||||
|
} |
||||||
|
|
||||||
|
return($self->{SKIN}{HTML}); |
||||||
|
} |
||||||
|
|
||||||
|
# =head3 |
||||||
|
# |
||||||
|
# Private Functions; |
||||||
|
# |
||||||
|
# =cut |
||||||
|
|
||||||
|
############################################################################################################# |
||||||
|
# Private functions # |
||||||
|
############################################################################################################# |
||||||
|
|
||||||
|
1; |
@ -0,0 +1,18 @@ |
|||||||
|
#!/usr/bin/perl |
||||||
|
# |
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use AN::Tools; |
||||||
|
|
||||||
|
my $an = AN::Tools->new(); |
||||||
|
|
||||||
|
my $THIS_FILE = "home"; |
||||||
|
|
||||||
|
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. |
||||||
|
$| = 1; |
||||||
|
|
||||||
|
print "Content-type: text/html; charset=utf-8\n\n"; |
||||||
|
print "hello.\n"; |
||||||
|
|
||||||
|
|
||||||
|
exit(0); |
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,8 @@ |
|||||||
|
<head> |
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||||
|
<title>Striker</title> |
||||||
|
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=cgi-bin/home"> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
Hi, I'll be right with you... |
||||||
|
</body> |
@ -0,0 +1,38 @@ |
|||||||
|
<!-- start master --> |
||||||
|
#!replace!header!# |
||||||
|
|
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
#!replace!left_top_bar!# |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
#!replace!center_top_bar!# |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
#!replace!right_top_bar!# |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td colspan="3"> |
||||||
|
#!replace!center_body!# |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
#!replace!left_bottom_bar!# |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
#!replace!center_bottom_bar!# |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
#!replace!right_bottom_bar!# |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
#!replace!footer!# |
||||||
|
<!-- end master --> |
||||||
|
|
||||||
|
<!-- start button_bar --> |
||||||
|
<!--end button_bar --> |
Loading…
Reference in new issue