about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2014-09-13 20:45:15 +0100
committerAlan Pearce2014-09-13 20:45:15 +0100
commitd311826df5bf8c232e511cf79d382000f36f4db1 (patch)
tree6ada3febfd4df0d294e1bef6119ddb48bfd558b2 /src
parent5814a6cadbd6f6ca36398806197d458730686e03 (diff)
downloadmicroformats-d311826df5bf8c232e511cf79d382000f36f4db1.tar.lz
microformats-d311826df5bf8c232e511cf79d382000f36f4db1.tar.zst
microformats-d311826df5bf8c232e511cf79d382000f36f4db1.zip
Refactor parsers using expression-threading
Diffstat (limited to 'src')
-rw-r--r--src/microformats/parser.clj30
1 files changed, 21 insertions, 9 deletions
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."