From abce14ea6914678045a0d69adf182e5a2d5b5ee1 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 24 Sep 2014 18:51:15 +0100 Subject: Extract mf property element selection into methods --- src/microformats/parser.clj | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index 03e543f..4706992 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -222,15 +222,27 @@ :url (list (parse-implied-url element)) :photo (list (parse-implied-photo element))}))) +(defn- select-p + [element] (html/select element [(html/attr-contains :class "p-")])) + +(defn- select-u + [element] (html/select element [(html/attr-contains :class "u-")])) + +(defn- select-dt + [element] (html/select element [(html/attr-contains :class "dt-")])) + +(defn- select-e + [element] (html/select element [(html/attr-contains :class "e-")])) + (defn get-mf-properties "Parse children of a microformat, returning a map of properties" [element] (let [cappend (partial merge-with concat)] (merge (parse-implied element) - (apply cappend (map parse-p (html/select element [(html/attr-contains :class "p-")]))) - (apply cappend (map parse-u (html/select element [(html/attr-contains :class "u-")]))) - (apply cappend (map parse-dt (html/select element [(html/attr-contains :class "dt-")]))) - (apply cappend (map parse-e (html/select element [(html/attr-contains :class "e-")])))))) + (apply cappend (map parse-p (select-p element))) + (apply cappend (map parse-u (select-u element))) + (apply cappend (map parse-dt (select-dt element))) + (apply cappend (map parse-e (select-e element)))))) (defn parse-h "Parse h-* classes within a HTML element." -- cgit 1.4.1