Skip to content

Commit

Permalink
Added layouts.
Browse files Browse the repository at this point in the history
Added a layouts directory to view, and added a default application.clj layout.
Changed render-view in controller base.clj to a multimethod, and added an optional parameters map.
  • Loading branch information
Matt Courtney committed Aug 10, 2009
1 parent 6783168 commit 203b485
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
1 change: 0 additions & 1 deletion file_structure/default/app/views/ReadMe.txt

This file was deleted.

9 changes: 9 additions & 0 deletions file_structure/default/app/views/layouts/application.clj
@@ -0,0 +1,9 @@
(ns views.layouts.application
(:use conjure.view.base)
(:require [clj-html.core :as html]))

(defview [body]
(html/html
[:html
[:body
body]]))
4 changes: 1 addition & 3 deletions file_structure/default/script/generators/view_generator.clj
Expand Up @@ -22,9 +22,7 @@ added to the body of the view code."}
(defview []
(html/html
[:html
[:body
" inner-content "]]))"))
" inner-content "))"))

(defn
#^{:doc "Generates the view content and saves it into the given view file."}
Expand Down
20 changes: 14 additions & 6 deletions file_structure/default/vendor/conjure/controller/base.clj
Expand Up @@ -2,9 +2,17 @@
(:require [conjure.view.util :as view-util]))

(defn
#^{:doc "Renders the view given in the request-map."}
render-view [request-map & params]
(view-util/load-view request-map)
(apply
(eval (read-string (str (view-util/request-view-namespace request-map) "/render-view")))
request-map params))
#^{:doc "Determines the type of render-view called. Possible values: :request-map, :parameters."}
render-type? [request-map & params]
(if (and (contains? request-map :controller) (contains? request-map :action))
:request-map
:parameters))

(defmulti render-view "Renders the view given in the request-map." render-type?)

(defmethod render-view :request-map [request-map & params]
(apply render-view { :layout "application" } request-map params))

(defmethod render-view :parameters [parameters request-map & params]
(view-util/render-layout (:layout parameters) request-map
(apply view-util/render-view request-map params)))
17 changes: 16 additions & 1 deletion file_structure/default/vendor/conjure/view/util.clj
Expand Up @@ -49,4 +49,19 @@
#^{:doc "Returns the view namespace for the given view file."}
view-namespace [controller view-file]
(if (and controller view-file)
(view-namespace-by-action controller (loading-utils/clj-file-to-symbol-string (. view-file getName)))))
(view-namespace-by-action controller (loading-utils/clj-file-to-symbol-string (. view-file getName)))))

(defn
#^{:doc "Returns the rendered view from the given request-map."}
render-view [request-map & params]
(load-view request-map)
(apply
(eval (read-string (str (request-view-namespace request-map) "/render-view")))
request-map params))

(defn
#^{:doc "Returns the rendered layout for the given layout name."}
render-layout [layout-name request-map body]
(let [layouts-request-map (assoc request-map :controller "layouts")
application-request-map (assoc layouts-request-map :action (if layout-name layout-name "application"))]
(render-view application-request-map body)))

0 comments on commit 203b485

Please sign in to comment.