ganelon.web.dyna-routes documentation

This names provides the equivalent of webnoir's defpage/add-middleware macros.
What is does, is to essentially provide dynamic list of routes and ability to define
multiple routes in many definition files.

The route paths should not overlap here, and default routes (files, not-found, etc.) should be set explicitly.

It is entirely possible to access other features of Ganelon without using dyna-routes. Or just use dyna-routes
and skip other features.

default-routes-fn

(default-routes-fn)
Return ring handler with middleware and routes registered for a :default namespace.

Example usage:

(compojure.core/ANY "/*" []
  (-> (ganelon.web.dyna-routes/default-routes-fn)
    wrap-fake-admin)))

defpage

macro

(defpage path args & body)
Macro inspired by Noir's defpage, but with a full access to Compojure's parameters support.
Registers route for a provided path and parameters using compojure.core/ANY macro in a :default namespace.

Example usage:

(ganelon.web.dyna-routes/defpage "/routing/sample" []
  "Hello world!")

defpage-ns

macro

(defpage-ns name-space path args & body)
Macro inspired by Noir's defpage, but with a full access to Compojure's parameters support.
Registers route for a provided path and parameters using compojure.core/ANY macro in a supplied namespace.

Example usage:

(ganelon.web.dyna-routes/defpage-ns :default "/routing/sample" []
  "Hello world!")

route-ns-fn

(route-ns-fn name-space)
Return ring handler for a namespace provided as a parameter. Then handler provides
all of the routes and middleware registered in a designated namespace.

Example usage:

(compojure.core/GET "/routing/sample5/*" []
  (-> (ganelon.web.dyna-routes/route-ns-fn :sample-admin)
      wrap-fake-admin)))

setmiddleware!

(setmiddleware! name mw)(setmiddleware! name-space name mw)
Register middleware in a namespace. When no namespace is provided, use :default namespace.

This feature is an alternative to classical approach with Ring handlers/middleware chain.

Middleware functions from a namespace can be referenced later on by route-ns-fn.

Example usage:

(dr/setmiddleware! :i18n-detect
  #(fn [request] (detect-lang % request)))

setroute!

(setroute! name route)(setroute! name-space name route)
Register route in a namespace. When no namespace is provided, use :default namespace.

Routes from a namespace can be referenced later on by route-ns-fn.

Example:

(setroute! :example2
  (compojure.core/GET "/routing/sample2" []
    "Hello world !!!"))