changeset 61:89747520b861

2007-11-10 00:01:04 by steve Moved the XML files into their own directory to avoid duplication. Updated the code to have --theme-dir=xx --theme=xx instead of just the --template=xx
author steve
date Sat, 10 Nov 2007 00:01:04 +0000
parents 4af5f3ee59e8
children 41386f30097e
files Makefile bin/chronicle etc/chroniclerc themes/blocky/index.xml.template themes/blocky/month.xml.template themes/blocky/tags.xml.template themes/copyrighteous/index.xml.template themes/copyrighteous/month.xml.template themes/copyrighteous/tags.xml.template themes/default/index.xml.template themes/default/month.xml.template themes/default/tags.xml.template themes/xml/index.xml.template themes/xml/month.xml.template themes/xml/tags.xml.template
diffstat 15 files changed, 207 insertions(+), 167 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Oct 31 00:10:39 2007 +0000
+++ b/Makefile	Sat Nov 10 00:01:04 2007 +0000
@@ -8,7 +8,7 @@
 # --
 # http://www.steve.org.uk/
 #
-# $Id: Makefile,v 1.14 2007-10-25 18:36:50 steve Exp $
+# $Id: Makefile,v 1.15 2007-11-10 00:01:04 steve Exp $
 
 
 #
@@ -63,6 +63,8 @@
 	cp ./etc/chroniclerc ${prefix}/etc/chroniclerc
 	mkdir -p ${prefix}/usr/local/bin
 	cp ./bin/chronicle ${prefix}/usr/local/bin
+	mkdir -p ${prefix}/usr/share/chronicle/themes/xml
+	cp -r ./themes/xml/*.* ${prefix}/usr/share/chronicle/themes/xml
 	mkdir -p ${prefix}/usr/share/chronicle/themes/default
 	cp -r ./themes/default/*.* ${prefix}/usr/share/chronicle/themes/default
 	mkdir -p ${prefix}/usr/share/chronicle/themes/copyrighteous
--- a/bin/chronicle	Wed Oct 31 00:10:39 2007 +0000
+++ b/bin/chronicle	Sat Nov 10 00:01:04 2007 +0000
@@ -11,12 +11,13 @@
 
   Path Options:
 
-   --config      Specify a configuration file to read.
-   --input       Specify the input directory to use.
-   --output      Specify the directory to write output to.
-   --templates   Specify the path to the theme templates.
-   --pattern     Specify the pattern of files to work with.
-   --url-prefix  Specify the prefix to the live blog.
+   --config         Specify a configuration file to read.
+   --input          Specify the input directory to use.
+   --output         Specify the directory to write output to.
+   --theme-dir      Specify the path to the theme templates.
+   --theme          Specify the theme to use.
+   --pattern        Specify the pattern of files to work with.
+   --url-prefix     Specify the prefix to the live blog.
 
 
   Pre & Post-Build Commands:
@@ -173,7 +174,7 @@
  --
  http://www.steve.org.uk/
 
- $Id: chronicle,v 1.26 2007-10-31 00:10:39 steve Exp $
+ $Id: chronicle,v 1.27 2007-11-10 00:01:04 steve Exp $
 
 =cut
 
@@ -242,6 +243,24 @@
 
 
 #
+#  Make sure we have arguments which are sane.
+#
+#  Specifically we want to cope with the "new" 'theme-dir', and 'theme'
+# arguments.
+#
+#
+sanityCheckArguments();
+
+
+#
+#  Listing themes?
+#
+if ( $CONFIG{'list-themes'} )
+{
+    listThemes( $CONFIG{'theme-dir'} );
+    exit;
+}
+
 #  Should we run something before we start?
 #
 if ( $CONFIG{'pre-build'} )
@@ -400,9 +419,10 @@
     $CONFIG{'output'}     = "./output";
 
     #
-    #  Theme directory.
+    #  Theme setup
     #
-    $CONFIG{'template'}   = "./themes/default";
+    $CONFIG{'theme-dir'}   = "./themes/";
+    $CONFIG{'theme'}       = "default";
 
     #
     #  prefix for all links.
@@ -434,8 +454,6 @@
 
   Parse the command line arguments this script was given.
 
-  TODO:  Document these in the POD.
-
 =end doc
 
 =cut
@@ -455,12 +473,14 @@
                "manual",       \$MANUAL,
                "verbose",      \$CONFIG{'verbose'},
                "version",      \$VERSION,
+               "list-themes",  \$CONFIG{'list-themes'},
 
                # paths
                "config=s",     \$CONFIG{'config'},
                "input=s",      \$CONFIG{'input'},
                "output=s",     \$CONFIG{'output'},
-               "templates=s",  \$CONFIG{'template'},
+               "theme-dir=s",  \$CONFIG{'theme-dir'},
+               "theme=s",      \$CONFIG{'theme'},
                "pattern=s",    \$CONFIG{'pattern'},
 
                # optional
@@ -487,7 +507,7 @@
 
     if ( $VERSION )
     {
-        my $REVISION      = '$Revision: 1.26 $';
+        my $REVISION      = '$Revision: 1.27 $';
         if ( $REVISION =~ /1.([0-9.]+) / )
         {
             $REVISION = $1;
@@ -1051,8 +1071,6 @@
   This function is a *mess* and iterates over the data structure much
  more often than it needs to.
 
-  TODO:  FIXME
-
 =end doc
 
 =cut
@@ -1507,14 +1525,36 @@
     my( $file, %params ) = (@_);
 
     #
+    #  Get the directory.
+    #
+    my $dir = $CONFIG{'theme-dir'};
+
+    #
+    #  XML files go in theme-dir/xml/
+    #
+    if ( $file =~ /\.xml\./i )
+    {
+        $dir .= "/xml/";
+    }
+    else
+    {
+        $dir .= "/" . $CONFIG{'theme'} . "/";
+    }
+
+
+    #
     #  Make sure the file exists.
     #
-    if ( ! -e $CONFIG{'template'} . "/" . $file )
+    if ( ! -e $dir . $file )
     {
         print <<EOF;
 
-  The template file $file was not found in our template directory
- of $CONFIG{'template'}.
+  The template file $file was not found in the theme directory.
+
+  Theme          :  $CONFIG{'theme'}
+  Theme Directory: $CONFIG{'theme-dir'}
+
+  We expected to find $dir$file;
 
   Aborting.
 EOF
@@ -1522,7 +1562,7 @@
     }
 
     my $t = HTML::Template->new( filename          => $file,
-                                 path              => $CONFIG{'template'},
+                                 path              => $dir,
                                  loop_context_vars => 1,
                                  global_vars       => 1,
                                  %params );
@@ -1649,6 +1689,77 @@
 
 =begin doc
 
+  Sanity check our arguments:
+
+  1.  Make sure we have a theme-directory
+
+  2.  Make sure we have a theme.
+
+=end doc
+
+=cut
+
+sub sanityCheckArguments
+{
+    if ( !$CONFIG{'theme-dir'} )
+    {
+        print <<EOF;
+
+  Error - You don't have a theme directory setup.
+
+  Please specify --theme-dir=/some/path, or add this to your configuration
+ file:
+
+theme-dir = /path/to/use/
+EOF
+
+        exit;
+    }
+
+    if ( ! -d $CONFIG{'theme-dir'} )
+    {
+        print "The theme directory you specified doesn't exist:\n";
+        print "\t" . $CONFIG{'theme-dir'} . "\n";
+        exit;
+    }
+
+    if ( !$CONFIG{'theme'} )
+    {
+        print <<EOF;
+
+  You've not specified a theme.
+
+  Please specify --theme=xx
+
+  Or add this to your configuration file:
+
+theme = xx
+
+
+  [You may list themes with --list-themes]
+
+EOF
+
+        exit;
+    }
+
+
+    if ( ! -d $CONFIG{'theme-dir'} . "/" . $CONFIG{'theme'} )
+    {
+        print "The theme directory you specified doesn't exist in the theme directory:\n";
+        print "\tTheme    :" . $CONFIG{'theme'}     . "\n";
+        print "\tTheme dir:" . $CONFIG{'theme-dir'} . "\n";
+        print "\tExpected :" . $CONFIG{'theme-dir'} . "/" . $CONFIG{'theme'} . "\n";
+        exit;
+    }
+
+}
+
+
+
+
+=begin doc
+
   Copy any static files from the theme directory into the "live" location
  in the output.
 
@@ -1665,7 +1776,7 @@
     #
     #  Soure and destination for the copy
     #
-    my $input  = $CONFIG{'template'};
+    my $input  = $CONFIG{'theme-dir'} . "/" . $CONFIG{'theme'};
     my $output = $CONFIG{'output'};
 
     foreach my $pattern ( qw! *.css *.jpg *.gif *.png *.js *.ico ! )
@@ -1777,3 +1888,21 @@
 
 
 
+sub listThemes
+{
+    my( $dir ) = ( @_ );
+
+    $CONFIG{'verbose'} && print "Listhing themes beneath : $dir\n";
+
+    foreach my $name ( sort( glob( $dir . "/*" ) ) )
+    {
+        next unless( -d $name );
+
+        next if ( $name =~ /\/xml$/ );
+
+        if ( $name =~ /^(.*)\/([^\/\\]*)$/ )
+        {
+            print $2 . "\n";
+        }
+    }
+}
--- a/etc/chroniclerc	Wed Oct 31 00:10:39 2007 +0000
+++ b/etc/chroniclerc	Sat Nov 10 00:01:04 2007 +0000
@@ -40,9 +40,14 @@
 
 
 #
-#  Directory containing the templates
+#  Directory containing the theme subdirectories.
 #
-template = /usr/share/chronicle/themes/default
+theme-dir = /usr/share/chronicle/themes
+
+#
+#  The theme to use.
+#
+theme = default
 
 
 #
--- a/themes/blocky/index.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Blog Entries</title>
-		<description>Blog Entries</description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/blocky/month.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></title>
-		<description>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/blocky/tags.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></title>
-		<description>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/copyrighteous/index.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Blog Entries</title>
-		<description>Blog Entries</description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/copyrighteous/month.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></title>
-		<description>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/copyrighteous/tags.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></title>
-		<description>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/default/index.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Blog Entries</title>
-		<description>Blog Entries</description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/default/month.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></title>
-		<description>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- a/themes/default/tags.xml.template	Wed Oct 31 00:10:39 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
-	<channel>
-		<title>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></title>
-		<description>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></description>
-
-	<!-- tmpl_loop name="entries" -->
-	<item>
-		<title><!-- tmpl_var name="title" escape='html' --></title>
-		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
-		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
-		<description><!-- tmpl_var name="body" escape='html' --></description>
-	</item>
-	<!-- /tmpl_loop -->
-        </channel>
-</rss>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themes/xml/index.xml.template	Sat Nov 10 00:01:04 2007 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
+	<channel>
+		<title>Blog Entries</title>
+		<description>Blog Entries</description>
+
+	<!-- tmpl_loop name="entries" -->
+	<item>
+		<title><!-- tmpl_var name="title" escape='html' --></title>
+		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
+		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
+		<description><!-- tmpl_var name="body" escape='html' --></description>
+	</item>
+	<!-- /tmpl_loop -->
+        </channel>
+</rss>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themes/xml/month.xml.template	Sat Nov 10 00:01:04 2007 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
+	<channel>
+		<title>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></title>
+		<description>Entries from <!-- tmpl_var name='month_name' --> <!-- tmpl_var name='year' --></description>
+
+	<!-- tmpl_loop name="entries" -->
+	<item>
+		<title><!-- tmpl_var name="title" escape='html' --></title>
+		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
+		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
+		<description><!-- tmpl_var name="body" escape='html' --></description>
+	</item>
+	<!-- /tmpl_loop -->
+        </channel>
+</rss>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themes/xml/tags.xml.template	Sat Nov 10 00:01:04 2007 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
+	<channel>
+		<title>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></title>
+		<description>Entries tagged <!-- tmpl_var name='tagname' escape='html' --></description>
+
+	<!-- tmpl_loop name="entries" -->
+	<item>
+		<title><!-- tmpl_var name="title" escape='html' --></title>
+		<link><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></link>        
+		<guid isPermaLink="true"><!-- tmpl_var name='top' --><!-- tmpl_var name='link' --></guid>
+		<description><!-- tmpl_var name="body" escape='html' --></description>
+	</item>
+	<!-- /tmpl_loop -->
+        </channel>
+</rss>