By now we have simple and functional admin interface for extension management. Let’s go beyond basics, how about default settings page that extension writers can take advantage of? Let me explain what I mean. Suppose, you wrote BBCode extension (hope Mads won’t be mad at me:). It let people use XHTML in their comments without compromising security. The way it works: you define a square bracket syntax that people can use and extension converts it into real markup on comment serve. This is what code looks like:

Parse(ref body, "b", "strong");
Parse(ref body, "i", "em");
Parse(ref body, "u", "span style=\"text-decoration:underline\"", "span");
Parse(ref body, "quote", "cite title=\"Quote\"", "cite");

If you need to add or remove things that people can use in their comments, you can go and modify these lines, adding or removing stuff. How many of you done so? Anybody? Well, it’s kind of a pain – especially when we talking hosting environment. This is a lot easier with extension like QuickLinks which comes with admin page:

But then, it is a pain for extension writer to implement admin page for simple extension. It will likely require more effort to do this than write actual extension. What if we put Extension Manager in charge of heavy lifting and let him manage settings? So, instead of implementing its own admin page, BBCode would have to:

1. Declare settings as dictionary object.
2. Try to load settings from cache (manager is responsible for populating it).
3. If cache is empty, load dictionary with default values and cache it.

private Dictionary<string, string[]> Settings
{
    get {
        Dictionary<string, string[]> s = new Dictionary<string, string[]>();
        if (HttpContext.Current.Cache["x:BBCode"] != null) {
            s = (Dictionary<string, string[]>)HttpContext.Current.Cache["x:BBCode"];
        }
        else {
            s.Add("b", new string[1]{"strong"});
            s.Add("i", new string[1] {"em" });
            s.Add("u", new string[2] {"span style=\"text-decoration:underline\"", "span"});
            s.Add("quote", new string[2] { "cite title=\"Quote\"", "cite" });
            HttpContext.Current.Cache["x:BBCode"] = s;
        }
        return s;
    }
}

Use this dictionary object in your extension instead of hard-coded values.

private void Post_CommentServing(object sender, ServingEventArgs e)
{
    string body = e.Body;
    foreach (string key in Settings.Keys) {
        string[] s = Settings[key];
 
        if(s.Length == 2)
            Parse(ref body, key, s[0], s[1]);
        else
            Parse(ref body, key, s[0]);
    }
    e.Body = body;
}

Extension and Manager communicate through the cache using common convention: cache key should be named as “x:extensionname” and must contain a dictionary object. If this is true, extension and manager have shared storage and can use it to pass dada to each other. This way you don’t have to implement your own admin interface (which over time probably would require admin panel re-design to handle many more additional tabs) and all extension admin pages are neatly lined up under common UI and easy to use. Everybody wins!

Signature

Related posts

Comments

12/4/2007 4:27:01 AM

Very nice. I will edit my Quick Links and Quicker Links extension to use this method.

Are you using the new snaplinks extension on your site to get that affect?

CK

12/4/2007 4:42:06 AM

I set up direct SnapShots account while ago and did not look at snaplinks yet; I might use it later, especially if it gives extra functionality. As for Extension Manager, you can absolutely modify your extensions to get ready for it right now. My plan is to make it downloadable as "beta" at the end of this week and "go live" some time next week.

rtur.net

12/6/2007 11:30:41 AM

Hey I was wondering if you were going to release the Extension Manager? It looks like it's a cool idea so far. Keep playing with BE though, I am so far and I like it!

Justin Wendlandt

12/6/2007 12:01:47 PM

I've sent code to Mads, and it looks like he liked it. Extension Manager just might become a part of upcoming BE 1.2.5 distribution. I'll keep you guys posted.

rtur.net

12/6/2007 12:19:08 PM

Would appreciate it emailed to me if you wouldn't mind. Want to check it out so I can get my extensions compatible.

ck

ck

12/7/2007 9:39:27 AM

This looks awesome. I'll be excited to see this released with 1.3

Al Nyveldt

Add comment


 

  Country flag

biuquoteimg
Loading



<<  July 2008  >>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Enhanced with Snapshots

Subscribe to Rtur.net