viewing source w/ exyus

2008-01-25 @ 22:20#

had some fun this evening (again). this time i added a simple "viewsource" tool to the exyus engine. now it's easy to build URLs that can display source code files safely for a browser.

it's pretty simple, really, i wrote a new class based on HTTPResource that forces the return content-type to text/plain (and throws 416 if the client can't support that) and then echoes the file to the client. you can check out the checked in source for thePlainTextViewer.cs for details.

i used this new base-class resource to create an instance that handles just the source files for the TaskList project. the instance class looks like this:

using System;
using System.Web;
using Exyus.Web;

// 2008-01-25 (mca)
namespace Exyus.Samples
{
    // echo source code files to browser in plain text
    [UriPattern(@"/tasklist/source/(?:\.xcs)(?:.*)?")]
    [MediaTypes("text/plain")]
    class TaskListSource : PlainTextViewer
    {
        public TaskListSource()
        {
            this.MaxAge = 600;
            this.UseValidationCaching = true;

            this.Files.Add("file1.cs", "/path/to/file/file1.cs");
            this.Files.Add("file2.css", "/path/to/file/file2.css");
            this.Files.Add("file3.js", "/path/to/file/file3.js");
            this.Files.Add("file4.xsl", "/path/to/file/file4.xsl");
        }

    }
}

you can check out the *live* TaskList Source Viewer , too.!

code