Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

Similar things

  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • scheming away
  • still scheming away
  • Relations and their domain structures
  • Learning lessons from Lisp or patterns and languages in PHP
  • a sample testsuite for the (any/type) base types
  • An exercise with continuations, prompts and scheme macros
  • Lisp without Parenthesis
  • macro processor - initial notes

guild
Home » blogs » vlado's blog

scheming templates

Submitted by vlado on Tue, 2006-01-31 11:09.articles | code | lisp | programming | scheme | webdesign

I'm intrigued. You might have noticed that I like Lisp. Itellectually, that is. I don't really speak it. I finally decided to dive and try and learn it. On the surface it is not that hard - the language is extremely simple, essentially it has brackets and white space as separators, a couple of special forms - something like built in functions or language constructs in other language terminology, and a few really cool features like quote, unquote, quasiquote, (precious special forms actually), oh, yes, it has an eval.

In order to go forward with the learning I shall try and implement a simple web-design friendly template for xml applications. The idea is similar to TAL, or taglibs, etc...

Problem

A template is a valid xml document with namespaces. Some, not all, namespaces have programmatic meaning, that is they should be interpreted by an application. A template engine should be able to read an xml document and execute those statements encoded in xml.

Example

an XML source fragment

<cms:node-content>
  <div>
    <cms:node-title>
      <h3><a cms:node-title-link="relative" >
          <cms:node-title-text >
Sed ut perspiciatis unde omnis iste natus error sit
voluptatem accusantium doloremque laudantium, totam 
rem aperiam, eaque ipsa quae ab illo inventore veri-
tatis et quasi architecto beatae vitae dicta sunt 
explicabo. 
          </cms:node-title-text >
          </a>
      </h3>
    .....
  </div>
</cms:node-content>

This should execute cms:node-content, cms:node-title, cms:node-title-link and cms-node-title-text, which in turn perform some action. Each of the cms:* functions should know the xml context from which they are called. They might transform the underlying xml or be completely silent, being used for their side-effects.

A first draft of a scheme representation

(div 
  (cms:node-title
    (h3
      (a (cms:node-title-text Sed ut perspiciatis...)
         (@ (cms:node-title-link "relative")
      )
    )
  )
)

In the above code I presume that all namespace tags have corresponding scheme functions defined. This code is a rough, simplified approximation of SXML produced s-expressions. The key is that the s-expressions should be evaluateable scheme constructs. This code might evaluate to:

<div class="node-content>
  <h3><a href="Cicero/-45/de_Finibus_Bonorum_et_Malorum" 
     title="Cicero, de Finibus Bonorum et Malorum">
     Section 1.10.32 of "de Finibus Bonorum et Malorum",
     written by Cicero in 45 BC</a>
  </h3>
  .....
</div>

The source XML fragment for all practical purposes defines a template. The idea is that a web-designer will provide a solid xhtml design, possibly with the added markup. The html file is an example rendering of that particular page, which can be filled in by a server side software. This approach is a useful double sword - designer friendly and enables programming by example, i.e a collection (union) of example renderings with the appropriate add-on markup, can be joined into a more complex, context dependent template.

Markup variation

  • passtrough form - outputs its contents or doesn't modufy the program - structural html markup
  • substitution form - replaces it's occurence with something else, higjer level markup - for example various widgets
  • silent side-effects form - you won't guess what it is doing, by simply viewing the program/xml file, for example various counters, etc...
  • substitutions with sideeffects, update the db, display the results

The above should describe what forms are needed for a decent template system.

What now?

Well, I need to dig deep and try and produce a solution, which does somethin g like this. I'll give myself a bonus point for making it simple. Another bonus point for me would be for a slim solution, this bonus point will be awarded only if the solution is readable.

vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970