* scheme -> (X)HTML
@ 2008-03-25 19:37 Paul Emsley
2008-03-25 19:53 ` Julian Graham
2008-03-25 20:49 ` Francesco Salvestrini
0 siblings, 2 replies; 11+ messages in thread
From: Paul Emsley @ 2008-03-25 19:37 UTC (permalink / raw
To: guile-user
Dear Guilers,
I have in mind to write a little script that makes a web page about the state of
various files.
I'd like to use some schemey way of doing this. s-expression -> HTML perhaps.
What is the thinking guile-user's way of approaching this?
Cheers,
Paul.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
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-03-31 16:41 ` Paul Emsley
2008-03-25 20:49 ` Francesco Salvestrini
1 sibling, 2 replies; 11+ messages in thread
From: Julian Graham @ 2008-03-25 19:53 UTC (permalink / raw
To: Paul Emsley; +Cc: guile-user
Hi Paul,
There are several good tools out there for doing this: Oleg Kiselyov
has written a Scheme-based port of SAX called SSAX [1] that can read
and emit S-expressions in a format he calls SXML. It's available for
Guile as part of Andy Wingo's guile-lib [2]. For permissive HTML
parsing, Neil Van Dyke has written HtmlPrag [3]. And if you're
interested in a more DOM-based approach, I've got a module called SDOM
[4].
Hope that helps!
Regards,
Julian
[1]: http://okmij.org/ftp/Scheme/SXML.html
[2]: http://home.gna.org/guile-lib/
[3]: http://www.neilvandyke.org/htmlprag/
[4]: http://www.nongnu.org/sdom/
On Tue, Mar 25, 2008 at 3:37 PM, Paul Emsley <paul.emsley@bioch.ox.ac.uk> wrote:
>
> Dear Guilers,
>
> I have in mind to write a little script that makes a web page about the state of
> various files.
>
> I'd like to use some schemey way of doing this. s-expression -> HTML perhaps.
>
> What is the thinking guile-user's way of approaching this?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-25 19:53 ` Julian Graham
@ 2008-03-25 20:38 ` Neil Jerram
2008-06-13 20:53 ` Sebastian Tennant
2008-03-31 16:41 ` Paul Emsley
1 sibling, 1 reply; 11+ messages in thread
From: Neil Jerram @ 2008-03-25 20:38 UTC (permalink / raw
To: Paul Emsley; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 663 bytes --]
"Julian Graham" <joolean@gmail.com> writes:
> Hi Paul,
>
> There are several good tools out there for doing this: Oleg Kiselyov
> has written a Scheme-based port of SAX called SSAX [1] that can read
> and emit S-expressions in a format he calls SXML. It's available for
> Guile as part of Andy Wingo's guile-lib [2]. For permissive HTML
> parsing, Neil Van Dyke has written HtmlPrag [3]. And if you're
> interested in a more DOM-based approach, I've got a module called SDOM
> [4].
As a further option, please see the attached. If you're interested in
this, please let me know, because I may have a more up to date version
somewhere.
Regards,
Neil
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: template.scm --]
[-- Type: text/x-scheme, Size: 13401 bytes --]
;;;; (ossau template) -- template file processor
;;; Copyright (C) 2005 Neil Jerram
;;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 2.1 of the License, or (at your option) any later version.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(define-module (ossau template)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
#:export (template->code)
#:export-syntax (process-template))
;*****************************************************************************;
;* A template file is a file of content, such as HTML, that is complete *;
;* except for places where the content needs to be filled in *;
;* programmatically. In the case of the template processor code here, the *;
;* code to fill in the dynamic content is written in Scheme and appears *;
;* inline in the template file. *;
;* *;
;* Areas of Scheme code in the template file are delimited by $. For *;
;* example: *;
;* *;
;* <I>This page was processed by Guile $(display (version))$</I> *;
;* *;
;* here (display (version)) is interpreted and processed as Scheme code; *;
;* the rest is normal (HTML) content. *;
;* *;
;* If either normal content or Scheme code needs to include a $ character, *;
;* it can do so by doubling the $, as in: Price $$10.20. *;
;* *;
;* Fragments of Scheme code do not have to be individually balanced. For *;
;* example: *;
;* *;
;* $(for-each (lambda (x)$ *;
;* <LI>The square of $(display x)$ is $(display (* x x))$</LI> *;
;* $ ) (iota 11))$ *;
;* *;
;* A shorthand is provided for cases where a fragment only wants to display *;
;* a variable. This is $~FORMAT VARNAME$, for example $~A x$. ~FORMAT is a *;
;* format specifier understood by (ice-9 format), and VARNAME is the name of *;
;* the variable to display. *;
;* *;
;* It may sometimes help to know the exact algorithm in order to write a *;
;* piece of template file code correctly. It is as follows. *;
;* *;
;* 1. Convert the template file - even the normal content - into a big *;
;* Scheme code string by: *;
;* *;
;* - converting each fragment of normal content to `(display FRAGMENT)' *;
;* *;
;* - converting each `~FORMAT VARNAME' fragment to *;
;* `(format #t ~FORMAT VARNAME)' *;
;* *;
;* - copying other Scheme code fragments as written. *;
;* *;
;* 2. Read and evaluate this string in an environment as specified by the *;
;* arguments to process-template. *;
;* *;
;*****************************************************************************;
;*****************************************************************************;
;* template->code *;
;* *;
;* Reads a template file and returns the Scheme code that should be read and *;
;* evaluated to generate the implied output. *;
;*****************************************************************************;
(define (template->code template)
;***************************************************************************;
;* Utility procedure: convert any occurrences of "$$" in STRING to just *;
;* "$". *;
;***************************************************************************;
(define (unescape-$$ string)
(cond ((string-match "\\$\\$" string)
=>
(lambda (match-data)
(string-append (substring string 0 (match:start match-data 0))
"$"
(unescape-$$ (substring string
(+ (match:start match-data
0)
1))))))
(else string)))
;***************************************************************************;
;* Utility procedure: given a string read from the template file, after *;
;* splitting between scheme and non-scheme parts, return the Scheme code *;
;* corresponding to the template string. *;
;***************************************************************************;
(define (make-code-string template-string in-scheme)
(if in-scheme
;*********************************************************************;
;* Template string should be interpreted as Scheme code. If it *;
;* begins with "~", it is a shorthand for a format expression; *;
;* otherwise, it is straight Scheme code and doesn't need any *;
;* further tweaking. *;
;*********************************************************************;
(cond ((string-match "^~[^ ]+ " template-string)
=>
(lambda (match-data)
(let ((beg (match:start match-data 0))
(end (match:end match-data 0)))
(format #f
"(format #t ~S ~A)"
(substring template-string beg (- end 1))
(substring template-string end)))))
(else template-string))
;*********************************************************************;
;* Template string is normal file content (i.e. outside Scheme *;
;* code). The corresponding Scheme code should display it. *;
;*********************************************************************;
(format #f "(display ~S)" template-string)))
;***************************************************************************;
;* Main procedure code. *;
;***************************************************************************;
(with-input-from-file template
(lambda ()
;***********************************************************************;
;* Loop reading lines from the template file. *;
;***********************************************************************;
(let loop ((template-line (read-line (current-input-port) 'concat))
(in-scheme #f)
(strings '()))
(if (eof-object? template-line)
;*****************************************************************;
;* EOF: return the concatenated Scheme code string. *;
;*****************************************************************;
; (let ((code
(string-append "(begin "
(apply string-append
(reverse strings))
")")
; ))
; (with-output-to-file "template-debug.scm"
; (lambda ()
; (display code)))
; code)
;*****************************************************************;
;* Not yet EOF: normal processing. First check for single "$"; *;
;* these mark the boundaries between Scheme code and normal *;
;* (non-Scheme) file content. *;
;*****************************************************************;
(cond ((string-match "(^|[^$])(\\$)($|[^$])" template-line)
=>
;**********************************************************;
;* Found a single "$", so process the part of the line *;
;* before the "$", then toggle the in-scheme flag and *;
;* loop to process the rest of the line. *;
;**********************************************************;
(lambda (match-data)
(let (($pos (match:start match-data 2)))
(loop (let ((rest (substring template-line (+ $pos 1))))
(if (<= (string-length rest) 1)
(read-line (current-input-port) 'concat)
rest))
(not in-scheme)
(cons (make-code-string (unescape-$$
(substring template-line
0
$pos))
in-scheme)
strings)))))
;***********************************************************;
;* No "$" in this line, so process whole line and loop to *;
;* read the next line. *;
;***********************************************************;
(else
(loop (read-line (current-input-port) 'concat)
in-scheme
(cons (make-code-string (unescape-$$ template-line)
in-scheme)
strings)))))))))
;*****************************************************************************;
;* process-template *;
;* *;
;* Processes a template file, with the generated output going to the current *;
;* output port. Returns unspecified. *;
;* *;
;* Args are: template - Name of template file. *;
;* vars - Variables to define for the Scheme code in the *;
;* template file, in the same form as a set of let *;
;* bindings, i.e. *;
;* ((variable1 value1) *;
;* (variable2 value2) *;
;* ...) *;
;* modules - List of modules that the Scheme code in the *;
;* template file uses. *;
;* *;
;*****************************************************************************;
(define-macro (process-template template vars . modules)
`(let ((module (make-module 31
(map resolve-interface
',modules))))
,@(map (lambda (vardef)
`(module-define! module
',(if (pair? vardef) (car vardef) vardef)
,(if (pair? vardef) (cadr vardef) vardef)))
vars)
(eval (with-input-from-string (template->code ,template) read)
module)))
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-25 19:37 scheme -> (X)HTML Paul Emsley
2008-03-25 19:53 ` Julian Graham
@ 2008-03-25 20:49 ` Francesco Salvestrini
1 sibling, 0 replies; 11+ messages in thread
From: Francesco Salvestrini @ 2008-03-25 20:49 UTC (permalink / raw
To: guile-user
Hi Paul,
On Tuesday 25 March 2008, Paul Emsley wrote:
> Dear Guilers,
>
> I have in mind to write a little script that makes a web page about the
> state of various files.
>
> I'd like to use some schemey way of doing this. s-expression -> HTML
> perhaps.
Links that could be useful:
http://en.wikipedia.org/wiki/SXML
http://okmij.org/ftp/Scheme/SXML.html
An implementation for guile is available at the following URL:
http://home.gna.org/guile-lib
Cheers,
Francesco
> What is the thinking guile-user's way of approaching this?
>
> Cheers,
>
> Paul.
--
In the Spring, I have counted 136 different kinds of weather inside of
24 hours.
-- Mark Twain, on New England weather
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-25 19:53 ` Julian Graham
2008-03-25 20:38 ` Neil Jerram
@ 2008-03-31 16:41 ` Paul Emsley
2008-03-31 20:33 ` Francesco Salvestrini
1 sibling, 1 reply; 11+ messages in thread
From: Paul Emsley @ 2008-03-31 16:41 UTC (permalink / raw
To: guile-user
Julian Graham wrote:
> On Tue, Mar 25, 2008 at 3:37 PM, Paul Emsley <paul.emsley@bioch.ox.ac.uk> wrote:
>
>
>> Dear Guilers,
>>
>> I have in mind to write a little script that makes a web page about the state of
>> various files.
>>
>> I'd like to use some schemey way of doing this. s-expression -> HTML perhaps.
>>
>> What is the thinking guile-user's way of approaching this?
>>
>
> Hi Paul,
>
> There are several good tools out there for doing this: Oleg Kiselyov
> has written a Scheme-based port of SAX called SSAX [1] that can read
> and emit S-expressions in a format he calls SXML. It's available for
> Guile as part of Andy Wingo's guile-lib [2]. For permissive HTML
> parsing, Neil Van Dyke has written HtmlPrag [3]. And if you're
> interested in a more DOM-based approach, I've got a module called SDOM
> [4].
>
> Hope that helps!
>
> Regards,
> Julian
>
>
> [1]: http://okmij.org/ftp/Scheme/SXML.html
> [2]: http://home.gna.org/guile-lib/
> [3]: http://www.neilvandyke.org/htmlprag/
> [4]: http://www.nongnu.org/sdom/
>
>
Hi Julian,
Thank you and others for replying to my query.
I looked at [1] and [2] in your list - I didn't want to parse XML - not
yet anyway.
Trying [1] I found that Oleg made me jump through hoops with his
idiosyncratically organised
web pages. That put me off a bit. When I tried his code, it was not
clear to me where the output
was going. So I tried [2]. I ended up using [2] because I like reading
Andy Wingo's blog and
it just worked out of the box anyway.
It was such fun! I've not quasiquoted so deeply before. I'm still
tinkering with the script - I use
it to see how my hetrogeneous overnight builds got on.
code here:
http://coot.googlecode.com/svn/trunk/build-web-page-builder.scm
results here:
http://www.ysbl.york.ac.uk/~emsley/coot/build-info.html
(Incidentally, the FC3 build seems to fail because guile-gtk-2.1 fails
to build (it fails in make, not
configure. Is guile-gtk-2.1 supposed to work on gtk+-2.4? ... not
completely the right place to
ask, I guess).
I have a question about the output. How do I put line breaks into the
generated text? All on one
line is fine for my browser - but makes it hard to eyeball the HTML.
After I wrote it (and saw how concise the sxml translator was), I though
"so what's all the fuss
about PHP?" One of the major things, perhaps, is the generation of
images in-line. So I thought
"couldn't guile+sxml do something similar making SVGs on the fly?" Is
that being quietly coded
up by someone? Making a few graphs on the fly shouldn't be so hard,
should it? In fact, I was
even thinking of doing it myself :)
Regards,
Paul.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-31 16:41 ` Paul Emsley
@ 2008-03-31 20:33 ` Francesco Salvestrini
2008-04-02 11:42 ` Thien-Thi Nguyen
0 siblings, 1 reply; 11+ messages in thread
From: Francesco Salvestrini @ 2008-03-31 20:33 UTC (permalink / raw
To: guile-user
Hi Paul,
Sorry for bothering you off the list but I've hit some troubles with guile
mailing lists lately so I'm writing to you directly.
There's a package I've put on savannah that uses SXML (via guile) in order to
build HTML. Maybe it could be of some help to you. This is its main URL:
http://www.nongnu.org/sitetool
Maybe it worth a look.
NOTE: It is in its early stage of development so do not expect too much ;-)
Cheers,
Francesco
On Monday 31 March 2008, Paul Emsley wrote:
> Julian Graham wrote:
> > On Tue, Mar 25, 2008 at 3:37 PM, Paul Emsley <paul.emsley@bioch.ox.ac.uk>
wrote:
> >> Dear Guilers,
> >>
> >> I have in mind to write a little script that makes a web page about the
> >> state of various files.
> >>
> >> I'd like to use some schemey way of doing this. s-expression -> HTML
> >> perhaps.
> >>
> >> What is the thinking guile-user's way of approaching this?
> >
> > Hi Paul,
> >
> > There are several good tools out there for doing this: Oleg Kiselyov
> > has written a Scheme-based port of SAX called SSAX [1] that can read
> > and emit S-expressions in a format he calls SXML. It's available for
> > Guile as part of Andy Wingo's guile-lib [2]. For permissive HTML
> > parsing, Neil Van Dyke has written HtmlPrag [3]. And if you're
> > interested in a more DOM-based approach, I've got a module called SDOM
> > [4].
> >
> > Hope that helps!
> >
> > Regards,
> > Julian
> >
> >
> > [1]: http://okmij.org/ftp/Scheme/SXML.html
> > [2]: http://home.gna.org/guile-lib/
> > [3]: http://www.neilvandyke.org/htmlprag/
> > [4]: http://www.nongnu.org/sdom/
>
> Hi Julian,
>
> Thank you and others for replying to my query.
>
> I looked at [1] and [2] in your list - I didn't want to parse XML - not
> yet anyway.
>
> Trying [1] I found that Oleg made me jump through hoops with his
> idiosyncratically organised
> web pages. That put me off a bit. When I tried his code, it was not
> clear to me where the output
> was going. So I tried [2]. I ended up using [2] because I like reading
> Andy Wingo's blog and
> it just worked out of the box anyway.
>
> It was such fun! I've not quasiquoted so deeply before. I'm still
> tinkering with the script - I use
> it to see how my hetrogeneous overnight builds got on.
>
> code here:
> http://coot.googlecode.com/svn/trunk/build-web-page-builder.scm
> results here:
> http://www.ysbl.york.ac.uk/~emsley/coot/build-info.html
>
> (Incidentally, the FC3 build seems to fail because guile-gtk-2.1 fails
> to build (it fails in make, not
> configure. Is guile-gtk-2.1 supposed to work on gtk+-2.4? ... not
> completely the right place to
> ask, I guess).
>
> I have a question about the output. How do I put line breaks into the
> generated text? All on one
> line is fine for my browser - but makes it hard to eyeball the HTML.
>
> After I wrote it (and saw how concise the sxml translator was), I though
> "so what's all the fuss
> about PHP?" One of the major things, perhaps, is the generation of
> images in-line. So I thought
> "couldn't guile+sxml do something similar making SVGs on the fly?" Is
> that being quietly coded
> up by someone? Making a few graphs on the fly shouldn't be so hard,
> should it? In fact, I was
> even thinking of doing it myself :)
>
> Regards,
>
> Paul.
--
<lilo> Fairlight: udp is the light margarine of tcp/ip transport protocols :)
-- Seen on #Linux
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-31 20:33 ` Francesco Salvestrini
@ 2008-04-02 11:42 ` Thien-Thi Nguyen
0 siblings, 0 replies; 11+ messages in thread
From: Thien-Thi Nguyen @ 2008-04-02 11:42 UTC (permalink / raw
To: guile-user
Another way is to use modules (ttn-do zzz xhtml-tree)[0] and
(ttn-do zzz publishing)[1]. All of gnuvola's html, modulo
texinfo output, is rendered that way. Likewise, the servers
grumi[2] and sizzweb[3] compose using those modules.
Same idea as the others proposed, different dependencies.
thi
[0] http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-xhtml_002dtree
[1] http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-publishing
[2] http://www.gnuvola.org/software/ttn-do/scm-html/grumi.scm.html.gz
[3] http://www.gnuvola.org/software/ttn-do/scm-html/sizzweb.scm.html.gz
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-03-25 20:38 ` Neil Jerram
@ 2008-06-13 20:53 ` Sebastian Tennant
2008-06-16 21:15 ` Neil Jerram
0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Tennant @ 2008-06-13 20:53 UTC (permalink / raw
To: guile-user
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.
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:
guile> (primitive-eval (with-input-from-string (template->code "/path/to/version.html") read))
<html>
<p>This page was processed by Guile 1.8.4</p>
</html>
guile>
or, better still, using eval-string:
guile> (eval-string (template->code "/path/to/version.html"))
<html>
<p>This page was processed by Guile 1.8.4</p>
</html>
guile>
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)
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?
Could you perhaps provide a simple example usage of process-template?
Any guidance much appreciated.
Regards,
Sebastian
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-06-13 20:53 ` Sebastian Tennant
@ 2008-06-16 21:15 ` Neil Jerram
2008-06-21 9:11 ` Sebastian Tennant
0 siblings, 1 reply; 11+ messages in thread
From: Neil Jerram @ 2008-06-16 21:15 UTC (permalink / raw
To: Sebastian Tennant; +Cc: guile-user
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-06-16 21:15 ` Neil Jerram
@ 2008-06-21 9:11 ` Sebastian Tennant
2008-07-03 22:32 ` Neil Jerram
0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Tennant @ 2008-06-21 9:11 UTC (permalink / raw
To: guile-user
Quoth "Neil Jerram" <neiljerram@googlemail.com>:
> OK, I've checked now, and it appears that the code already posted is
> the most up to date that I have.
Noted.
>> guile> (process-template "/path/to/version.html" ((foo 'bar)) (ice-9 rdelim))
>> [...]
>> <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 [...as] the (guile) module contains
> Guile's core bindings, including `begin'.
Ah, I see. I suspected this but make-module is not included in the
procedure index of the info manual and nowhere is there any mention of
the (guile) module.
> (Possibly process-template could add (guile) automatically, but the
> implementation as it stands allows for greater precision.)
Absolutely, and it's not hard to use once you know how.
>> 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").
Neat.
> (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.)
So many options, so few clinchers.
>> 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.
Your explanation is crystal clear, thanks a lot. I was going to suggest
modifying process-template to accept an empty variables list and, in the
absence of a module list, use (guile) and the (current-module) used, but
eval-template is much cleaner.
Out of pure curiosity, whats the significance of '31' in the make-module
call in process-template?
Seb
--
Emacs' AlsaPlayer - Music Without Jolts
http://sebyte.org/eap.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: scheme -> (X)HTML
2008-06-21 9:11 ` Sebastian Tennant
@ 2008-07-03 22:32 ` Neil Jerram
0 siblings, 0 replies; 11+ messages in thread
From: Neil Jerram @ 2008-07-03 22:32 UTC (permalink / raw
To: Sebastian Tennant; +Cc: guile-user
2008/6/21 Sebastian Tennant <sebyte@smolny.plus.com>:
>
> Out of pure curiosity, whats the significance of '31' in the make-module
> call in process-template?
I believe it's the initial size of the module's hash table for storing
bindings (from identifiers to variable locations). (I believe that
prime numbers are good sizes for hash tables.)
Neil
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-07-03 22:32 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).