Skip to content

Commit

Permalink
template files found on path now
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyoor committed Feb 23, 2012
1 parent ee89091 commit 0543ce7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion project.clj
Expand Up @@ -11,5 +11,5 @@
[org.clojars.tavisrudd/redis-clojure "1.3.1-SNAPSHOT"] [org.clojars.tavisrudd/redis-clojure "1.3.1-SNAPSHOT"]
] ]
:dev-dependencies [[lein-ring "0.4.5"]] :dev-dependencies [[lein-ring "0.4.5"]]
:ring {:handler testify.core/app} :ring {:handler testify.routes/app}
) )
20 changes: 10 additions & 10 deletions src/testify/appear.clj
Expand Up @@ -5,7 +5,7 @@
(:require [clojure.string :as string])) (:require [clojure.string :as string]))




(deftemplate base "testify/templates/base.html" [pagetitle content] (deftemplate base "../resources/templates/base.html" [pagetitle content]
;if a header is passed in, give substi fun ;if a header is passed in, give substi fun
;otherwise, give identity fun (leave html unchng) ;otherwise, give identity fun (leave html unchng)
[:div#header :span#pagetitle] (maybe-appear pagetitle) [:div#header :span#pagetitle] (maybe-appear pagetitle)
Expand All @@ -14,7 +14,7 @@
[:div#content] (maybe-content content)) [:div#content] (maybe-content content))




(deftemplate link-base "testify/templates/base.html" (deftemplate link-base "../resources/templates/base.html"
[pagetitle linkname linkref content] [pagetitle linkname linkref content]
;if a header is passed in, give substi fun ;if a header is passed in, give substi fun
;otherwise , give identity fun (leave html unchng) ;otherwise , give identity fun (leave html unchng)
Expand All @@ -24,20 +24,20 @@
(maybe-href linkref)) (maybe-href linkref))
[:div#content] (maybe-content content)) [:div#content] (maybe-content content))


(defsnippet message "testify/templates/base.html" [:span.message] (defsnippet message "../resources/templates/base.html" [:span.message]
[message] [message]
;TODO: make this more expressive? ;TODO: make this more expressive?
[:span.message] (maybe-content message)) [:span.message] (maybe-content message))


(defsnippet input "testify/templates/user_input.html" [:input.field] (defsnippet input "../resources/templates/user_input.html" [:input.field]
[type name classy value] [type name classy value]
[:input.field] [:input.field]
(do-> (maybe-type type) (do-> (maybe-type type)
(maybe-class classy) (maybe-class classy)
(maybe-name name) (maybe-name name)
(maybe-value value))) (maybe-value value)))


(defsnippet ul-link "testify/templates/user_list.html" (defsnippet ul-link "../resources/templates/user_list.html"
;grab the whole unordered list ;grab the whole unordered list
[:ul.mainlist] [:ul.mainlist]
;take link name and ref as params ;take link name and ref as params
Expand All @@ -48,7 +48,7 @@
(do-> (content linkname) (do-> (content linkname)
(set-attr :href linkref))) (set-attr :href linkref)))


(defsnippet ul-link-delete "testify/templates/admin_list.html" (defsnippet ul-link-delete "../resources/templates/admin_list.html"
;grab the whole unordered list ;grab the whole unordered list
[:ul.mainlist] [:ul.mainlist]
;take link name and ref as params ;take link name and ref as params
Expand All @@ -62,14 +62,14 @@
(do-> (maybe-name postname) (do-> (maybe-name postname)
(maybe-value postval))) (maybe-value postval)))


(defsnippet form "testify/templates/user_input.html" [:form] (defsnippet form "../resources/templates/user_input.html" [:form]
[method action content] [method action content]
[:form] [:form]
(do-> (set-attr :action action (do-> (set-attr :action action
:method method) :method method)
(maybe-content content))) (maybe-content content)))


(defsnippet save-form "testify/templates/user_input.html" [:form] (defsnippet save-form "../resources/templates/user_input.html" [:form]
[method action content] [method action content]
[:form] [:form]
(do-> (set-attr :action action (do-> (set-attr :action action
Expand All @@ -78,7 +78,7 @@
(append (input "submit" "save" "saver" "Save Page")))) (append (input "submit" "save" "saver" "Save Page"))))


;page form has a hidden field for the template name ;page form has a hidden field for the template name
(defsnippet page-form "testify/templates/user_input.html" [:form] (defsnippet page-form "../resources/templates/user_input.html" [:form]
[method action template content] [method action template content]
[:form] [:form]
(do-> (set-attr :action action (do-> (set-attr :action action
Expand All @@ -87,7 +87,7 @@
(prepend (input "hidden" "template" "passer" template)) (prepend (input "hidden" "template" "passer" template))
(append (input "submit" "save" "saver" "Save Page")))) (append (input "submit" "save" "saver" "Save Page"))))


(defsnippet input-row "testify/templates/user_input.html" (defsnippet input-row "../resources/templates/user_input.html"
;take the typeclass and the name, plug in into an inputrow ;take the typeclass and the name, plug in into an inputrow
;TODO Have typing pick which field (textarea or which input) we pull ;TODO Have typing pick which field (textarea or which input) we pull
;TODO Give ajaxified validation based on typeclass to the user ;TODO Give ajaxified validation based on typeclass to the user
Expand Down
2 changes: 2 additions & 0 deletions src/testify/core.clj
Expand Up @@ -5,6 +5,8 @@
[testify.debug :as debug] [testify.debug :as debug]
[testify.routes :as routes])) [testify.routes :as routes]))


;;This main is used from a Java environment (lein run)
;;lein-ring's main is specified in project.clj
(defn -main [] (defn -main []
(let [port (System/getenv "PORT")] (let [port (System/getenv "PORT")]
(if port (if port
Expand Down
14 changes: 10 additions & 4 deletions src/testify/process/fileops.clj
Expand Up @@ -2,7 +2,13 @@


;;differentiate cloud foundry & other paths by env variable ;;differentiate cloud foundry & other paths by env variable
(defn real-dir [relpath] (defn real-dir [relpath]
(let [testifydir (. System getenv "TESTIFYDIR") ] (let [testifyenv (. System getenv "TESTIFYDIR")
(cond (nil? testifydir) userdir (.. System (getProperties) (get "user.dir"))]
(str "/resources/" relpath) (cond (nil? testifyenv)
:else (str testifydir "/" relpath)))) (str userdir "/resources/" relpath)
:else (str userdir testifyenv "/" relpath))))

(defn find-template
"given a template filename, return the full path to the template"
[tname]
(real-dir (str "templates/" tname)))
7 changes: 5 additions & 2 deletions src/testify/process/transform.clj
Expand Up @@ -67,7 +67,7 @@
(defn process-fname (defn process-fname
"Take a function name string and return the appropriate Clojure symbol" "Take a function name string and return the appropriate Clojure symbol"
[fname] [fname]
(load-string (str "html/" (.trim fname)))) (load-string (str "net.cgrand.enlive-html/" (.trim fname))))


(defn single-transform (defn single-transform
"take one user-script transformation statement and apply it to the given HTML nodes" "take one user-script transformation statement and apply it to the given HTML nodes"
Expand Down Expand Up @@ -99,7 +99,10 @@
(defn bulk-transform (defn bulk-transform
"apply a user transformation from the specified transform file to the the specified HTML file" "apply a user transformation from the specified transform file to the the specified HTML file"
[#^java.lang.String html #^java.lang.String transform ] [#^java.lang.String html #^java.lang.String transform ]
(apply str (html/emit* (make-transform (html/html-snippet (slurp html)) (slurp transform))))) (apply str (html/emit* (make-transform (html/html-snippet (slurp (fileops/find-template html))) (slurp (fileops/find-template transform))))))

;;TODO: code generic bulk and specific file or redis string retrieval



;;;;Testing/debugging ;;;;Testing/debugging


Expand Down
2 changes: 1 addition & 1 deletion src/testify/views/page.clj
Expand Up @@ -21,7 +21,7 @@
;;use the ids to populate a linklist ;;use the ids to populate a linklist
;;TODO: switch this to use template context ;;TODO: switch this to use template context
;;(link-base nil "Add Page?" "/template" (linknodes pagelist "/page/view?pname=")) ;;(link-base nil "Add Page?" "/template" (linknodes pagelist "/page/view?pname="))
(bulk-transform "../templates/base.html" "../templates/main.tr"))) (bulk-transform "base.html" "main.tr")))




(defn form-page [template] (defn form-page [template]
Expand Down

0 comments on commit 0543ce7

Please sign in to comment.