Mason - is this sensible?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

(Also posted to mason-users)


OK - scenario:

I want .html files to be served as complete content, and .page files to be
wrapped with the HTML head stuff, a menu and a footer. The idea is that most
of my content will be .page files, wrapped with a constant set of stuff. But
I can stick a .html file in and know that it will not be wrapped, should I
need to...

ie is only the text content of a single page without any common
stuff, tedious head/html tags and friends etc...

I have a default handler with this in (gets called if the target URI cannot
be resolved by apache):

    # Handle permanant redirects
    $m->redirect('/venuespace.html', 301) if $r->uri() eq

    # OK - there is no target file for the URI
    my $rcompname = $r->uri();
    # Try for a .page component
    $rcompname =~ s/\.html$/\.page/;
    if ($m->comp_exists($rcompname))
    $m->abort(404); # Not found

    html_extra_headers     => '<!-- Wibble -->'
    pagetitle         => 'Robertsbridge'
    footercomment        => '&copy; 2010'
    navid            => ''

So far, for a target exisiting .html, .cgi, .pl etc file, this does not get

If the client asks for /index.html but exists, this subexecs
/ after checking for redirects, and if it fails, aborts with a

OK - now to handle the wrapping of

We have an autohander thus
    # If the request is for a .page component, remapped by default.mas
    if ( $m->request_comp->name() =~ m/\.page$/ )
    # Otherwise, run with the original request

Just for completeness, page.mas looks roughly like, with lots of snippage
for brevity:

<html xmlns=" ">
            <% $m->request_comp->attr('pagetitle') %>

    <% $m->request_comp->attr('html_extra_headers') %>


<body id="<% $m->request_comp->attr('navid') %>">

        <div id="headertext">
            <h1><% $m->request_comp->attr('pagetitle') %></h1>
        </div> <!--headertext-->
# Here we incorporate the component: #
    <% $m->call_next %>

            <& /_mason/main_menu.mas &>

<p id="footer-author"><% $m->request_comp->attr('footercomment') %></p>



Obviously there's loads of div blocks and other stuff in there, but you see
the general execution flow...

Does that look reasonably sane? If so, it means I "get" Mason. If not,
well.. But I can say that it seems to function in reality.

Thanks for any comments :)



Tim Watts

Managers, politicians and environmentalists: Nature's carbon buffer.

Site Timeline