Skip to content

Instantly share code, notes, and snippets.

@jsnikeris
Created July 18, 2011 23:42
Show Gist options
  • Save jsnikeris/1090966 to your computer and use it in GitHub Desktop.
Save jsnikeris/1090966 to your computer and use it in GitHub Desktop.
(def *expected-selectors* [[:id] [:published] [:updated]
[[:link (e/attr= :rel "edit")]]
[[:link (e/attr= :rel "alternate")]]])
(def *entry-template* (e/xml-resource "templates/entry.xml"))
(defn normalize-entry [entry]
(e/transform entry [:entry]
(e/do->
(for [sel (filter #(empty? (e/select entry %)) *expected-selectors*)]
(e/append (e/select *entry-template* sel))))))
@jsnikeris
Copy link
Author

Here is a solution:

;; selectors of elements expected to be found on an Entry
(def *expected-selectors* [[:id] [:published] [:updated]
                           [[:link (e/attr= :rel "edit")]] 
                           [[:link (e/attr= :rel "alternate")]]])

(defn normalize-entry [entry]
  (e/transform entry [:entry]
    (e/append
     (for [sel (filter #(empty? (e/select entry %)) *expected-selectors*)]
       (e/select (e/xml-resource "templates/entry.xml") sel)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment