noir.core documentation

Functions to work with partials and pages.

compojure-route

(compojure-route compojure-func)
Adds a compojure route fn to the end of the route table. These routes are queried after
those created by defpage and before the generic catch-all and resources routes.

These are primarily used to integrate generated routes from other libs into Noir.

custom-handler

(custom-handler & args)
Adds a handler to the end of the route table. This is equivalent to writing
a compojure route using noir's [:method route] syntax.

(custom-handler [:post "/login"] {:as req} (println "hello " req))
=> (POST "/login" {:as req} (println "hello" req))

These are primarily used to interface with other handler generating libraries, i.e. async aleph handlers.

custom-handler*

(custom-handler* route func)
Adds a handler to the end of the route table. This is equivalent to writing
a compojure route using noir's [:method route] syntax, but allows functions
to be created dynamically:

(custom-handler* [:post "/login"] (fn [params] (println req)))

These are primarily used to interface with other dynamic handler generating libraries

defpage

(defpage & args)
Adds a route to the server whose content is the the result of evaluating the body.
The function created is passed the params of the request and the destruct param allows
you to destructure that meaningfully for use in the body.

There are several supported forms:

(defpage "/foo/:id" {id :id})  an unnamed route
(defpage [:post "/foo/:id"] {id :id}) a route that responds to POST
(defpage foo "/foo:id" {id :id}) a named route
(defpage foo [:post "/foo/:id"] {id :id})

The default method is GET.

defpartial

(defpartial fname params & body)
Create a function that returns html using hiccup. The function is callable with the given name.

post-route

(post-route & args)
Adds a route to the end of the route table and passes the entire request to
be desctructured and used in the body. These routes are guaranteed to be
evaluated after those created by defpage and before the generic catch-all and
resources routes.

pre-route

(pre-route & args)
Adds a route to the beginning of the route table and passes the entire request
to be destructured and used in the body. These routes are the only ones to make
an ordering gaurantee. They will always be in order of ascending specificity (e.g. /* ,
/admin/* , /admin/user/*) Pre-routes are usually used for filtering, like redirecting
a section based on privileges:

(pre-route '/admin/*' {} (when-not (is-admin?) (redirect '/login')))

render

(render route & [params])
Renders the content for a route by calling the page like a function
with the given param map. Accepts either '/vals' or [:post '/vals']

url-for

(url-for route & [arg-map])
given a named route, i.e. (defpage foo "/foo/:id"), returns the url for the
route. If the route takes arguments, the second argument must be a
map of route arguments to values

(url-for foo {:id 3}) => "/foo/3"