chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] egg update: hart 1.1.2


From: Graham Fawcett
Subject: [Chicken-users] egg update: hart 1.1.2
Date: Wed, 6 Feb 2008 15:54:14 -0500

Hi folks,

I've just committed a new release (1.1.2) of the 'hart'
HTML-generation egg on the release/3 branch. The egg itself
should be available the next time the egg-post-commit job runs.

This is a bugfix release to correct an error in the evaluation of
attribute expressions. For example, in the expression:

(hart (a (@ (href (some-proc))) ...))

...the expression (some-proc) was being evaluated twice. This has
now been corrected.

The reason for evaluating twice in the first place was to allow
for optional attributes: if (some-proc) evaluated to #f, then the
'href' attribute would be omitted from the output. E.g.:

(let ((maybe-link (lambda () #f)))
  (hart->string
   (a (@ (href (maybe-link)))
      "foo")))
=>
"<a>foo</a>"

(The optional-attribute behaviour was an undocumented feature.
Ahem, I'll berate my documentation writer for the omission.)

In this new version, you can use the following technique to
generate elements with alternating attributes, e.g.:

(define (make-toggler a b)
  (let ((curr #f))
    (lambda ()
      (set! curr (not curr))
      (if curr a b))))

(hart->string
 (let: ((tog (make-toggler "odd" "even")))
       (for: (n '(1 2 3))
         (li (@ (class (tog))) (text: n)))))
=>
"<li class=\"odd\">1</li><li class=\"even\">2</li><li class=\"odd\">3</li>"

I'll put these examples into the wiki documentation shortly.

This version also includes a much faster html-escaping
routine (written in C). (In common usage, it makes less of an
performance impact than I thought it would, so it's a bit of a
premature optimization.)

Enjoy!
Graham




reply via email to

[Prev in Thread] Current Thread [Next in Thread]