On 13 June 2010 14:20, Matt <macourt...@gmail.com> wrote:
> Yesterday morning, I took one more look at Leiningen for Conjure.
> After a few false starts and build hacking, I had exactly the same
> idea for a Conjure plugin for Leiningen. I've started breaking Conjure
> into two jars, conjure.jar which will be all the base libraries for
> Conjure, and lein-conjure.jar which will be the Conjure Leiningen
> plugin.

That sounds good!

> I checked out clout, and found I couldn't use it. Maybe I don't know
> exactly how it works, but I would like to define routes with something
> like Rails old "/:controller/:action/:id", but clout seemed to require
> something more like "/book/:id" where book would then be hard coded to
> the book controller and the action could be figured out from the
> request method. Though this is somewhat closer to how Rails works now,
> it isn't very useful for me. Am I missing something, or is that how
> you designed it? How would the Rails route: "/book/1/edit" work?

I think you're missing something :)

Clout is a very low level library. It matches routes using a
Rails-like routing syntax, but it doesn't do anything more than that.
You can match routes like "/book/:id", but you can also match routes
like "/:controller/:action/:id".

user=> (use 'clout.core)
nil
user=> (route-matches "/:controller/:action/:id" "/book/edit/1")
{"id" "1", "action" "edit", "controller" "book"}

It uses strings instead of keywords, because that ties into Ring
parameters better. I may change this in future to keywords; I'm not
sure which is best at the moment.

In any case, you could write a Ring handler function something like this:

(defvar- main-route
  (route-compile "/:controller/:action/:id"))

(defn conjure-handler [request]
  (if-let [route-params (route-matches main-route request)]
    (let [params (merge (request :params) route-params)
          action (find-action (params "controller") (params "action"))
          request (assoc request :params params)]
      (run-action action request))
    (page-not-found request)))

Using this scheme, you get similar behaviour to Rails, and it opens up
the possibility of custom routes.

- James

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to