Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jeyoor/testify
base: 30e2b9140f
...
head fork: jeyoor/testify
compare: 14f0209dd2
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 18, 2012
@jpaugh jpaugh [FIX] Fixed the code update that plagued us
Now, the project compiles!
I redid some changes that had been missing. routes.clj was missing, but
the corresponding code was also gone from core.clj: i.e. the deletions
from core.clj were recorded /without/ the additions to routes.clj.

The same thing had happened with process.clj and views.

I split the views out into separate files under views/ this time. I
think it makes sense to think of the admin and pages components as
separate modules, and the views now reflect this.
34b4561
@jpaugh jpaugh run.sh autostarts redis-server
run.sh guarantees that redis-server is running before starting the web
server: if it's already running, then nothing will be done.
488427f
@jpaugh jpaugh Changed the README to ReST format, so it looks pretty on GitHub
Previously, it had been README.md, i.e. Markdown format, but since
we wern't actually using Markdown syntax, and since I know ReST, I
figured this would be better.

Actually, ReST is pretty simple, so I think everyone can start using it
without realizing it.
c44c51f
@jeyoor Merge branch 'master', remote branch 'jpaugh/master' 14f0209
View
19 README → README.rst
@@ -1,12 +1,16 @@
-# testify
+Introduction
+============
Testify is a web applicaton framework designed for personal storying.
-## Installation
+Installation
+============
There are three dependencies of testify: java, redis, and lein
-Your Java version needs to be at least 1.5. I bet you can handle that.
+Your Java version needs to be at least 1.5. I bet you can handle that. Note
+that we don't need the JDK: just the JRE is fine. (And if you don't know the
+difference, you're fine ;-)
redis is in your distribution's repository. For Ubuntu, that is
@@ -26,18 +30,23 @@ PATH+=':~/bin'
The first time lein runs, it will gather all of its dependencies, so you don't
have to.
-## Usage
+Usage
+=====
+
Run the following command to start the webserver:
$ ./run.sh
+This also starts redis-server, if that's not already running.
+
By default, the website is hosted at http://localhost:8000, but if you need to
change the port number, use the PORT environment variable. Note that PORT must
be either a number or unset.
$ PORT=8000 ./run.sh
-## License
+License
+=======
Copyright (C) 2012 Jeyan Oorjitham
View
10 run.sh
@@ -1,2 +1,8 @@
-#!/bin/sh
-exec lein run -m testify.core
+#!/bin/bash
+APPDIR=$(dirname $0)
+if [[ -z $(pidof redis-server) ]]; then
+ echo "Starting Redis server"
+ redis-server $APPDIR/redis/redis.conf >/dev/null&
+fi
+echo "Starting web server"
+exec lein run -m testify.core
View
23 src/testify/process/dyn_html.clj
@@ -1,11 +1,10 @@
-(ns testify.process.dyn-html (:use testify.remain
- testify.appear testify.html-macros)
- (:require [redis.core
- :as redis]
- [net.cgrand.enlive-html
- :as html]
- [testify.util
- :as util]))
+(ns testify.process.dyn-html
+ (:use testify.remain
+ testify.appear
+ testify.html-macros)
+ (:require [redis.core :as redis]
+ [net.cgrand.enlive-html :as html]
+ [testify.util :as util]))
(defn get-html [id]
(do-redis (fetch (str "template:" id ":html"))))
@@ -22,15 +21,11 @@
(defn get-types
"for each node in list, destructure to find its type"
[nodelist]
- (map #
- (let [{{classy :class} :attrs} %]
- classy)
+ (map #(let [{{classy :class} :attrs} %] classy)
nodelist))
(defn get-ids [nodelist]
- (map #
- (let [{{idy :id} :attrs} %]
- idy)
+ (map #(let [{{idy :id} :attrs} %] idy)
nodelist))
(defn map-ids-types [nodelist]
View
77 src/testify/routes.clj
@@ -0,0 +1,77 @@
+(ns testify.routes
+ (:use
+ compojure.core
+ )
+ (:require
+ [compojure.route :as route]
+ [compojure.handler :as handler]
+ [testify.middleware :as middleware]
+ [testify.persist :as persist]
+ [testify.debug :as debug]
+
+ [testify.views.page :as page]
+ [testify.views.admin :as admin]
+ [testify.views.template :as template]
+ [testify.views.resource :as resource]
+ )
+)
+
+
+
+(defroutes page-routes
+ ;Redirect to something useful
+ ;(GET "/" [] )
+ (GET "/form" [tname] (page/form-page tname))
+ (GET "/view" [pname] (page/view-page pname))
+ (POST "/save" [save PageName template & savedata] (page/save-page PageName template savedata))
+ (POST "/delete" [pname token] (page/delete-page))
+)
+
+(defroutes admin-routes
+
+ (GET "/" [] (admin/admin-menu))
+ (GET "/templates/preview" [tname] (template/preview-template tname))
+ (GET "/template/form" [] (template/form-template))
+ ;use the "save" param but don't pass it [drop btn name before saving everything]
+ (POST "/template/save" [save TemplateName thtml] (template/save-template TemplateName thtml))
+ (POST "/template/delete" [tname] (template/delete-template tname))
+ (GET "/resource/form" [] (resource/form-resource))
+ (POST "/resource/save" [save ResourceName rfile] (resource/save-resource ResourceName rfile))
+ (POST "/resource/delete" [rname] (resource/delete-resource rname))
+ (GET "/template" [] (admin/admin-template))
+ (GET "/resource" [] (admin/admin-resource))
+ (GET "/page" [] (admin/admin-page))
+ ;pages
+ (POST "/page/delete" [] (admin/admin-delete-page))
+)
+
+(defroutes main-routes
+
+ (context "/page" [] page-routes)
+ (context "/admin" [] admin-routes)
+
+ ;misc
+ (GET "/on_dev" [] (str (middleware/development?)))
+ (GET "/template" [] (template/list-template))
+ (GET "/" [] (page/list-page) )
+ (route/resources "/")
+ (route/not-found "<h3>Page not found</h3>")
+)
+
+
+(def app
+ (if (middleware/development?)
+ ;production blocks error stacktraces from printing, but logs 'em
+
+ ;thread the object instead of the symbol
+ (->
+ #'main-routes
+ (handler/site)
+ )
+ (->
+ #'main-routes
+ (handler/site)
+ (middleware/wrap-errorlog)
+ ;TODO:
+ ;(middleware/wrap-failsafe)
+ )))
View
73 src/testify/views/admin.clj
@@ -0,0 +1,73 @@
+(ns testify.views.admin
+ (:use
+ testify.remain
+ testify.appear
+ testify.process
+ )
+ (:require
+ [testify.process.dyn-html :as dhtml]
+ [testify.util :as util]
+ [clojure.string :as string]
+ [clojure.contrib.io :as io]
+ ))
+
+(defn admin-menu []
+ (link-base
+ "Administration"
+ "Back to User's View"
+ "/"
+ (list
+ (ul-link "Manage pages" "/admin/page")
+ (ul-link "Manage templates" "/admin/template")
+ (ul-link "Manage resources" "/admin/resource")
+ )
+ )
+)
+
+(defn admin-page []
+ ;get ids from full keynames
+ (let [paglist (map id (dump "page" "token"))]
+ ;use the ids to populate a linklist
+ (link-base
+ "Manage pages" "Add a Page" "/template"
+ (form "POST" "/admin/page/delete"
+ (dbl-linknodes paglist "/page/view?pname=" "delete" "Delete ")
+ )
+ )
+ )
+)
+
+(defn admin-template
+ "retrive a list of templates from the data store and return html link list"
+ []
+ ;get ids from full keynames
+ (let [tmpltlist (map id (dump "template" "html"))]
+ ;use the ids to populate a linklist
+
+ (link-base
+ "Manage templates" "Add a Template" "/admin/template/form"
+ (form "POST" "/admin/template/delete"
+ (dbl-linknodes tmpltlist "/template/preview?tname=" "delete" "Delete ")
+ )
+ )
+ )
+)
+
+(defn admin-resource
+ "retrive a list of resources from the data store and return html link list with admin properties"
+ []
+ ;get ids from full keynames
+ (let [reslist (map id (dump "resource" "file"))]
+ ;use the ids to populate a linklist
+ (link-base
+ "Manage resources" "Add a Resource" "/admin/resource/form"
+ (form "POST" "/admin/resource/delete"
+ (dbl-linknodes reslist "/resource/" "delete" "Delete ")
+ )
+ )
+ )
+)
+
+(defn admin-delete-page []
+;TODO codethis
+)
View
99 src/testify/views/page.clj
@@ -0,0 +1,99 @@
+(ns testify.views.page
+ (:use
+ testify.remain
+ testify.appear
+ testify.process
+ )
+ (:require
+ [net.cgrand.enlive-html :as html]
+ [testify.process.dyn-html :as dhtml]
+ [testify.util :as util]
+ [clojure.string :as string]
+ [clojure.contrib.io :as io]
+ ))
+
+(defn list-page
+ "retrive a list of pages from the data store and return html link list"
+ []
+ ;get ids from full keynames
+ (let [pagelist (map id (dump "page" "token"))]
+ ;use the ids to populate a linklist
+ (link-base nil "Add Page?" "/template" (linknodes pagelist "/page/view?pname="))
+ ))
+
+
+(defn form-page [template]
+ ;todo: unroll with let?
+ (if (nil? template)
+ (link-base "" "Please choose a template from the list." "/template/" "ERROR! No template specified")
+ (base "Enter text, an image URL, or a GodTube video URL"
+ (page-form "POST" "/page/save" template
+ (map
+ #(apply input-row %)
+ (cons
+ ;add an input for filename
+ (list "text" "PageName" )
+ (dhtml/get-pairs (fetch (str "template:" template ":html")))
+ )
+ )
+ )
+ )
+ )
+)
+
+;TODO: validate user's responses here
+;TODO: check for DB errors here?
+;TODO: transactional dbstuff?
+(defn save-page [pname template savedata]
+ (let [ ;NOTE: must change :keyword to ":keyword"
+ keyz (keys savedata)
+ valuez (util/scrub (vals savedata))
+ token (util/gen-token pname)
+ ]
+ ;add new page to mommaset
+ (if (sstore "page" pname)
+ (do
+ ;New page! store page's deletion tokes
+ (store (str "page:" pname ":token") token)
+ ;store the page's template
+ (store (str "page:" pname ":template") template)
+ ;store the subsmap
+ (apply hstore (str "page:" pname ":subs") (interleave keyz valuez))
+ ;print the tokes
+ (link-base
+ "Success! Page saved."
+ "Back to main"
+ "/"
+ (message (str "Your deletion token is "
+ token ". Please save your token somewhere safe."
+ "You will need if you ever want to remove your page from Testify." ) )
+ )
+ )
+ ;page exists, say error
+ (link-base
+ "Error! Page exists with that name."
+ "Back to add page"
+ "javascript:javascript:history.go(-1)"
+
+ (message (str "A page with that name already exists. Please try again." ) )
+ )
+
+ )
+ )
+)
+
+(defn view-page [pname]
+ (let [ prefix (str "page:" pname) subsm (hfetch (str prefix ":subs")) tname (fetch (str prefix ":template"))]
+ (let [thtml (fetch (str "template:" tname ":html")) tnodes (html/html-snippet thtml)]
+ ;TODO finishthis
+ (string/join (dhtml/subsw tnodes subsm))
+ )
+ )
+)
+
+(defn delete-page
+ "if both nil, diplay form, otherwise take args and delete the page"
+ ([])
+ ;TODO codethis
+ ([pname token])
+)
View
32 src/testify/views/resource.clj
@@ -0,0 +1,32 @@
+(ns testify.views.resource
+ (:use
+ testify.remain
+ testify.appear
+ testify.process
+ )
+ (:require
+ [testify.process.dyn-html :as dhtml]
+ [testify.util :as util]
+ [clojure.string :as string]
+ [clojure.contrib.io :as io]
+ ))
+
+(defn form-resource []
+ (link-base "Enter a name and pick a file to upload." "Back to admin" "/admin/resource"
+ (save-form "POST" "/admin/template/save"
+ (conj
+ (input-row (list "text" "TemplateName" ))
+ (input "file" "file-input" "FileName" "coolfile.jpg")
+ ))))
+
+(defn save-resource [rname rfile]
+ (if (or (nil? rfile) (nil? rname))
+ (link-base "" "Back to Resource Add" "/admin/resource/form" "Error! File or name missing")
+ (store (str "resource:" rname ":file") (io/to-byte-array rfile))
+ ))
+
+(defn delete-resource [rname]
+ (if (nil? rname)
+ (link-base "Delete a resource" "Back to admin" "/admin/" )
+ ))
+
View
68 src/testify/views/template.clj
@@ -0,0 +1,68 @@
+(ns testify.views.template
+ (:use
+ testify.remain
+ testify.appear
+ testify.process
+ )
+ (:require
+ [testify.process.dyn-html :as dhtml]
+ [testify.util :as util]
+ [clojure.string :as string]
+ [clojure.contrib.io :as io]
+ ))
+
+(defn list-template
+ "retrive a list of templates from the data store and return html link list"
+ []
+ ;get ids from full keynames
+ (let [tmpltlist (map id (dump "template" "html"))]
+ ;use the ids to populate a linklist
+ (base "Pick a template" (linknodes tmpltlist "/page/form?tname="))
+
+ )
+)
+
+(defn form-template []
+ (base "Enter a name and html for the template. Use class=a, a E {text,image,video} to mark tags for substitution."
+ (save-form "POST" "/admin/template/save"
+ (map
+ #(apply input-row %)
+ (list
+ ;add an input
+ (list "text" "TemplateName" )
+ (list "text" "thtml")
+ )
+ )
+ )
+ )
+)
+
+
+;TODO validate for valid HTML
+;TODO validate for AT LEAST ONE field
+;TODO validate for correct typing?
+;TODO warn if already exists
+(defn save-template [tname thtml]
+ (let [res1 (sstore "template" tname)
+ res2 (store (str "template:" tname ":html") thtml)]
+ (link-base "Template saved!" "Back to admin" "/admin" (str "New template? " res1 "Stored ok? " res2))
+ )
+)
+
+;TODO: confirmation page?
+(defn delete-template [tname]
+ (let [res1 (sdelete "template" tname)
+ res2 (delete (str "template:" tname ":html")) ]
+ (link-base "Template deleted!" "Back to admin" "/admin" (str "Unlisted ok? " res1 "Deleted ok? " res2))
+ )
+)
+;TODO: codethis with umm.. returning the template's html
+(defn preview-template [tname]
+ (link-base
+ (str "Previewing template " tname)
+ "Back to templates"
+ "/template"
+ (do-redis (fetch (str "template:" tname ":html")))
+ )
+)
+

No commit comments for this range

Something went wrong with that request. Please try again.