Hello plugin
Projects...   
Hello plugin   
[10-12-2004]

 

dsoHelloMod

hello.cc is an example plugin for hitoplive. It's intended to show how to add a trivial new tag to hitoplive's markup language. I hope you'll forgive me if I don't explain it much - documention is a little sparse in these parts. This bit is still work-in-progress, so expect b0rkenness.

This version of hello.cc is written for hitop 0.35.
hello.cc is Copyright © Iain Georgeson 2003.
You may redistribute it and/or modify it under the same terms as hitop, substituting my name as the Copyright Holder.

The source to hello.cc is as follows:

#ifndef __htmlstreamh__
  #include "../htmlstream.h"
#endif

#ifndef __htmlh__
  #include "../html.h"
#endif

#ifndef __stringproch__
  #include "../stringproc.h"
#endif

#ifndef __pluginh__
  #include "../plugin.h"
#endif

#ifndef __parammaph__
  #include "../parammap.h"
#endif

#include <string>

class dsoHelloMod :
    public Plugin
{
public:
    dsoHelloMod();
    virtual void Init();
    static HTMLStream::iterator GREET(HTMLStream& stream,
            HTMLStream::iterator Curconst ParamMap& paramMap,
            const stringtag);
};

static dsoHelloMod initmodule;

dsoHelloMod::dsoHelloMod()
{
    RegisterPlugin("hello", 1);
}

void dsoHelloMod::Init()
{
    SetNamespace("HELLO");
    RegisterCommand("GREET", &GREET);
}

HTMLStream::iterator dsoHelloMod::GREET(HTMLStream& stream,
        HTMLStream::iterator Curconst ParamMap& paramMap, const stringtag)
{
    string person;
    if (!paramMap.Retrieve("PERSON", person))
    {
        person = "World";
    }

    // Insert our bit into the stream.
    stream.m_stream.insert(Cur, HTML(false"Hello " + person));

    // This bit appears to be the correct idiom for removing this
    // command from the HTML stream.
    HTMLStream::iterator Next = Cur;
    ++Next;
    stream.m_stream.erase(Cur);
    return Next;
}

(Syntax-highlighting made possible by Hrvoje Niksic's htmlize package for emacs).

The plugin implements a tag "GREET", within a namespace "hello", with one attribute - "PERSON", the recipient of the greeting. It defaults to "World". Use it as follows:

<@REQUIRES PLUGIN="hello">

<@hello.GREET PERSON="Iain">

© 1998-2008 Iain Georgeson