Changeset 14438 in project


Ignore:
Timestamp:
04/25/09 18:33:26 (10 years ago)
Author:
sjamaan
Message:

Add example code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/3/spiffy-utils

    r14435 r14438  
    9797behave as with {{write-cookie}}. (See above).
    9898
     99==== Example
     100
     101<enscript highlight=scheme>
     102;; A simple webpage which allows you to play with three different
     103;; types of variables, which are submitted to the page itself via HTTP GET.
     104(use spiffy-utils sxml-transforms srfi-1 regex doctype)
     105(define vars `((integer . ,(get-var 'integer string->number 0))
     106               (boolean . ,(get-var 'boolean string->bool))
     107               (string . ,(get-var 'string identity ""))))
     108
     109(define (addfoo var)
     110  (string-append var "foo "))
     111
     112(define (delfoo var)
     113  (string-substitute "foo " "" var))
     114
     115(define (alist-replace var func)
     116  (alist-cons var (func (alist-ref var vars))
     117              (alist-delete var vars)))
     118
     119(define my-conversion-rules
     120  `((doctype . ,(lambda (doctype) doctype:xhtml-1.0-strict))
     121    ,@universal-conversion-rules))
     122
     123(define document
     124 `((doctype)
     125   (html
     126    (head
     127     (title "GET-var and typing showcase"))
     128    (body
     129     (dl
     130      (dt "Integer:")
     131      (dd (url ,(link-to "test.ssp" (alist-replace 'integer sub1)) "sub1")
     132          " " ,(alist-ref 'integer vars) " "
     133          (url ,(link-to "test.ssp" (alist-replace 'integer add1)) "add1"))
     134      (dt "Boolean:")
     135      (dd ,(->string (alist-ref 'boolean vars)) " "
     136          (url ,(link-to "test.ssp" (alist-replace 'boolean not)) "Toggle"))
     137      (dt "String:")
     138      (dd (url ,(link-to "test.ssp" (alist-replace 'string delfoo)) "Delete foo")
     139          " " ,(alist-ref 'string vars)
     140          (url ,(link-to "test.ssp" (alist-replace 'string addfoo)) "Add foo")))))))
     141
     142(output-html document shortcut-rules my-conversion-rules)
     143</enscript>
     144
    99145=== Pagination
    100146
     
    229275browser.  If the browser does not support it, an url with the
    230276description {{title}} is provided.
     277
     278==== Example
     279
     280<enscript highlight=scheme>
     281;; A quick example of how to use pagination-rules
     282(use spiffy-utils sxml-transforms doctype srfi-1)
     283
     284(define my-conversion-rules
     285  `((doctype . ,(lambda (doctype) doctype:xhtml-1.0-strict))
     286    ,@universal-conversion-rules))
     287
     288(define content
     289  `((doctype)
     290    (html
     291     (head
     292      (title "Showing page" ,(current-page 109) " of " ,(page-count 109)))
     293     (body
     294      (paginate-list
     295       (div (@ (class "paginated-stuff"))
     296            (p "Click on a number to flip to the corresponding page:")
     297            (pagination-links)
     298            (p "Below we see something that is shown only once per page "
     299               "(the UL), which has subentries that are shown many times "
     300               "per page, ie the entries on the page (the LIs):")
     301            (ul
     302             (entries
     303              (li (entry))))
     304            (p "As we can see, every part of the page that has to be "
     305               "for every entry is enclosed by the (entries) 'tag'."
     306               "We can also show the same entries twice or more:")
     307            (ol
     308             (entries
     309              (li (entry))))
     310            (p "Showing entry" (first-entry) " through " (last-entry) " on "
     311               "page " (current-page) " of " (page-count) "."))
     312       ,(iota 109))
     313      (p "We are showing entry " ,(first-entry 109) " through "
     314         ,(last-entry 109) ".")
     315      (p "Note that it is necessary to pass the total number of entries "
     316         "to every pagination function, but not the actual tags within "
     317         "(pagination).  This is because the paginator has no way of "
     318         "determining this outside of the (paginate-list) 'tag'.")))))
     319
     320(output-html content pagination-rules shortcut-rules my-conversion-rules)
     321</enscript>
    231322
    232323=== Miscellaneous
Note: See TracChangeset for help on using the changeset viewer.