Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update orchard.clojuredocs to use compact EDN file #68

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TEST_SELECTOR := :java$(JAVA_VERSION)
TEST_PROFILES := +test

test-resources/clojuredocs/export.edn:
curl -o $@ https://clojuredocs-edn.netlify.com/export.edn
curl -o $@ https://clojuredocs-edn.netlify.com/export.compact.edn

test: test-resources/clojuredocs/export.edn
lein with-profile +$(VERSION),$(TEST_PROFILES) test $(TEST_SELECTOR)
Expand Down
18 changes: 7 additions & 11 deletions src/orchard/clojuredocs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

(def cache (atom {}))
(def default-edn-file-url
"https://clojuredocs-edn.netlify.com/export.edn")
"https://clojuredocs-edn.netlify.com/export.compact.edn")
(def cache-file-name
(str/join os/file-separator [(os/cache-dir)
"orchard"
Expand All @@ -27,16 +27,12 @@
mkdirs)
(->> url slurp (spit cache-file-name)))

(defn- map-from-key [f coll]
(reduce #(assoc %1 (f %2) %2) {} coll))

(defn- load-cache-file! [cache-file]
(let [docs (-> cache-file slurp edn/read-string)]
(->> (:vars docs)
(group-by #(:ns %))
(reduce-kv #(assoc %1 %2 (map-from-key :name %3)) {})
(reset! cache))
true))
(->> cache-file
slurp
edn/read-string
(reset! cache))
true)

(defn load-cache!
"Load exported documents file from ClojureDocs, and store it as a cache.
Expand Down Expand Up @@ -82,4 +78,4 @@
(find-doc ns-name var-name default-edn-file-url))
([ns-name var-name export-edn-url]
(load-cache! export-edn-url)
(get-in @cache [ns-name var-name])))
(get @cache (keyword ns-name var-name))))
2 changes: 1 addition & 1 deletion test-resources/clojuredocs/export.edn

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/orchard/clojuredocs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@
(is (not (empty? @docs/cache)))))

(testing "find non-existing document"
(is (nil? (docs/find-doc test-edn-file "non-existing-ns" "non-existing-var")))))
(is (nil? (docs/find-doc "non-existing-ns" "non-existing-var" test-edn-file)))))