Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
* config.cs: Add Prefix (base directory for output), BlogTemplate
Browse files Browse the repository at this point in the history
    (previously hardcoded as the "template" file), EntryTemplate properties
    (previously hardcoded as the "entry" file).  Add support for command-line
    handling (used for regression tests).
  * entry.test, template.test: Test input files (used for regression tests).
  * lb.cs:
    - Use new Config fields to control entry & file templates, prefix for
      output directory;
    - Change the RSS publication date to be the latest file time found, not the
      current time (helps make regression tests more consistent, as the
      pubdate won't be changing all the time in the RSS file).
    - Move entry_id handling into DayEntry.Id property (it's used in 2 places).
    - Permit rendering to a TextWriter
    - Don't open/read/close the file template all the time, but cache the file
      in memory (slight performance improvement).
    - Change RenderHtml() to use Translate().  Allows greater code sharing,
      consistency, easily adding new variables for replacement.
    - Add @BLOG_ENTRY_INDEX@ variable, a <ul/> list of all entries in a given
      page.
    - Create a .rss2 file for each category.
  * makefile: Add check and check-update targets.  `check' runs the regression
    tests, while `check-update' updates the expected output.

svn path=/trunk/lb/; revision=55834
  • Loading branch information
Jonathan Pryor committed Jan 20, 2006
1 parent 929c5a7 commit 09a61dc
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 51 deletions.
28 changes: 28 additions & 0 deletions ChangeLog
@@ -1,3 +1,31 @@
2006-01-19 Jonathan Pryor <jonpryor@vt.edu>

* config.cs: Add Prefix (base directory for output), BlogTemplate
(previously hardcoded as the "template" file), EntryTemplate properties
(previously hardcoded as the "entry" file). Add support for command-line
handling (used for regression tests).
* entry.test, template.test: Test input files (used for regression tests).
* lb.cs:
- Use new Config fields to control entry & file templates, prefix for
output directory;
- Change the RSS publication date to be the latest file time found, not the
current time (helps make regression tests more consistent, as the
pubdate won't be changing all the time in the RSS file).
- Move entry_id handling into DayEntry.Id property (it's used in 2 places).
- Permit rendering to a TextWriter
- Don't open/read/close the file template all the time, but cache the file
in memory (slight performance improvement).
- Change RenderHtml() to use Translate(). Allows greater code sharing,
consistency, easily adding new variables for replacement.
- Add @BLOG_ENTRY_INDEX@ variable, a <ul/> list of all entries in a given
page.
- Create a .rss2 file for each category.
* makefile: Add check and check-update targets. `check' runs the regression
tests, while `check-update' updates the expected output.
* test/in/2005/jul-20.txt, test/in/foo/bar/2005/jul-14.html: test input
files for regression tests.
* test/out/**: expected output for regression tests.

2006-01-03 Miguel de Icaza <miguel@novell.com>

* lb.cs: The THML title for individual archive blogs is now set to
Expand Down
107 changes: 107 additions & 0 deletions config.cs
@@ -1,3 +1,4 @@
using System;
using System.Xml.Serialization;

[XmlRoot("config")]
Expand All @@ -16,4 +17,110 @@ public class Config {
[XmlAttribute] public string InputEncoding;
[XmlAttribute] public string OutputEncoding;
[XmlAttribute] public string AnalyticsStub;
[XmlAttribute] public string Prefix;
[XmlAttribute] public string BlogTemplate;
[XmlAttribute] public string EntryTemplate;

public bool Parse (string[] args)
{
for (int i = 0; i < args.Length; ++i) {
string arg = args [i];
switch (arg) {
case "-h": case "--help":
PrintHelp ();
return false;
case "-p": case "--prefix":
if (NextArgument (args, ref i, ref Prefix))
break;
return false;
case "-d": case "--blog-directory":
if (NextArgument (args, ref i, ref BlogDirectory))
break;
return false;
case "-b": case "--blog-template":
if (NextArgument (args, ref i, ref BlogTemplate))
break;
return false;
case "-e": case "--entry-template":
if (NextArgument (args, ref i, ref EntryTemplate))
break;
return false;
case "-x": case "--rss-filename":
if (NextArgument (args, ref i, ref RSSFileName))
break;
return false;
default:
if (ExtractArgument ("-p", arg, ref Prefix))
break;
if (ExtractArgument ("--prefix", arg, ref Prefix))
break;
if (ExtractArgument ("-b", arg, ref BlogTemplate))
break;
if (ExtractArgument ("--blog-template", arg, ref BlogTemplate))
break;
if (ExtractArgument ("-e", arg, ref EntryTemplate))
break;
if (ExtractArgument ("--entry-template", arg, ref EntryTemplate))
break;
if (ExtractArgument ("-d", arg, ref BlogDirectory))
break;
if (ExtractArgument ("--blog-directory", arg, ref BlogDirectory))
break;
if (ExtractArgument ("-x", arg, ref RSSFileName))
break;
if (ExtractArgument ("--rss-filename", arg, ref RSSFileName))
break;
Error ("unrecognized option `{0}'", arg);
return false;
}
}
return true;
}

private static void PrintHelp ()
{
Console.WriteLine ("Usage: lb [OPTION]*");
Console.WriteLine ("lb (Lame Blog) is a blog engine.");
Console.WriteLine (@"
Options:
-p, --prefix=DIR Root directory for generated files.
-d, --blog-directory=DIR Where to find blog entry files (*.txt, *.html).
-b, --blog-template=FILE Blog template file .
-e, --entry-template=FILE Entry template file.
-x, --rss-filename=FILE Basename for RSS filename.
-h, --help Display this message and exit.
");
}

private void Error (string format, params object[] args)
{
Console.Write ("lb: ");
Console.WriteLine (format, args);
Console.WriteLine ("Try `lb --help' for more information.");
}

private bool ExtractArgument (string prefix, string argument, ref string value)
{
if (argument.Length - 1 <= prefix.Length)
return false;
if (!argument.StartsWith (prefix))
return false;

char delim = argument [prefix.Length];
if (delim != '=' && delim != ':')
return false;

value = argument.Substring (prefix.Length+1);
return true;
}

private bool NextArgument (string[] args, ref int i, ref string value)
{
if ((i+1) >= args.Length) {
Error ("missing argument for `{0}'", args [i]);
return false;
}
value = args [++i];
return true;
}
}
30 changes: 30 additions & 0 deletions entry.test
@@ -0,0 +1,30 @@
<p>@ENTRY_NAVIGATION@</p>
<h2 id="@ENTRY_ID@" name="@ENTRY_ANCHOR@">@ENTRY_CAPTION</h2>
@ENTRY_BODY@
<hr>
<p>Test Variables:</p>
<dl>
<dt>\@BASEDIR\@:</dt>
<dd>@BASEDIR@</dd>
<dt>\@COPYRIGHT\@:</dt>
<dd>@COPYRIGHT@</dd>
<dt>\@ENTRY_ANCHOR\@:</dt>
<dd>@ENTRY_ANCHOR@</dd>
<dt>\@ENTRY_CAPTION\@:</dt>
<dd>@ENTRY_CAPTION@</dd>
<dt>\@ENTRY_CATEGORY\@:</dt>
<dd>@ENTRY_CATEGORY@</dd>
<dt>\@ENTRY_CATEGORY_PATHS\@:</dt>
<dd>@ENTRY_CATEGORY_PATHS@</dd>
<dt>\@ENTRY_DATECAPTION\@:</dt>
<dd>@ENTRY_DATECAPTION@</dd>
<dt>\@ENTRY_ID\@:</dt>
<dd>@ENTRY_ID@</dd>
<dt>\@ENTRY_NAVIGATION\@:</dt>
<dd>@ENTRY_NAVIGATION@</dd>
<dt>\@ENTRY_PATH\@:</dt>
<dd>@ENTRY_PATH@</dd>
<dt>\@ENTRY_PERMALINK\@:</dt>
<dd>@ENTRY_PERMALINK@</dd>
</dl>

0 comments on commit 09a61dc

Please sign in to comment.