unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Neil Jerram" <neiljerram@googlemail.com>
To: "Sebastian Tennant" <sebyte@smolny.plus.com>
Cc: guile-user@gnu.org
Subject: Re: scheme -> (X)HTML
Date: Mon, 16 Jun 2008 22:15:28 +0100	[thread overview]
Message-ID: <49dd78620806161415u4be464a9g410073b55b581b51@mail.gmail.com> (raw)
In-Reply-To: <3anht5tp.fsf@vps203.linuxvps.org>

2008/6/13 Sebastian Tennant <sebyte@smolny.plus.com>:
> Neil Jerram <neil@ossau.uklinux.net> writes:
>> As a further option, please see attached [template.scm].  If you're
>> interested in this, please let me know, because I may have a more up
>> to date version somewhere.
>
> I'd be interested in getting hold of the latest version of
> template.scm as it does exactly what I need for my Guile CGI scripting
> projects.

OK, I've checked now, and it appears that the code already posted is
the most up to date that I have.

> Also, how to use the process-template macro?
>
> Having created the file version.html which reads:
>
>  <html>
>   <p>This page was processed by Guile $(display (version))$</p>
>  </html>
>
> I can get the desired result in a REPL using primitive-eval:
[...]
> or, better still, using eval-string:
[...]
> but using the process-template macro (with a variable list and module
> requirement) produces an error:
>
>  guile> (process-template "/path/to/version.html" ((foo 'bar)) (ice-9 rdelim))
>
>  Backtrace:
>  In standard input:
>    39: 0* (process-template "/path/to/version.html" ((foo (quote bar))) ...)
>    39: 1  (let* ((module #)) (module-define! module (quote foo) ...) ...)
>  In unknown file:
>     ?: 2  [eval (begin # # # ...) #<module b7cca530>]
>     1: 3* (begin # # # ...)
>
>  <unnamed port>:1:1: In expression (begin (display "<html>
>  ") (display "  <p>This page was processed by Guile ") ...):
>  <unnamed port>:1:1: Unbound variable: begin
>  ABORT: (unbound-variable)

The process-template call is just slightly wrong; it just needs to
mention the (guile) module also:

   (process-template "/path/to/version.html" ((foo 'bar)) (guile)
(ice-9 rdelim))

The (guile) module contains Guile's core bindings, including `begin'.

(Possibly process-template could add (guile) automatically, but the
implementation as it stands allows for greater precision.)

> Would it not suffice to evaluate the template code in the environment
> of the CGI script, i.e., with all the modules loaded and required
> variables defined in the script before
>
>  (eval-string (template-code "/path/to/more-complex-template.html"))
>
> is called?

Interesting idea.  I didn't provide that option before, because it
wasn't helpful in the context of the program for which I wrote (ossau
template), but you can easily define another API, say `eval-template',
which does this:

(define (eval-template template . module)
  (eval (with-input-from-string (template->code template) read)
        (if (null? module) (current-module) (car module))))

Then the call would be just (eval-template
"/path/to/more-complex-template.html").

(The thing with process-template is that it allows additional variable
bindings to be set up for just that process-template call, and one
wouldn't (I think) want those bindings to persist in the whatever is
the reference module for the template code.  So process-template
currently creates a temporary module, using make-module, to avoid
this.  But this is not cast in stone; perhaps process-template should
use a surrounding `let' form instead to set up the bindings, or
perhaps it would be better for the template file to begin with

$(use-modules (ice-9 rdelim))$

instead of having (ice-9 rdelim) in the process-template call.  I'm not sure.)

> Could you perhaps provide a simple example usage of process-template?

I do have more examples, but I think this is probably already covered
above; let me know if not.

Regards,
        Neil




  reply	other threads:[~2008-06-16 21:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-25 19:37 scheme -> (X)HTML Paul Emsley
2008-03-25 19:53 ` Julian Graham
2008-03-25 20:38   ` Neil Jerram
2008-06-13 20:53     ` Sebastian Tennant
2008-06-16 21:15       ` Neil Jerram [this message]
2008-06-21  9:11         ` Sebastian Tennant
2008-07-03 22:32           ` Neil Jerram
2008-03-31 16:41   ` Paul Emsley
2008-03-31 20:33     ` Francesco Salvestrini
2008-04-02 11:42       ` Thien-Thi Nguyen
2008-03-25 20:49 ` Francesco Salvestrini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49dd78620806161415u4be464a9g410073b55b581b51@mail.gmail.com \
    --to=neiljerram@googlemail.com \
    --cc=guile-user@gnu.org \
    --cc=sebyte@smolny.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).