Ring middleware to automatically compile and regenerate your cssgen stylesheets. Works well with Compojure and Noir. Very much still in alpha.
Add the following to your project.clj
:
:dependencies [[ring-cssgen "0.0.1-SNAPSHOT"]]
First off, create your cssgen stylesheets and throw them in a common namespace,
something like yourapp.css.design
works well. Here's the important part, be sure to
return your css from the -main
function.
(ns yourapp.css.design
(:use cssgen))
(defn -main []
(css
[:body
:color "blue"]))
Now you can use the wrap-cssgen
middleware with your ring application.
wrap-cssgen
takes one additional argument, a predicate which receives the
request and determines whether it is a legal CSS resource. As a conveniece
a default predicate is included which may be used, css-req?
. It simply checks
if the URI begins with /css
and ends with .css
.
(ns yourapp.server
(:require [ring.middleware.cssgen :as [cssgen]]))
(def app
(-> your-handler
(cssgen/wrap-cssgen cssgen/css-req?)))
When /css/design.css
is requested from the server, that URI is mapped to the
yourapp.css.design
namespace. It will then be automatically generated and
written to disk.
Similarly, if /beer/lol.css
is requested, that URI is mapped to the
yourapp.beer.lol
namespace.
Requesting a CSS resource runs code, potentially unsafe. Be sure you provide a restrictive predicate.
Run the specs with leiningen: lein spec
ring-cssgen is distributed under the Eclipse Public License, the same as Clojure.