Skip to content

Commit

Permalink
style updates; using a different default name for the file upload dir…
Browse files Browse the repository at this point in the history
…ectory
  • Loading branch information
rob7hunter committed Nov 10, 2008
1 parent 64c3852 commit 1819cb2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 2 additions & 0 deletions STYLE.txt
Expand Up @@ -37,3 +37,5 @@ Style guide to writing code for the LeftParen project:

* Going forward, we want to use .ss as the extension for all Scheme files. This
apparently plays nicer with the PLT module system.

* Don't use [ or ]. Just use ( and ) all the time.
11 changes: 6 additions & 5 deletions files.scm
Expand Up @@ -4,14 +4,15 @@
(file "web-support.scm")
"settings.scm")

(provide save-uploaded-file!)
(provide save-uploaded-file-and-return-filename!)

(declare-setting *PATH_TO_FILEDATA* (build-path (current-directory) "filedata"))
(declare-setting *PATH_TO_FILEDATA* (build-path (current-directory) "uploaded-files"))

(define (save-uploaded-file! file-data)
(define (save-uploaded-file-and-return-filename! file-data)
(let* ((filename (fresh-filename-id (binding/string:file-filename file-data)))
(raw-file-bytes (binding/string:file-content file-data))
(fport (open-output-file (build-path (setting *PATH_TO_FILEDATA*) filename) #:exists 'error)))
(raw-file-bytes (binding/string:file-content file-data))
(fport (open-output-file (build-path (setting *PATH_TO_FILEDATA*) filename)
#:exists 'error)))
(write-bytes raw-file-bytes fport)
(close-output-port fport)
filename))
Expand Down
35 changes: 19 additions & 16 deletions form.scm
Expand Up @@ -104,8 +104,10 @@
;; it gets a #f assigned to it:
(relevant-req-bindings
(map (match-lambda ((list name label type)
(cons name (field-value-lift (find-binding (symbol->string name) bindings)
type))))
(cons name
(field-value-lift (find-binding
(symbol->string name) bindings)
type))))
fields))
(data (alist-merge init-data relevant-req-bindings))
(a-rec (if (rec? init)
Expand Down Expand Up @@ -226,20 +228,21 @@

;; go from form value to Scheme value
(define (field-value-lift field-val field-type)
(cond
; checkbox?
[(and (equal? field-type 'checkbox) (binding/string:form? field-val))
(if (equal? (binding/string:form-value field-val) "on") #t #f)]
; number?
[(and (equal? field-type 'number) (binding/string:form? field-val))
(string->number (binding/string:form-value field-val))]
; image?
[(and (equal? field-type 'image) (binding/string:file? field-val))
(save-uploaded-file! field-val)]
; else
[else (if (and (binding/string:form? field-val) (string=? (binding/string:form-value field-val) ""))
#f
(binding/string:form-value field-val))]))
(cond
;; checkbox?
((and (equal? field-type 'checkbox) (binding/string:form? field-val))
(if (equal? (binding/string:form-value field-val) "on") #t #f))
;; number?
((and (equal? field-type 'number) (binding/string:form? field-val))
(string->number (binding/string:form-value field-val)))
;; image?
((and (equal? field-type 'image) (binding/string:file? field-val))
(save-uploaded-file-and-return-filename! field-val))
;; else
(else (if (and (binding/string:form? field-val)
(string=? (binding/string:form-value field-val) ""))
#f
(binding/string:form-value field-val)))))

(define (paint-rich-text-editor field-name field-value form-id)
`(div ((class "yui-skin-sam"))
Expand Down
2 changes: 1 addition & 1 deletion generate-lib.scm
Expand Up @@ -39,7 +39,7 @@
(e "The directory ~A already exists." fresh-project-path)
(begin (ensure-existence-of-dir! fresh-project-path)
(ensure-existence-of-dir! (build-path fresh-project-path "data"))
(ensure-existence-of-dir! (build-path fresh-project-path "filedata"))
(ensure-existence-of-dir! (build-path fresh-project-path "uploaded-files"))
(ensure-existence-of-dir! (build-path fresh-project-path "htdocs"))
(ensure-existence-of-dir! (build-path fresh-project-path "htdocs/css"))
(ensure-existence-of-dir! (build-path fresh-project-path "htdocs/js"))
Expand Down

0 comments on commit 1819cb2

Please sign in to comment.