[Journal - Creating Web Articles]

Creating Web Articles

Sunday, September 4, 2005

Today, I'll give a little insight into how I create my web site articles, Journal entries mainly, using WebEdit.NET. The focus is on template-based editing, with the help of the code interpreter.

I have a template like this:

<html>

<head>

<!-- $clearTemplateParams()% -->
<!-- $getTemplateFileBase()% -->

<title>$getTemplateTitle()%</title>

</head>


<body bgcolor="white">

<h1>$getTemplateTitle()%</h1>

<p style="text-align: right;">
$getTemplateDateText()%
</p>

<p>
Article goes here ...
</p>

</body>

</html>

WebEdit.NET, when it opens a file like this as a template, prompts me with the parameter dialog, into which I can enter strings. However, wouldn't it be a little easier if I had a custom dialog that:

So, I wrote a little dialog function and assorted helpers in WebEdit's code interpreter. Here's the code:

clearTemplateParams()
{
    sName = "TemplateParams";
    if(Vars.ExistsValue(sName)){
        Vars.RemoveValue(sName);
    }
    "OK";
}

getTemplateTitle()
{
    getTemplateParams().GetProperty("Title")
}

getTemplateDateText()
{
    getTemplateParams().GetProperty("DateText")
}

getTemplateFileBase()
{
    getTemplateParams().GetProperty("FileBase")
}

getTemplateParams()
{
    ret = null;
    sName = "TemplateParams";
    if(Vars.ExistsValue(sName)){
        ret = Vars.GetValue(sName);
    }else{
        sCaption = "Blog Entry Paramters";
        sDescription = "Choose title, publication date, and file base:";
        frm = new Gregor.UICore.Dialogs.FMultiInput(sCaption, sDescription);
        txtTitle = frm.AddTextBox(string.Empty);
        mc = frm.AddMonthCalendar(DateTime.Now);
        txtFileBase = frm.AddTextBox(DateTime.Now.ToString("yyyyMMdd"));
        handleDateChanged(sender, e){
            txtFileBase.Text = mc.SelectionStart.ToString("yyyyMMdd");
        }
        UserHandler.Add(mc, "DateChanged", handleDateChanged);
        if(frm.ShowDialog(WebEditApp.MainForm).Equals(DialogResult.OK)){
            ToString(){
                string.Concat("TemplateParams for: ", this.GetProperty("Title"));
            }
            ret = UserObject.Create(ToString);
            ret.AddProperty("Title", txtTitle.Text);
            pubDate = mc.SelectionStart;
            cult = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            ret.AddProperty("DateText", pubDate.ToString("dddd, MMMM d, yyyy", cult));
            ret.AddProperty("FileBase", txtFileBase.Text);
            Vars.SetValue(sName, ret);
        }
        UserHandler.Remove(mc, "DateChanged", handleDateChanged);
    }
    ret;
}

The whole architecture (cough!) has the following features:

To use the template, follow these steps: