[Top][All Lists]

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

Re: tagged string builder

From: Martin Grabmueller
Subject: Re: tagged string builder
Date: Mon, 26 Mar 2001 11:28:37 +0200

> From: Keisuke Nishida <address@hidden>
> Date: Sun, 25 Mar 2001 13:01:24 -0500
> By the way, is it a good idea to rewrite Guile's web pages
> using this notation?  I generate my personal pages like this:


Just for those who are interested in generating HTML with Guile: Some
time ago, I wrote a little skript for generating my personal pages,
which is small, simple to use and closer to writing HTML (for example,
you can use Emacs' html-mode without great problems.

Example input looks like this:

%(define title "mgrabmue's home")
%(define author-email "address@hidden")
<h2>%title </h2>
<address>%author-email </address>

Have fun,


#! /bin/sh
exec guile -s $0 $*

; html-pp.scm
; This fine tool can be used to preprocess text files (I mainly use it
; to generate web pages.  Usage is simple.  Just pass the name of the
; file to preprocess on the commandline and the processed output will
; be written to stdout.  If no file name is given, standard input is
; used to read the data.
; Syntax of the source files:
; ===========================
; Normal text in source files are simply written to standard output.
; Preprocessing is triggered by using the character `%' in the input
; file. The Scheme expression immediately following this character is
; read and evaluated, the result of evaluation is then written to
; standard output, if it is a string, otherwise it is only evaluated
; for side effects.
; Note that any whitespace following a Scheme expression is discarded
; and thus does not appear in the output.
; See the example source file `boo.scmtml' for how to use this script.

;;; File handling ====================================================

;; Process all expressions available on port IN-PORT.
(define (handle-file in-port)
  (let loop ((ch (read-char in-port)))
    (cond ((eof-object? ch)
          ((char=? ch #\%)
           (let* ((expr (read in-port))
                  (res (eval expr (interaction-environment))))
             (if (string? res)
                 (display res)))
           (loop (read-char in-port)))
           (display ch)
           (loop (read-char in-port))))))

;; Process all files whose filenames are on the list FILES.  Use STDIN
;; if the given list is empty.
(define (handle-files files)
  (if (pair? files)
      (for-each (lambda (file)
                  (call-with-input-file file handle-file))
      (handle-file (current-input-port))))

(let ((cmdline (command-line)))
  (handle-files (if (pair? cmdline) (cdr cmdline) '())))

reply via email to

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