File rollup-pages.scm artifact 6207d17268 part of check-in 136be142e4


(use regex posix srfi-69 srfi-1)

(define extract-rx (regexp "pages\\/(.*)_(view|ctrl).scm"))

(let* ((views  (glob "pages/*_view.scm"))
       (ctrls  (glob "pages/*_ctrl.scm"))
       (all    (append views ctrls))
       (lookup (make-hash-table))
       (pages  (delete-duplicates
		(map (lambda (x)
		       (let* ((res  (string-match extract-rx x))
			      (page (cadr res))
			      (type (caddr res)))
			 (hash-table-set! lookup (conc page "_" type) #t)
			 (cadr res)))
		     all))))
       (if (null? all)(begin (print "No page files matching pages/*_(view|ctrl).scm")(exit)))
  (print "Pages: " pages)
  (with-output-to-file "all_pages.scm"
    (lambda ()
      (for-each (lambda (page)
		  (print "(define (pages:" page ")")
		  (if (hash-table-ref/default lookup (conc page "_view") #f)
		      (print "(include \"pages/" page "_view.scm\")"))
		  (if (hash-table-ref/default lookup (conc page "_ctrl") #f)
		      (print "(include \"pages/" page "_ctrl.scm\")"))
		  (print ")\n"))
		pages))))