State of 2.0

37 views
Skip to first unread message

Machiel Groeneveld

unread,
Nov 18, 2013, 3:55:31 PM11/18/13
to jo...@googlegroups.com
Joodo seems like a great bundling of existing frameworks like ring and compojure. Also nice to see version 2.0 is out!

I'd like to know how much of http://www.joodoweb.com/tutorial/basics information is still relevant. The main question is how/if to use controllers in 2.0. Also I'm guessing the 1.2 plugin doesn't work well with the new 2.0 version of the library itself.

Any pointers would be great, I will update anything I figure out.



Andrew Zures

unread,
Nov 18, 2013, 10:06:08 PM11/18/13
to jo...@googlegroups.com
Hi Machiel,

There have been some tweaks to the way Joodo 2.0 uses controllers.  

In the 1.2 version, the controller syntax in your core.clj file is something like "(controller-router 'file_path.controller_folder)" which is found within the "(defroutes <web-routes>)" function.

In 2.0, each controller should be called in your core.clj file using the refresh middleware:  (refresh/handler 'namespace.more-namespace/top-level-controller-function) . The entire path to the controller file is necessary as well as the specific function.

For example, take the Joodoweb application itself:

an example of the old code is:

(defroutes joodoweb-routes
         (controller-router 'joodoweb.controller)
)

an example of the new code is:

(defroutes joodoweb-routes
          (refresh/handler 'joodoweb.controller.docs-controller/docs-controller)
          (refresh/handler 'joodoweb.controller.tutorial-controller/tutorial-controller)
)

note how each controller file must be included with its full namespace and top level function.  You'll also have to add the refresh middleware to you namespace dependencies.  In this example I've added it with the pseudonym "refresh":

(ns my-app.core
   (:require 
    [joodo.middleware.refresh :as refresh])
)

for the receiving method of each controller, nothing should have changed since version 1.2.  However an example as we use it is below:

(defroutes docs-controller
   (GET "/docs" [] (redirect "docs/index"))
   (context "/docs" []
     (GET "/index" [] (render-template "docs/index")))
)

As to your question about the joodoweb tutorial, we hope to have it updated in the next week or so.

Hopefully that helps.  Let me know if you need any additional help or if you have any other questions about Joodo.

Andrew Zures

unread,
Nov 19, 2013, 10:46:13 AM11/19/13
to jo...@googlegroups.com
Hi Machiel,

Joodo 2.0 controllers work a bit differently than in the 1.2 version.

In the 1.2 version, your core.clj file, with your top level routes, was probably something like this:

(defroutes my-routes
      (controller-router 'joodoweb.controller)
)

in the 2.0 version, Joodo uses its refresh middleware and each controller must be listed.  First, add the joodo.middleware.refresh to your namespace dependencies:

(ns my-namespace
   (:require 
        [joodo.middleware.refresh :as refresh])
)

Second, call the "refresh/handle" function in your defroutes for each controller, using the complete controller namespace and top level function. For example, joodoweb has two controllers and has the syntax below:

(defroutes my-routes
        (refresh/handler 'joodoweb.controller.docs-controller/docs-controller)
        (refresh/handler 'joodoweb.controller.tutorial-controller/tutorial-controller)
)

A sample of what is found inside one of the controllers namespace is below.  The controller namespace haven't changed, so all you should need is the change to "refresh" noted above.

(defroutes docs-controller
  (GET "/docs" [] (redirect "docs/index"))
  (context "/docs" []
    (GET "/index" [] (render-template "docs/index")))
  )

Also, the Joodo plugin is no longer used in Joodo 1.2.  Joodo instead runs on top of ring, so running 'leing ring server" should bring up the app.  Also note that the default port for Joodo 1.2 was 8080 but Joodo 2.0 uses ring so the port will be 3000.

Let me know if you have any other additional questions.  We're currently updating the joodoweb tutorial to reflect the new Joodo changes.

On Monday, November 18, 2013 2:55:31 PM UTC-6, Machiel Groeneveld wrote:
Reply all
Reply to author
Forward
0 new messages