Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns app.core
  2.   (require [clojure.string :as str]
  3.            [clojure.walk :as walk]
  4.            [clj-time.core :as t]
  5.            [com.stuartsierra.component :as component]
  6.            [clojure.core.matrix :as matrix]
  7.            [clojure.data.json :as json]
  8.            [org.httpkit.client :as http]
  9.            [clatrix.core :as clatrix]
  10.            [hiccup.core :refer :all]
  11.            [pl.danieljanus.tagsoup :refer :all]
  12.            [clojure.core.async :refer [go <! >! timeout chan]])
  13.   (:import (java.io File FileOutputStream)))
  14.  
  15. (def +path+ "resources/svg/")
  16.  
  17. (defn- list-svgs [path]
  18.   (let [files (file-seq (clojure.java.io/file path))
  19.         files (map #(-> {:name (.getName %)
  20.                          :path (.getAbsolutePath %)})
  21.                    files)
  22.         svg-files (filter #(str/ends-with? (:name %) ".svg") files)
  23.         svg-files (map #(assoc % :contents (slurp (:path %))) svg-files)]
  24.     (into [] svg-files)))
  25.  
  26. (defn- svg-to-hiccup [file]
  27.   (assoc file :contents (parse-string (:contents file))))
  28.  
  29. (defn- svgs-to-hiccup [files]
  30.   (map svg-to-hiccup files))
  31.  
  32. (defn get-svgs [path]
  33.   (svgs-to-hiccup (list-svgs path)))
  34.  
  35. (defn create-inline-svg [path inclusion-set]
  36.   (let [svgs (get-svgs path)
  37.         filtered-svgs (filter #(inclusion-set (:name %)) svgs)]
  38.     (apply conj [:div {:display "none"}]
  39.       (into [] (map :contents filtered-svgs)))))
  40.  
  41. (defmacro inline-svg [path inclusion-set]
  42.   `(let [svg# (create-inline-svg ~path ~inclusion-set)]
  43.      svg#))
  44.  
  45. (println (inline-svg +path+ #{"bussi-24.svg"}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement