Feel free to add a link to this on the Ring wiki:
https://github.com/mmcgrana/ring/wiki/Third-Party-Libraries
- James
[snip]
Dieter is ring middleware which concatenates javascript and css files
into one file with optional minification. It also has a couple of
precompilers built in for turning less.js into css, and handlebars.js
files into javascript. More can be added but I haven't had the need
for others yet...
Maybe someone else will find this useful. If so, the package is on
http://clojars.org/dieter and the code is at https://github.com/edgecase/dieter.
Hi John. Thanks for giving Dieter a try. I don't come from a Java
background so I'm definitely open to suggestions on how to handle this
case. My initial thought is that we can add support for loading assets
from the system resource path. Then we create a lein task to
pre-compile your assets when building the uberjar. Thoughts?
-John
You could make the assets just normal Java resources, and the
preprocessors as standard Ring middleware. That would be a more
idiomatic approach, I think.
- James
I'm guessing that in the deployment strategy of deploying an uberjar
(presumably to tomcat or similar application server) would prevent us
from writing files to the filesystem. Is this a correct assumption?
If we can't write files we're left with 2 options
1. Cache the final asset in memory
2. Precompile the assets into Java resources as part of uberjar
creation. Serve those resources directly via file middleware.
James, If I understand your suggestion correctly, you would advocate for the
memory cache. It would probably be the easier option for me to
implement as well, but I want to understand the resource picture a
little better. Is it discouraged to build resources at deploy-time?
-John
That's not quite what I'm saying.
Caching and compiling are two separate problems. A cache does not need
to know what it is caching, and a compiler does not need to know it is
being cached.
Idiomatic Clojure is about reducing a complex problem to simple
components. In this case, I think you need to separate out compiling
and caching.
For example:
(-> handler
wrap-coffeescript
(wrap-cache (file-cache "/var/cache/myapp))
The cache could be in memory, or a location on disk, or some external
system like S3. Caching to a file on disk isn't forbidden, so long as
the web app has read/write access to the directory you supply.
- James
- James
I'd love to tell you my background is different, but... :-)
Being able to load assets from Java resources would be nice, and it
probably the bit I'm most concerned about. I can give it a place on
disk to store data for the actual cache it a production system. I
also like James's suggestion of making the preprocessors standard
middleware too (I only care about the less preprocessor for now).
-John
-John
(ns lorem.ipsum.test
(:use clojure.test)
(:use midje.sweet)
(:require [noir.validation :as vali]))
;then I added this
(declare ^:dynamic *errors*)
(def good-item {:title "pass!" :body "this should pass"})
(def bad-item {:title "this should fail" :body ""})
;stolen from noir-blog
(defn lorem-valid? [{:keys [title body]}]
(vali/rule (vali/has-value? title)
[:title "There must be a title"])
(vali/rule (vali/has-value? body)
[:body "There's no post content."])
(not (vali/errors? :title :body)))
(facts
;neither this
(lorem-valid? good-item)) => nil
;nor this worked
(binding [^:dynamic *errors* (atom {})]
(lorem-valid? good-item)) => nil
)
They printed out these:
java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast
to clojure.lang.IDeref
noir.validation$get_errors.invoke(validation.clj:48)
and of course a lot of error lines following.
I find myself using send-request more often (also in noir.util.test).
I have also been having a lot of fun testing my validation through the
routes with my test2 harness. This makes testing a bit more
declarative (avoiding things like managing bindings and introducing
mini state management like you're having to do with your tests there,
Hoàng Minh Thắng)
It's here:
https://github.com/nickbauman/noir.util.test2
By the way, there is nothing wrong with testing on a lower level, like
you are, Hoàng Minh Thắng. Chris and I are just pointing out other
ways of doing it.