Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composable selector/transform in snippet #136

Open
SevereOverfl0w opened this issue Nov 6, 2015 · 1 comment
Open

Composable selector/transform in snippet #136

SevereOverfl0w opened this issue Nov 6, 2015 · 1 comment

Comments

@SevereOverfl0w
Copy link

I'm trying to make some pairs which can be reused easily within a snippet or template (the at form in general?)

I'm trying to handle setting values to their original value, when there is an error on the form, currently my code looks like:

(html/defsnippet form
  "templates/form.html" [:.container]
  [errors defaults] 
  [(html/attr= :name "name")] (html/set-attr :value (get defaults "name"))
  [(html/attr= :name "description")] (html/set-attr :value (get defaults "description"))
  [(html/attr= :name "image")] (html/set-attr :value (get defaults "image"))
  [:.errors] (html/content (pr-str errors)))

I'd like something a little more reusable, e.g.

(html/defsnippet form
  "templates/form.html" [:.container]
  [errors defaults]
  (somefn defaults ["name" "description" "image"])
  (somefn defaults "name") ;; Or this!
  [:.errors] (html/content (pr-str errors)))

I've tried returning a map from somefn, which didn't work, and I've been able to conjure up any other solution in it's place. I was hoping there might be some advice here?

@SevereOverfl0w
Copy link
Author

I've come up with something somewhat reusable, whereby I use a nested at, and apply run on every node, but less than ideal:

(defn gen-defaults
  [m k]
  (fn [node]
    (html/at node
      [(html/attr= :name k)] (html/set-attr :value value))))

(html/defsnippet form
  "templates/form.html" [:.container]
  [errors defaults]
  [:*] (gen-defaults defaults "name")
  [:.errors] (html/content (pr-str errors)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant