pull/9/head
Matthew Butterick 11 years ago
parent 5ca8ec5eed
commit c025de31dc

@ -10,6 +10,11 @@
[arg (if (> (len args) 0) (get args 0) "")])
(display (format "~a: " POLLEN_COMMAND_FILE))
(case arg
[("help") (displayln "valid commands are
polcom start (starts project server)
polcom render (renders all files in project directory)
polcom clone (copies rendered files to desktop)
polcom [filename] (renders individual file)")]
[("start") `(require "server.rkt")]
[("render") `(begin
;; todo: take extensions off the comand line

@ -24,7 +24,7 @@
(set! last-message-time now)
(if then
(- now then)
"--"))
"0"))
(define (zero-fill str count)
(set! str (~a str))
@ -59,7 +59,7 @@
(string-append (string-join time-fields ":") (if (< (date-hour date) 12) "am" "pm")))
(define (make-debug-timestamp)
(format "[~a ~as]" (make-timestamp) (seconds-since-last-message)))
(format "[~a ~as]" (make-timestamp) (seconds-since-last-message)))
(define (message . items)
(displayln (string-join `(,(make-debug-timestamp) ,@(map (λ(x)(if (string? x) x (~v x))) items))) (current-error-port)))

@ -19,8 +19,9 @@
(dynamic-rerequire path) ; stores module mod date; reloads if it's changed
(dynamic-require path 'main))
(module+ test
(check-equal? (file->xexpr (build-path (current-directory) "tests/server-routes/foo.p") #:render #f) '(root "\n" "foo")))
;; todo: rewrite this test, obsolete since filename convention changed
;;(module+ test
;; (check-equal? (file->xexpr (build-path (current-directory) "tests/server-routes/foo.p") #:render #f) '(root "\n" "foo")))
;; read contents of file to string
;; just file->string with a render option
@ -94,15 +95,19 @@
#:key path->string string<?))
;; calculate names of post-pollen files
;; todo: this isn't quite right. Assumes post-pollen file will have html extension.
;; not necessarily true (it will assume the extension of its template.)
;; But pulling out all the template extensions requires parsing all the files,
;; which is slow and superfluous, since we're trying to be lazy about rendering.
(define post-pollen-files (map ->output-path pollen-files))
;; Make a combined list of pollen files and post-pollen files, in alphabetical order
(define all-pollen-files (sort (append pollen-files post-pollen-files) #:key path->string string<?))
(define leftover-files (filter (λ(f) (and
(not (equal? (->string f) "polcom")) ;todo: generalize this test
(not ((->string f) . starts-with? . "."))
(not (f . in? . all-pollen-files))))
(directory-list pollen-project-directory)))
(message leftover-files)
;; Utility function for making file rows
(define (make-file-row file routes)
;; Utility function for making cells
@ -123,14 +128,14 @@
`(td (a ((href ,target)) ,name))))
`(tr ,(make-link-cell 'direct) ,@(map make-link-cell routes)))
(if (andmap empty? (list ptree-files all-pollen-files all-preproc-files template-files))
(if (andmap empty? (list ptree-files all-pollen-files all-preproc-files template-files leftover-files))
'(body "No files yet. Get to work!")
`(body
(style ((type "text/css")) "td a { display: block; width: 100%; height: 100%; padding: 8px; }"
"td:hover {background: #eee}")
(table ((style "font-family:Concourse T3;font-size:115%"))
;; options for ptree files and template files
,@(map (λ(file) (make-file-row file '(raw))) (append ptree-files template-files))
,@(map (λ(file) (make-file-row file '(raw))) (append leftover-files ptree-files template-files))
;; options for pollen files
,@(map (λ(file) (make-file-row file '(raw source xexpr force))) post-pollen-files)

@ -6,7 +6,9 @@
(require "server-routes.rkt" "predicates.rkt" "debug.rkt")
(define port-number 8088)
(message (format "Starting webserver at http://localhost:~a" port-number))
(message (format "Project directory is ~a" pollen-project-directory))
(message (format "Project server is http://localhost:~a" port-number) "(Ctrl-C to exit)")
(define (logger req)
(define client (request-client-ip req))
@ -24,7 +26,7 @@
(define-values (start url)
(dispatch-rules
[("start") (λ(req)
[("pollen") (λ(req)
(logger req)
(response/xexpr (route-index)))]
[("source" (string-arg)) (route-wrapper route-source)]
@ -37,7 +39,8 @@
(route-default req)
(next-dispatcher))]))
(message "Ready to rock. Type ^C to exit")
(message (format "Project dashboard is http://localhost:~a/pollen" port-number))
(message "Ready to rock")
(serve/servlet start

@ -4,16 +4,29 @@
(provide setup)
(define cd (current-directory))
(define (make-polcom-data racket-path)
(format "#! ~a
#lang racket/base
(require pollen/command)
; pollen setup run on ~a"
; pollen setup run in ~a on ~a"
racket-path
cd
(format "~a at ~a" (make-datestamp) (make-timestamp))))
(define (setup)
(define cd (current-directory))
; this function is just for export.
; it hides the test-only parameter
(setup-testable #f))
(define (setup-testable test-only)
(message (format "Set up ~a as a pollen directory? ['y' or 'yes']" cd))
(define setup-confirm (->string (read)))
(when (not (or (equal? setup-confirm "y") (equal? setup-confirm "yes")))
(begin
(message "Aborting setup")
(exit)))
(message (format "Setting up ~a as a pollen directory" cd))
(define racket-path (string-trim (with-output-to-string (λ() (system "which racket")))))
@ -27,12 +40,17 @@
(begin
(message (format "Deleting existing polcom file in ~a" cd))
(delete-file polcom-filename)))
(message (format "Creating new polcom file in ~a" cd))
(with-handlers ([exn:fail? (λ(e) (message "Couldn't write polcom file. Aborting setup"))])
(display-to-file polcom-data polcom-filename)
(with-output-to-string (λ() (system (format "chmod 755 ~a" polcom-filename))))
(when (not test-only)
(begin
(message (format "Creating new polcom file in ~a" cd))
(display-to-file polcom-data polcom-filename)
(with-output-to-string (λ() (system (format "chmod 755 ~a" polcom-filename))))))
(message "Setup complete")
(message (format "Run '~a~a start' to start pollen development server" cd polcom-filename))
(message (format "Run '~a~a start' to start project server" cd polcom-filename))
(message (format "Or run '~a~a help' for a list of commands" cd polcom-filename))
(exit)))
(when (not test-only) (exit))))
(message "No path to racket binary. Aborting setup")))
(module+ main
(setup-testable #t))

@ -1,4 +1,3 @@
#lang racket/base
(require "debug.rkt")
(message "Starting Pollen")
(message "Using Racket" (version))
(require "debug.rkt" "world.rkt")
(message (format "Welcome to Pollen ~a" POLLEN_VERSION) (format "(Racket ~a)" (version)))

@ -2,6 +2,8 @@
(provide (all-defined-out))
(define POLLEN_VERSION "0.001")
(define POLLEN_PREPROC_EXT 'p)
(define POLLEN_SOURCE_EXT 'pd)
(define TEMPLATE_FILE_PREFIX "-")

Loading…
Cancel
Save