From: Uri Guttman <uri@quad.(none)>
Date: Mon, 7 May 2012 06:47:04 +0000 (-0400)
Subject: random changes
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=urisagit%2FCMS-Simple.git

random changes
---

diff --git a/CMS/Simple.pm b/CMS/Simple.pm
index f47fb3f..05184e1 100644
--- a/CMS/Simple.pm
+++ b/CMS/Simple.pm
@@ -4,6 +4,7 @@ use warnings ;
 use strict ;
 
 use Carp ;
+use File::Path;
 use Data::Dumper ;
 
 use CMS::Simple::Parse ;
@@ -62,6 +63,22 @@ sub new {
 	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 {
 
@@ -77,15 +94,17 @@ 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 ) ;
 
@@ -129,6 +148,9 @@ sub build_page {
 
 	$self->_filter_page_content( $page ) ;
 
+	if( my $filter = $page->{filter} ) {
+		$filter->( $page ) ;
+	}
 
 	$self->_render_page( $page ) ;
 #print ${$page->{rendered}} ;
@@ -149,29 +171,56 @@ sub _get_page_content {
 
 	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 ;
 }
@@ -218,7 +267,7 @@ sub _filter_page_content {
 
 	$self->_filter_content_hash( $page->{contents} ) ;
 
-#print Dumper $page->{contents} ;
+	print "DONE\n", Dumper $page->{contents} if $page->{dump_filtered} ;
 }
 
 sub _filter_content_hash {
@@ -232,6 +281,9 @@ sub _filter_content_hash {
 
 		next unless @new_val ;
 		$href->{$tag} = $new_val[0] ;
+
+#print "NEW\n", Dumper \@new_val if $tag =~ /location/ ;
+
 	}
 }
 
@@ -259,10 +311,27 @@ sub _filter_content_tag {
 
 	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 ;
 	}
@@ -273,14 +342,6 @@ sub _filter_content_tag {
 		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 ;
 }
 
@@ -288,6 +349,8 @@ sub _filter_content_value {
 
 	my( $self, $tag, $val, $path ) = @_ ;
 
+#print "VAL TAG $tag\n" if $tag =~ /location/ ;
+
 	my $filters = $self->{tag_to_filters}{$tag} ;
 
 	return unless $filters ;
@@ -347,8 +410,16 @@ sub _output_page {
 # 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 ;
 
diff --git a/CMS/Simple/Filter/Markup.pm b/CMS/Simple/Filter/Markup.pm
index 3861f94..baed318 100644
--- a/CMS/Simple/Filter/Markup.pm
+++ b/CMS/Simple/Filter/Markup.pm
@@ -13,6 +13,7 @@ my %markup_to_code = (
 	image_link	=> \&make_image_link,
 	ilink	=> \&make_image_link,
 	nbsp	=> sub { '&nbsp;' },
+	bold	=> \&make_bold,
 	em_dash	=> sub { '&#151;' },
 	eacute	=> sub { '&#233;' },
 	copy	=> sub { '&#169;' },
@@ -42,9 +43,11 @@ sub replace_markup {
 
 #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) ;
 }
@@ -57,7 +60,7 @@ sub make_link {
 
 	$url_text ||= $url ;
 
-	return qq{<A href="$url">$url_text</A>} ;
+	return qq{<a href="$url">$url_text</a>} ;
 }
 
 sub google_map {
@@ -67,7 +70,7 @@ 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 {
@@ -94,12 +97,21 @@ sub make_image_link {
 
 	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 ;
diff --git a/make_slides/cms.pl b/make_slides/cms.pl
old mode 100755
new mode 100644
diff --git a/make_slides/make_slides.pl b/make_slides/make_slides.pl
old mode 100755
new mode 100644