ovidiu      01/12/13 01:25:42

  Added:       scratchpad/schecoon/scheme sitemap.scm
  Log:
  Created.
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/scratchpad/schecoon/scheme/sitemap.scm
  
  Index: sitemap.scm
  ===================================================================
  ;; Sitemap definitions
  ;;
  ;; Author: Ovidiu Predescu <[EMAIL PROTECTED]>
  ;; Date: December 12, 2001
  ;;
  
  ;; Pipeline definition.
  ;;
  ;; A pipeline describes a list of operations to be performed usually
  ;; on a resource, usually an XML document. A pipeline starts with a
  ;; generator, followed by zero or more transformers, and a
  ;; serializer. Such a pipeline is used to process XML documents and
  ;; generate some other representation of the original document
  ;; (usually HTML, WML, PDF, SVG etc.).
  ;;
  ;; For resources which just need to be passed through without any
  ;; modification, the pipeline could have a single step, composed of a
  ;; reader.
  ;;
  ;; To facilitate reuse, pipelines can have names. Pipeline names have
  ;; to be unique, or an error is signaled.
  ;;
  ;; Pipelines are simply functions that accept arguments. These
  ;; arguments are usually passed from the sitemap, where they are
  ;; computed usually from the HTTP request.
  ;;
  ;; Below is an example of how pipelines definition look in
  ;; Scheme. Another Scheme module is responsible to mapping the
  ;; external XML representation of the pipelines definition into this
  ;; internal one.
  ;;
  ;;(define pipelines
  ;;  (define-pipelines
  ;;    (define-pipeline docbook-xhtml
  ;;      (lambda (file)
  ;;     (generate file)
  ;;     (transform '((type xslt)
  ;;                  (name "docbook2xhtml.xsl")
  ;;                  (parameter "view-source" (concat "docs/samples/" file))))
  ;;     (serialize (type xml))))
  ;;
  ;;    (define-pipeline gif-image
  ;;      (lambda (file)
  ;;     (read (concat "src/" file ".gif") "image/gif")))
  ;;    ))
  ;;
  ;; In the above example, we have two pipelines, `docbook-xhtml' and
  ;; `gif-image'. They both take as arguments a file name component,
  ;; which is used to generate the initial resource file. Of course, you
  ;; can define as many arguments as you want for a pipeline definition
  ;; function.
  ;;
  ;; The `define-pipelines' definition takes such a structure and
  ;; returns an associative list whose key is a pipeline name and the
  ;; value is the procedure that defines the pipeline.
  
  (define-syntax define-pipelines
    ; FIXME: tail recursive
    (lambda (x)
      (syntax-case x ()
       ((_ e) (syntax (list e)))
       ((_ e1 e2 ...)
        (syntax (let ((pipedef e1))
                (cons pipedef (define-pipelines e2 ...)))))
       )))
  
  (define-syntax define-pipeline
    (lambda (x)
      (syntax-case x ()
       ((_) '())
       ((_ name body)
        (syntax (cons (quote name) body))))))
  
  ;; Sitemap definition
  ;;
  ;; The sitemap specifies how to map URLs to pipelines, or to Scheme
  ;; functions to control the page flow in an application.
  ;;
  ;;(define the-sitemap
  ;;  (define-sitemap
  ;;    (match "sql/.*"
  ;;           (call-pipeline docbook-xhtml "\\1"))
  ;;
  ;;    (match "slides/.*\.gif"
  ;;           (call-pipeline gif-image "\\1"))
  ;;
  ;;    (match "view-source/*"
  ;;           (generate "\\1"))
  ;;           (transform '((type xslt) (name "xsp"))))
  ;;           (serialize (type xml))))
  ;;
  ;;    (match "shopping-cart"
  ;;       (shopping-cart))
  ;;    ))
  
  (define-syntax define-sitemap
    (lambda (x)
      (syntax-case x ()
       ((_ e ...)
        (syntax (lambda (url)
                (or (e url) ...))))
       )))
  
  (define-syntax match
    (lambda (x)
      (syntax-case x ()
       ((_ pattern expression ...)
        (syntax (let ((regexp (pregexp pattern)))
                (lambda (url)
                  (let ((result (pregexp-match regexp url)))
                    (if result
                        (begin expression ...)
                        #f))))))
       )))
  
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to