[albatross-users] Two questions (client-side production of static pages)

Andrew McNamara andrewm at object-craft.com.au
Fri Jun 28 10:13:09 EST 2002


I'm actually in the process of using Albatross to create a static web
site also, so hopefully I already have the answers you are looking
for. Mostly, it turns out, Dave has already provided the mechanism we
require (or hooks to make it easier).

>The first question/point: I want to be able to produce output to a
>file, not just stdout (don't want to use redirection as using stdout
>for other purposes).  Now, I've achieved this by patching ExecuteMixin
>and SimpleContext in the following "quick and dirty" manner:
[snip]
>This works for me, but I was wondering:
>
>  - Can anyone think of a better way to achieve this?

You should use the content trap mechamism, for example:

    ctx.push_content_trap()
    tmpl = ctx.load_template(filename)
    tmpl.to_html(ctx)
    ctx.flush_content()
    results = ctx.pop_content_trap()

    f = open(output_file, "w")
    f.write(results)
    f.close()

[snip]
>Now, what I'd _really_ like is to have a number of templates which are
>used to build each page.  In particular, a large chunk of master.html
>is a sidebar table which is rather large: I'd love to be able to break
>that out into a seperate template then bring it in in either
>master.html or better yet, somepage.html (then I could have a choice
>of sidebars for different pages, all of which use the same master).
>
>My instinct tells me there should be a way to do this but I haven't
>been able to find it.  Can anyone clue me in?

Macro's can be nested, but you have to explicitly pass args through -
you can do things like this:

    <al-macro name="sidebar">
     ...
     <al-usearg name="sidebar_arg">
     ...
    </al-macro>

    <al-macro name="master">
     ...
     <al-expand name="sidebar">
      <al-setarg name="sidebar_arg">
       <al-usearg name="master_sidebar_arg" />
      </al-setarg>
     </al-expand>
     ...
    </al-macro>

    <al-expand name="master">
     ...
     <al-setarg name="master_arg">
      ...
     </al-setarg>
     <al-setarg name="master_sidebar_arg">
      ...
     </al-setarg>
     ...
    </al-expand>

Note also that I keep my macros in separate files. My page generation
scheme creates one SimpleContext object that is used by all pages. I
first load the common macro templates, then all the pages: the macros
are recorded by the SimpleContext object and are available to all pages.

Actually, my scheme now goes beyond this - templates in sub-directories
can override those defined higher up (I did this by implementing my
own register_macro and get_macro methods on an object that inherits
from SimpleContext). I'm also overriding the load_template() method and
fiddling with the path on the way through to make <al-include> work more
intuitively with directory heirarchies.

It's still very much a work in progress - but at some point I would like
to make the script available.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list