Define view functions separately from classes
Using `lambda' the way it was being used is not pretty.
This commit is contained in:
parent
9788df48a9
commit
8e599478f7
1 changed files with 59 additions and 52 deletions
43
hypo.hy
43
hypo.hy
|
@ -65,19 +65,16 @@ If no lexer is found fallback onto the text lexer."
|
|||
(catch [ClassNotFound]
|
||||
(get-lexer-by-name "text"))))
|
||||
|
||||
(defclass raw []
|
||||
[[GET (lambda [self name]
|
||||
(defun get-raw [self name]
|
||||
(let ((dirname (+ "files/" (os.path.dirname name)))
|
||||
(repo (and (os.path.exists dirname)
|
||||
(Gittle dirname)))
|
||||
(resp (if repo
|
||||
(get (.commit-file
|
||||
repo "HEAD" (os.path.basename name))
|
||||
(get (.commit-file repo "HEAD" (os.path.basename name))
|
||||
"data"))))
|
||||
(or resp (no-such-file))))]])
|
||||
(or resp (no-such-file))))
|
||||
|
||||
(defclass download []
|
||||
[[GET (lambda [self name]
|
||||
(defun get-attachment [self name]
|
||||
(let ((dirname (+ "files/" (os.path.dirname name)))
|
||||
(repo (and (os.path.exists dirname)
|
||||
(Gittle dirname))))
|
||||
|
@ -85,9 +82,8 @@ If no lexer is found fallback onto the text lexer."
|
|||
(progn
|
||||
(web.header "Content-Disposition"
|
||||
(+ "attachment; filename=\"" name "\""))
|
||||
(get (.commit-file repo "HEAD"
|
||||
(os.path.basename name)) "data"))
|
||||
(no-such-file))))]])
|
||||
(get (.commit-file repo "HEAD" (os.path.basename name)) "data"))
|
||||
(no-such-file))))
|
||||
|
||||
(defun render-file [hash repo ref filename]
|
||||
(if (not (os.path.isdir filename))
|
||||
|
@ -107,8 +103,7 @@ If no lexer is found fallback onto the text lexer."
|
|||
(kwapply (render.main) args))
|
||||
""))
|
||||
|
||||
(defclass html []
|
||||
[[GET (lambda [self name]
|
||||
(defun get-html [self name]
|
||||
(let ((dirname (+ "files/" name))
|
||||
(repo (and (os.path.exists dirname)
|
||||
(Gittle dirname))))
|
||||
|
@ -117,16 +112,15 @@ If no lexer is found fallback onto the text lexer."
|
|||
[f (.iterkeys (.commit-tree repo "HEAD"))]
|
||||
(not (or (= f ".")
|
||||
(= f "..")))))
|
||||
(no-such-file))))]
|
||||
(no-such-file))))
|
||||
|
||||
[DELETE (lambda [self name]
|
||||
(defun delete-dir [self name]
|
||||
(let ((dirname (+ "files/" name)))
|
||||
(if (os.path.exists dirname)
|
||||
(shutil.rmtree dirname)
|
||||
(no-such-file))))]])
|
||||
(no-such-file))))
|
||||
|
||||
(defclass upload []
|
||||
[[PUT (lambda [self name]
|
||||
(defun upload-file [self name]
|
||||
(let ((h (hashes name))
|
||||
(dirname (+ "files/" (get h 0))))
|
||||
(os.mkdir dirname)
|
||||
|
@ -139,7 +133,20 @@ If no lexer is found fallback onto the text lexer."
|
|||
"email" "hypo@ryuslash.org"
|
||||
"message" "Initial commit"}))
|
||||
(setv web.ctx.status (str "201 Created"))
|
||||
(+ web.ctx.home "/" *prefix* (get h 0) "\n")))]])
|
||||
(+ web.ctx.home "/" *prefix* (get h 0) "\n")))
|
||||
|
||||
(defclass raw []
|
||||
[[GET get-raw]])
|
||||
|
||||
(defclass download []
|
||||
[[GET get-attachment]])
|
||||
|
||||
(defclass html []
|
||||
[[GET get-html]
|
||||
[DELETE delete-dir]])
|
||||
|
||||
(defclass upload []
|
||||
[[PUT upload-file]])
|
||||
|
||||
(defclass index []
|
||||
[[GET (lambda [self] (render.index))]])
|
||||
|
|
Loading…
Reference in a new issue