EzDevInfo.com

compojure

A concise routing library for Ring/Clojure

How Can I Output an HTML Comment in Compojure/Hiccup?

I'd like my program to output the following HTML:

<!--[if lt IE 8]><link rel="stylesheet" rel='nofollow' href="../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->

Is there a way to output html comment literals with Hiccup?


Source: (StackOverflow)

Compojure development without web server restarts

I've written a small Swing App before in Clojure and now I'd like to create an Ajax-style Web-App. Compojure looks like the best choice right now, so that's what I'm going to try out.

I'd like to have a real tiny edit/try feedback-loop, so I'd prefer not to restart the web server after each small change I do.

What's the best way to accomplish this? By default my Compojure setup (the standard stuff with ant deps/ant with Jetty) doesn't seem to reload any changes I do. I'll have to restart with run-server to see the changes. Because of the Java-heritage and the way the system is started etc. This is probably perfectly normal and the way it should be when I start the system from command-line.

Still, there must be a way to reload stuff dynamically while the server is running. Should I use Compojure from REPL to accomplish my goal? If I should, how do I reload my stuff there?


Source: (StackOverflow)

Advertisements

Serve index.html at / by default in Compojure

I have a static file called index.html that I'd like to serve when someone requests /. Usually web servers do this by default, but Compojure doesn't. How can I make Compojure serve index.html when someone requests /?

Here's the code I'm using for the static directory:

; match anything in the static dir at resources/public
(route/resources "/")

Source: (StackOverflow)

How to write multilingual applications in Clojure?

I'm trying to figure out how to create a Compojure-based web-site with multilingual support. Is there any solutions like i18n or something like that?


Source: (StackOverflow)

noir vs compojure?

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/.


Source: (StackOverflow)

What's the "big idea" behind compojure routes?

I'm new to Clojure and have been using Compojure to write a basic web application. I'm hitting a wall with Compojure's defroutes syntax, though, and I think I need to understand both the "how" and the "why" behind it all.

It seems like a Ring-style application begins with an HTTP request map, then just passes the request through a series of middleware functions until it gets transformed into a response map, which gets sent back to the browser. This style seems too "low level" for developers, thus the need for a tool like Compojure. I can see this need for more abstractions in other software ecosystems as well, most notably with Python's WSGI.

The problem is that I don't understand Compojure's approach. Let's take the following defroutes S-expression:

(defroutes main-routes
  (GET "/"  [] (workbench))
  (POST "/save" {form-params :form-params} (str form-params))
  (GET "/test" [& more] (str "<pre>" more "</pre>"))
  (GET ["/:filename" :filename #".*"] [filename]
    (response/file-response filename {:root "./static"}))
  (ANY "*"  [] "<h1>Page not found.</h1>"))

I know that the key to understanding all of this lies within some macro voodoo, but I don't totally understand macros (yet). I've stared at the defroutes source for a long time, but just don't get it! What's going on here? Understanding the "big idea" will probably help me answer these specific questions:

  1. How do I access the Ring environment from within a routed function (e.g. the workbench function)? For example, say I wanted to access the HTTP_ACCEPT headers or some other part of the request/middleware?
  2. What's the deal with the destructuring ({form-params :form-params})? What keywords are available for me when destructuring?

I really like Clojure but I am so stumped!


Source: (StackOverflow)

how does one _model_ data from relational databases in clojure?

I have asked this question on twitter as well the #clojure IRC channel, yet got no responses.

There have been several articles about Clojure-for-Ruby-programmers, Clojure-for-lisp-programmers.. but what is the missing part is Clojure for ActiveRecord programmers .

There have been articles about interacting with MongoDB, Redis, etc. - but these are key value stores at the end of the day. However, coming from a Rails background, we are used to thinking about databases in terms of inheritance - has_many, polymorphic, belongs_to, etc.

The few articles about Clojure/Compojure + MySQL (ffclassic) - delve right into sql. Of course, it might be that an ORM induces impedence mismatch, but the fact remains that after thinking like ActiveRecord, it is very difficult to think any other way.

I believe that relational DBs, lend themselves very well to the object-oriented paradigm because of them being , essentially, Sets. Stuff like activerecord is very well suited for modelling this data. For e.g. a blog - simply put

class Post < ActiveRecord::Base
  has_many :comments
 end


 class Comment < ActiveRecord::Base
   belongs_to :post
 end

How does one model this in Clojure - which is so strictly anti-OO ? Perhaps the question would have been better if it referred to all functional programming languages, but I am more interested from a Clojure standpoint (and Clojure examples)


Source: (StackOverflow)

Using Clojure with Vaadin

Has anyone tried implementing a web application with Clojure ( using Compojure ) and Vaadin ? I had seen an article on using Clojure with JWT for creating web apps. Vaadin is based on GWT so you get a lot of the advantages of GWT ( though Vaadin is completely Server-centric). And Clojure gives the advantage that you can use any Java Based Framework, so what thoughts on the Clojure + Vaadin based web application ?


Source: (StackOverflow)

Escape/sanitize user input in Clojure/Compojure

I am using Clojure/Ring/Compojure-0.4/Enlive stack to build a web application.

Are there functions in this stack that would either strip HTML or HTML-encode (i.e. <a> to &lt;a&gt;) user-supplied strings in order to prevent XSS attacks?


Source: (StackOverflow)

Compojure or Noir for a UI-less webservice?

If one is planning to create a UI-less web service (receives JSON and/or XML, returns JSON and/or XML), does Noir provide anything useful over and above Compojure?


Source: (StackOverflow)

How do you use sessions with Compojure/Ring?

I'm developing a web application using Compojure and I would hugely appreciate a small and complete example of storing and retrieving session data.

Many thanks in advance, James.


Source: (StackOverflow)

webjure vs compojure?

I've heard of two Clojure based web application frameworks: Webjure and Compojure. Can someone let me know which is better?


Source: (StackOverflow)

Good current documentation and/or tutorials for compojure/ring development?

As far as I can tell 90% of information that can be found through a google search on compojure/ring is outdated for 0.4.0.

Can anyone point me toward some good current documentation?

Thanks!


Source: (StackOverflow)

How to find a web hosting service for running Compojure

I am very interested in building a website using Clojure and Compojure, like so:

http://briancarper.net/blog/deploying-clojure-websites

However, due to my limited experience with the Java environment and Java culture, I am not sure where to begin when shopping for a web-hosting service.

Do I simply need to find a service that gives me full root access and has the JDK/JVM? Or are there other requirements as well?


Source: (StackOverflow)

Clojure web framework for designers/ front end devs [closed]

All of the popular Clojure web frameworks I am seeing use hiccup to generate HTML. I find hiccup is hard to have a front end design person adjust to, compared to other frameworks that parse the syntax out of templates.

Is there a clojure web framework that doesn't require the front end developer to learn LISP?


Source: (StackOverflow)