Skip to content

Commit

Permalink
use :private meta-data instead of defvar-
Browse files Browse the repository at this point in the history
  • Loading branch information
Takahiro Hozumi committed Jul 6, 2012
1 parent 15d50fb commit 5bcff6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
3 changes: 1 addition & 2 deletions project.clj
@@ -1,7 +1,6 @@
(defproject org.clojars.hozumi/hiccup-bridge "1.0.0-SNAPSHOT" (defproject org.clojars.hozumi/hiccup-bridge "1.0.0-SNAPSHOT"
:description "Hiccup to html, html to hiccup." :description "Hiccup to html, html to hiccup."
:dependencies [[org.clojure/clojure "1.2.0"] :dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.clojars.hozumi/clj-glob "0.1.0"] [org.clojars.hozumi/clj-glob "0.1.0"]
[org.clojars.hozumi/clj-det-enc "1.0.0-SNAPSHOT"] [org.clojars.hozumi/clj-det-enc "1.0.0-SNAPSHOT"]
[pattern-match "1.0.0"] [pattern-match "1.0.0"]
Expand Down
34 changes: 16 additions & 18 deletions src/leiningen/hicv.clj
Expand Up @@ -2,7 +2,6 @@
(:refer-clojure :exclude [pop!]) (:refer-clojure :exclude [pop!])
(:require [net.cgrand.enlive-html :as en] (:require [net.cgrand.enlive-html :as en]
[hiccup.core :as hic] [hiccup.core :as hic]
[clojure.contrib.def :as cdef :only [defvar-]]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.pprint :as pp] [clojure.pprint :as pp]
[hozumi.det-enc :as enc] [hozumi.det-enc :as enc]
Expand All @@ -12,9 +11,10 @@
[java.io StringReader PushbackReader [java.io StringReader PushbackReader
FileInputStream InputStreamReader LineNumberReader])) FileInputStream InputStreamReader LineNumberReader]))


(cdef/defvar- *clj-tag* :c--) (def ^{:private true} clj-tag :c--)
(cdef/defvar- *clj-attr-key* :clj) (def ^{:private true} clj-attr-key :clj)
(cdef/defvar- *attr-code-prefix* "clj--") (def ^{:private true} attr-code-prefix "clj--")
(def ^{:private true} hicv-dir-name "hicv/")


(defn- mk-tag [tag {:keys [class id]}] (defn- mk-tag [tag {:keys [class id]}]
(keyword (keyword
Expand Down Expand Up @@ -45,11 +45,11 @@
(reduce conj {} (reduce conj {}
(map (fn [[k v]] (map (fn [[k v]]
[(if-let [[_ c] (re-matches [(if-let [[_ c] (re-matches
(Pattern/compile (str *attr-code-prefix* "(.*)")) (Pattern/compile (str attr-code-prefix "(.*)"))
(name k))] (name k))]
(read-from-str c) k) (read-from-str c) k)
(if-let [[_ c] (re-matches (if-let [[_ c] (re-matches
(Pattern/compile (str *attr-code-prefix* "(.*)")) (Pattern/compile (str attr-code-prefix "(.*)"))
v)] v)]
(read-from-str c) v)]) attrs))) (read-from-str c) v)]) attrs)))


Expand All @@ -67,9 +67,9 @@
[tag attrs] [tag]) [tag attrs] [tag])
cnts (filter #(not (and (string? %) cnts (filter #(not (and (string? %)
(re-matches #"\n\s*" %))) content)] (re-matches #"\n\s*" %))) content)]
(if (and (= tag *clj-tag*) (if (and (= tag clj-tag)
(*clj-attr-key* attrs)) (clj-attr-key attrs))
(with-open [pbr (-> attrs *clj-attr-key* StringReader. PushbackReader.)] (with-open [pbr (-> attrs clj-attr-key StringReader. PushbackReader.)]
(let [s (read pbr)] (let [s (read pbr)]
(cond (cond
(seq? s) (into-it s cnts) (seq? s) (into-it s cnts)
Expand Down Expand Up @@ -130,18 +130,18 @@


(defn- attr-code [code] (defn- attr-code [code]
(with-out-str (with-out-str
(print *attr-code-prefix*) (print attr-code-prefix)
(pr code))) (pr code)))


(defn- hic2vec* [node] (defn- hic2vec* [node]
(condp #(%1 %2) node (condp #(%1 %2) node
seq? (reduce conj seq? (reduce conj
[*clj-tag* {*clj-attr-key* (clj-attr node)}] [clj-tag {clj-attr-key (clj-attr node)}]
(map hic2vec* (filter should-be-child? node))) (map hic2vec* (filter should-be-child? node)))
symbol? [*clj-tag* {*clj-attr-key* (str node)}] symbol? [clj-tag {clj-attr-key (str node)}]


html-node? (vec (map hic2vec* node)) html-node? (vec (map hic2vec* node))
vector? (reduce conj [*clj-tag* {*clj-attr-key* (clj-attr node)}] vector? (reduce conj [clj-tag {clj-attr-key (clj-attr node)}]
(map hic2vec* (filter should-be-child? node))) (map hic2vec* (filter should-be-child? node)))
map? (reduce conj {} map? (reduce conj {}
(map (fn [[k v]] (map (fn [[k v]]
Expand All @@ -156,10 +156,8 @@
(let [s (source2s fn-sym-or-s)] (let [s (source2s fn-sym-or-s)]
(hic2vec* s)))) (hic2vec* s))))


(cdef/defvar- *hicv-dir-name* "hicv/")

(defn- prepare-hicv-dir! [] (defn- prepare-hicv-dir! []
(let [f (io/file *hicv-dir-name*)] (let [f (io/file hicv-dir-name)]
(if-not (.exists f) (if-not (.exists f)
(.mkdir f)))) (.mkdir f))))


Expand All @@ -177,7 +175,7 @@


(defn- ns2filename [ns-str] (defn- ns2filename [ns-str]
(let [replaced (.replaceAll ns-str "/" ".")] (let [replaced (.replaceAll ns-str "/" ".")]
(str *hicv-dir-name* (str hicv-dir-name
replaced replaced
".html"))) ".html")))


Expand Down Expand Up @@ -232,7 +230,7 @@
(filter #(not (and (string? %) (filter #(not (and (string? %)
(re-matches #"\n\s*" %))) (re-matches #"\n\s*" %)))
(mapcat html2hic (if (empty? file-names) (mapcat html2hic (if (empty? file-names)
(-> *hicv-dir-name* io/file .listFiles) (-> hicv-dir-name io/file .listFiles)
file-names)))))) file-names))))))


(defn hicv (defn hicv
Expand Down

0 comments on commit 5bcff6d

Please sign in to comment.