use strict ;
use Carp ;
+use File::Path;
use Data::Dumper ;
use CMS::Simple::Parse ;
return $self ;
}
+sub _find_content_file {
+
+ my( $self, $file ) = @_ ;
+
+ my @dirs = @{$self->{content_paths}} ;
+
+ foreach my $dir ( @dirs ) {
+
+ my $file_path = "$dir/$file" ;
+
+ return $file_path if -e $file_path ;
+ }
+
+ croak "can't file content file '$file' in [@dirs]" ;
+}
+
sub _load_content {
# ADD BETTER DIRECTORY STUFF
######
- my $file_path = "$self->{content_paths}[0]/$file" ;
+ my $file_path = $self->_find_content_file( $file ) ;
my $content_text = read_file( $file_path ) ;
+#print "FILE $file_path\n$content_text" if $file_path =~ /location/;
+
my ($suffix) = $file_path =~ /\.(\w+)$/ ;
my $parser = $parsers{ $suffix } ;
- $parser or die "unknown suffix '$suffix'" ;
+ $parser or croak "unknown suffix '$suffix'" ;
my $parsed = $parser->( $content_text ) ;
$self->_filter_page_content( $page ) ;
+ if( my $filter = $page->{filter} ) {
+ $filter->( $page ) ;
+ }
$self->_render_page( $page ) ;
#print ${$page->{rendered}} ;
my $page_contents = $page->{contents} || {} ;
+ $page->{contents_map} ||= { $page->{name} => '' } ;
+
# loop over the default (common) and page specific content maps
foreach my $contents_map (
$self->{default_contents_map},
$page->{contents_map} ) {
-#print "MAP ", Dumper $contents_map ;
+print "MAP ", Dumper $contents_map if $page->{dump_content} ;
+
+ if ( ref $contents_map eq 'ARRAY' ) {
- while( my( $name, $location ) = each %{$contents_map} ) {
+ for( my $i = 0 ; $i < @$contents_map ; $i += 2 ) {
# get the contents for this content name
+ my( $name, $location ) =
+ @{$contents_map}[$i, $i+1] ;
+
+ my $contents = $all_contents->{$name}{parsed} ;
+
+ $self->_add_page_contents(
+ $page_contents,
+ $location,
+ $contents
+ ) ;
+
+#print "CONT ", Dumper $page_contents if $page->{dump_content} ;
- my $contents = $all_contents->{$name}{parsed} ;
+ }
+ }
+ else {
+ while( my( $name, $location ) =
+ each %{$contents_map} ) {
+
+ # get the contents for this content name
+
+ my $contents = $all_contents->{$name}{parsed} ;
- $self->_add_page_contents(
- $page_contents,
- $location,
- $contents
- ) ;
+ #print "CONT ", Dumper $contents if $page->{dump_content} ;
+
+ $self->_add_page_contents(
+ $page_contents,
+ $location,
+ $contents
+ ) ;
+ }
}
}
- print Dumper $page_contents if $page->{dump} ;
+ print "ALL CONT ", Dumper $page_contents if $page->{dump_content} ;
$page->{contents} = $page_contents ;
}
$self->_filter_content_hash( $page->{contents} ) ;
-#print Dumper $page->{contents} ;
+ print "DONE\n", Dumper $page->{contents} if $page->{dump_filtered} ;
}
sub _filter_content_hash {
next unless @new_val ;
$href->{$tag} = $new_val[0] ;
+
+#print "NEW\n", Dumper \@new_val if $tag =~ /location/ ;
+
}
}
my( $self, $tag, $val, $path ) = @_ ;
+#print "TAG1 $tag\n" ;
+#print "TAG $tag\n" if $tag =~ /location/ ;
+
my $ref_type = ref $val ;
+
+ if( my @new_val =
+ $self->_filter_content_value( $tag, $val, $path ) ) {
+
+ $val = $new_val[0] ;
+
+#print "VAL $tag\n" if $tag =~ /location/ ;
+
+# handle case where the filter changed the type of the value
+
+ $ref_type = ref $val ;
+ }
if ( $ref_type eq 'HASH' ) {
+#print "HASH $tag\n" if $tag =~ /location/ ;
+
$self->_filter_content_hash( $val, $path ) ;
return $val ;
}
return $val ;
}
- my @new_val = $self->_filter_content_value( $tag, $val, $path ) ;
-
- return unless @new_val ;
-
- $val = $new_val[0] ;
-
- $self->_filter_content_tag( $tag, $val, $path ) if ref $val ;
-
return $val ;
}
my( $self, $tag, $val, $path ) = @_ ;
+#print "VAL TAG $tag\n" if $tag =~ /location/ ;
+
my $filters = $self->{tag_to_filters}{$tag} ;
return unless $filters ;
# use file::path stuff to make this portable
##########
- my $output_path =
- "$self->{'output_dir'}/$page->{name}$self->{'output_suffix'}" ;
+ my $sub_dir = $page->{sub_dir} || '' ;
+ $sub_dir .= '/' if $sub_dir ;
+
+ my $suffix = $page->{'output_suffix'} || $self->{'output_suffix'} ;
+
+ my $output_dir = "$self->{'output_dir'}/$sub_dir" ;
+
+ mkpath( $output_dir ) unless -d $output_dir ;
+
+ my $output_path = "$output_dir$page->{name}$suffix" ;
$page->{'output_path'} = $output_path ;
image_link => \&make_image_link,
ilink => \&make_image_link,
nbsp => sub { ' ' },
+ bold => \&make_bold,
em_dash => sub { '—' },
eacute => sub { 'é' },
copy => sub { '©' },
#print "KEY $key [$text]\n" ;
+ $text = 'UNDEF' unless defined $text ;
+
my $code = $markup_to_code{ $key } ;
- $code or die "unknown markup key '$key'" ;
+ $code or die "unknown markup key '$key' text '$text'" ;
return $code->($text) ;
}
$url_text ||= $url ;
- return qq{<A href="$url">$url_text</A>} ;
+ return qq{<a href="$url">$url_text</a>} ;
}
sub google_map {
( my $url_text = $text ) =~ tr/ \t\n\r/+/s ;
return
-qq{<A href="http://maps.google.com/maps?f=q&hl=en&q=$url_text">$text</A>} ;
+qq{<a href="http://maps.google.com/maps?f=q&hl=en&q=$url_text">$text</a>} ;
}
sub make_email {
my( $url, $image_url ) = split /\|/, $text ;
- return qq{<A href="$url"><IMG src="$image_url"></A>} ;
+ return qq{<a href="$url"><img src="$image_url"></a>} ;
}
sub make_image {
my( $text ) = @_ ;
- return qq{<IMG src="$text">} ;
+ return qq{<img src="$text">} ;
}
+
+sub make_bold {
+
+ my( $text ) = @_ ;
+
+ return qq{<B>$text</B>} ;
+}
+
+1 ;