Skip to content

Commit

Permalink
Working on lein plugin, broken by verify error so far
Browse files Browse the repository at this point in the history
  • Loading branch information
jaley committed Aug 27, 2013
1 parent e36e43f commit d38c1bc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
2 changes: 2 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
[prismatic/dommy "0.1.1"]
[cljs-ajax "0.2.0"]]

;; :eval-in-leiningen true

:plugins [[lein-cljsbuild "0.3.2"]
[lein-ring "0.8.6"]]

Expand Down
23 changes: 15 additions & 8 deletions src/clj/cloc/core.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
(ns cloc.core
"Cloc main entry point, for Jetty web server."
(:require [ring.adapter.jetty :as jetty]
[cloc.routes :as routes]
[cloc.index :as index]
[cloc.search :as search]))
(:require [clojure.java.classpath :as cp]
[ring.adapter.jetty :as jetty]
[cloc.routes :as routes]
[cloc.index :as index]
[cloc.search :as search]))

(def server (atom nil))

(defn start-server!
"Start a jetty server"
[]
[& [ring-opts]]
(swap! server
(fn [s]
(when s (.stop s))
(jetty/run-jetty routes/main
{:port 1337, :join? false}))))
(or ring-opts
{:port 1337, :join? false})))))

(defn stop-server!
"Stop the jetty server, if one is running."
Expand All @@ -24,6 +26,11 @@
(defn init!
"Ring initialiser function.
When working interactively, call this before start-server!"
[& _]
(index/init-index!)
[& [classpath]]
(index/init-index! (or classpath (cp/classpath)))
(search/init-search-index! @index/index))

(defn main
[ring-opts classpath]
(init! classpath)
(start-server! ring-opts))
4 changes: 1 addition & 3 deletions src/clj/cloc/index.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns cloc.index
"Functions for access the documentation index structure."
(:require [clojure.java.classpath :refer [classpath]]
[codox.reader :refer [read-namespaces]])
(:require [codox.reader :refer [read-namespaces]])
(:import [java.io File]))

(def index
Expand Down Expand Up @@ -51,7 +50,6 @@
(defn init-index!
"Return a documentation index structure, to be used with the other
functions in this namespace."
([] (init-index! (classpath)))
([cp] (reset! index (index-classpath cp))))

(defn local-code
Expand Down
33 changes: 33 additions & 0 deletions src/clj/leiningen/cloc.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns leiningen.cloc
"Leiningen plugin to start the cloc web server locally."
(:require [leiningen.core.classpath :as cp]
[cemerick.pomegranate.aether :as aether]
[cloc.core :refer [main]]))

(defn- try-parse
"Try to convert v to integer, then bool, else string."
[v]
(if-let [num (try (Integer/parseInt v) (catch NumberFormatException _ nil))]
num
(cond
(re-find #"true|flase" (.toLowerCase v)) (Boolean/parseBoolean v)
:else (str v))))

(defn cloc
"Start the cloc doc server locally, serving API docs for
your code and all your dependencies. Accepts ring configuration
map keyword and value arguments. Most useful ones will be:
- :host -- host name to listen on
- :port -- port to listen for connections on"
[project & args]
(let [jars (filter (fn [f] (re-find #"\.jar$") (.getName f))
(aether/dependency-files
(cp/dependency-hierarchy :dependencies project)))]
(assert (even? (count args))
"Number of args should be even - only key-value pairs supported.")
(main (merge
(reduce (fn [m [k v ]] (assoc m (keyword k) (try-parse v)))
{}
(partition 2 args))
{:join? true}))))

0 comments on commit d38c1bc

Please sign in to comment.