noir vs compojure?

你说的曾经没有我的故事 提交于 2019-12-04 09:01:29

问题


I'm having trouble understanding the point of clojure's Noir library. It seems to be a framework written on top of compojure that renames defroute to defpage and calls it a day. Obviously an unfair simplification, but what exactly does Noir bring to the table? Why would I use Noir instead of plain compojure+hiccup?

EDIT/UPDATE: Noir is deprecated, interesting write up here: http://blog.raynes.me/blog/2012/12/13/moving-away-from-noir/.


回答1:


Compojure is a small framework that generates Ring request/response handlers, where handlers are chosen based on routes you define.

Noir adds functionality for session handling, cookies, templates and partials, an easier way to generate responses, form validation, route filters, encrypted passwords, JSON (de-)serialising and custom status pages. In other words, Noir combines Compojure, Hiccup, and a bunch of other clever stuff in one package.




回答2:


From the author of Noir himself:

Noir isn't really a replacement for [compojure and hiccup], more of an abstraction over them. It was born out of seeing how a real web-app evolved and what was missing from the ring/compojure/hiccup stack as I built http://www.typewire.io. Also, as I mentioned in one of the other comments, I hope that it will serve as the single "package" to start with web development in Clojure, instead of having to try and cobble it together from the pieces that are out there now. By controlling all of it, I can create a much more cohesive and well defined story for helping people get started. I can also share what I've learned about maintaining websites in Clojure and hopefully encourage patterns that avoid some of the pits I fell into.

(emphasis mine)




回答3:


Noir, the framework has been deprecated by Noir maintener himself.

It suggests to use Compojure and lib-noir :

For new websites, please use Compojure and lib-noir. This is pretty much just as batteries included as Noir itself ever was! You just have to learn how to write routes with Compojure. It’s easy and just as concise as it was in Noir. You don’t have to use ring-jetty-adapter and stuff, just use the lein-ring plugin to start your server. Also, if you took advantage of Noir including hiccup by default, you’ll have to have an explicit dependency on it now. No biggy, right? Right!

  • Compojure
  • lib-noir



回答4:


You can always check the API on the webnoir.org website. There is a lot of added functionality besides defpage.



来源:https://stackoverflow.com/questions/9950056/noir-vs-compojure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!