I am creating a noir webapp, and I need to dynamically create new views and models. I've been following the noir examples, in which the view and the controller for a resource have separate namespaces, and I've found it to be a very clean approach.
In keeping with this, I need to be able to dynamically create new namespaces corresponding to views and models, and then intern the appropriate functions in them. My idea was to have macros specified in a separate namespace which, when called in the new namespace, would provide the appropriate routes/partials/whatever.
For example (forgive my first defmacro):
(ns project.views.proto
(:use noir.core
hiccup.core
hiccup.element
hiccup.form))
(defmacro def-all-page
[path]
`(defpage ~path []
(html
[:h1 "Ya'll here"])))
is called from...
(ns project.proto
(:use [clojure.contrib.with-ns :only [with-ns]])
(create-ns 'foo)
(intern 'foo 'path "path") ; In reality, the path is dynamic which is why I intern it
(with-ns 'foo
(clojure.core/refer-clojure)
(use 'noir.core
'hiccup.core
'hiccup.element
'[project.views.proto :only [def-all-page]])
(def-all-page path)
However, calling this from within my new namespace gives me a NullPointerException. I'd greatly appreciate any help, and whether or not there is a better approach. Like, just using refer for a namespace which contains all the necessary definitions?
First post, and I don't think it's a repeat of this. Thanks!