From d311826df5bf8c232e511cf79d382000f36f4db1 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 13 Sep 2014 20:45:15 +0100 Subject: Refactor parsers using expression-threading --- src/microformats/parser.clj | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index 94f0110..764594e 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -87,26 +87,38 @@ (defn parse-p "Parse p-* classes within HTML element." [element] - (let [value (get-p-value element)] - (into {} (r/map #(hash-map % value) ((classes-to-props "p-") (element-to-classes element)))))) + (->> element + element-to-classes + ((classes-to-props "p-")) + (r/map #(hash-map % (get-p-value element))) + (into {}))) (defn parse-u "Parse u-* classes within HTML element" [element] - (let [value (get-u-value element)] - (into {} (r/map #(hash-map % value) ((classes-to-props "u-") (element-to-classes element)))))) + (->> element + element-to-classes + ((classes-to-props "u-")) + (r/map #(hash-map % (get-u-value element))) + (into {}))) (defn parse-dt "Parse dt-* classes within HTML element" [element] - (let [value (get-dt-value element)] - (into {} (r/map #(hash-map % value) ((classes-to-props "dt-") (element-to-classes element)))))) + (->> element + element-to-classes + ((classes-to-props "dt-")) + (r/map #(hash-map % (get-dt-value element))) + (into {}))) (defn parse-e "Parse e-* classes within HTML element" [element] - (let [value (get-e-value element)] - (into {} (r/map #(hash-map % value) ((classes-to-props "e-") (element-to-classes element)))))) + (->> element + element-to-classes + ((classes-to-props "e-")) + (r/map #(hash-map % (get-e-value element))) + (into {}))) (defn parse-children "Parse element children for microformats" @@ -115,7 +127,7 @@ (html/attr-starts :class "u-") (html/attr-starts :class "dt-") (html/attr-starts :class "e-")])]))] - (hash-map :properties (merge (parse-p el) (parse-u el))))) + (hash-map :properties (merge ((juxt parse-p parse-u parse-dt parse-e)))))) (defn parse-h "Parse h-* classes within a HTML document." -- cgit 1.4.1