magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Examples using selmer? #32

Closed andyparsons closed 9 years ago

andyparsons commented 9 years ago

Wondering if there are any examples using optimus asset loaders in a luminus/selmer project? We are keen to try optimus but struggling to wire everything up!

magnars commented 9 years ago

I don't have any experience with luminus or selmer, but I would be happy to answer any questions you have. What have you tried? Do these frameworks expose the Ring middleware stack somewhere?

andyparsons commented 9 years ago

Luminus makes us of ring and compojure, so yes. Selmer is a Django-like templating library into which I'd like to inject Optimus asset URLs. Let me poke around further and come back with a very specific issue. Thanks!

andyparsons commented 9 years ago

For example, this view function should render the bundle output into the Selmer template (the bracketed content is simply passed into the template). But, this actually outputs the string "clojure.lang.LazySeq@1" so we must be missing a step somewhere.

(defn style-guide [request]
  (layout/render
    "admin/styleguide.html" 
    {:page-style (optimus.hiccup/link-to-css-bundles request ["app.css"])}))
magnars commented 9 years ago

Ah yes, that is a bit convoluted if you're not using hiccup. In fact, I've been meaning to change it to be less hiccup-specific. I'll fix that on the train home, and push a new version.

If you want to have it working straight away, include hiccup in your project [hiccup "1.0.4"] then require [hiccup.core :refer [html]] and do:

(defn style-guide [request]
  (layout/render
    "admin/styleguide.html" 
    {:page-style (html (optimus.hiccup/link-to-css-bundles request ["app.css"]))}))
andyparsons commented 9 years ago

Ah, of course Dumb mistake not to get the HTML out of hiccup. Thanks. FWIW, more friendliness to Selmer, which is the default templating engine in Luminus would be great for adoption. I think Optimus' approach and flexibility is superior by far to the other options out there.

magnars commented 9 years ago

Glad to hear that. :) I wouldn't call it a dumb mistake as much as a dumb API. I'll get a new version out soon.

magnars commented 9 years ago

I've released [optimus "0.17.0"], which removes the optimus.hiccup namespace in favor of optimus.html.

The old optimus.hiccup/link-to-css-bundles created hiccup data structures, which is a mistake. It's specific to one rendering method, and Hiccup works just as well (or better) with strings.

You can replace optimus.hiccup with optimus.html, remove hiccup, and all should be well. :)

andyparsons commented 9 years ago

@magnars thanks for the super-fast update! Trying it now and will report back if any questions pop up.

magnars commented 9 years ago

This one had been brewing for a while, so thanks for giving me the proper incentive to do something about it. :)

andyparsons commented 9 years ago

Great. Note I removed my last note here, the issue was unrelated to your recent change.