Permalink
Browse files

Factored out compile-form into leiningen.ring.util

  • Loading branch information...
1 parent 7d10bc0 commit a695dc4a52550d2183b072ff8b8e5ceb8d466050 @weavejester committed Dec 11, 2012
Showing with 33 additions and 31 deletions.
  1. +31 −2 src/leiningen/ring/util.clj
  2. +2 −29 src/leiningen/ring/war.clj
@@ -1,4 +1,8 @@
-(ns leiningen.ring.util)
+(ns leiningen.ring.util
+ (:use [leinjacker.eval :only (eval-in-project)])
+ (:require [clojure.string :as str]
+ [clojure.java.io :as io]
+ leiningen.deps))
(defn ensure-handler-set!
"Ensure the :handler option is set in the project map."
@@ -8,4 +12,29 @@
(str "Missing Ring :handler option in project map.\n\n"
"You need to have a line in your project.clj file that looks like:\n"
" :ring {:handler your.app/handler}"))
- (System/exit 1)))
+ (System/exit 1)))
+
+(defn source-file [project namespace]
+ (io/file (:compile-path project)
+ (-> (str namespace)
+ (str/replace "-" "_")
+ (str/replace "." java.io.File/separator)
+ (str ".clj"))))
+
+(defn compile-form
+ "Compile the supplied form into the target directory."
+ [project namespace form]
+ ;; We need to ensure that deps has already run before we write anything
+ ;; to :target-dir, which is otherwise cleaned by deps if it runs for
+ ;; the first time as a side effect of eval-in-project Ideally,
+ ;; generated sources would be going into a dedicated directory and thus
+ ;; be immune from the lifecycle around :target-dir; that would be
+ ;; straightforward using lein 2.x middlewares, but not so easy with 1.x.
+ (leiningen.deps/deps project)
+ (let [out-file (source-file project namespace)]
+ (.mkdirs (.getParentFile out-file))
+ (with-open [out (io/writer out-file)]
+ (binding [*out* out] (prn form))))
+ (eval-in-project project
+ `(do (clojure.core/compile '~namespace) nil)
+ nil))
View
@@ -1,11 +1,9 @@
(ns leiningen.ring.war
- (:require leiningen.deps
- [leiningen.compile :as compile]
+ (:require [leiningen.compile :as compile]
[clojure.java.io :as io]
[clojure.string :as string]
[leinjacker.deps :as deps])
- (:use [leinjacker.eval :only (eval-in-project)]
- [clojure.data.xml :only [sexp-as-element indent-str]]
+ (:use [clojure.data.xml :only [sexp-as-element indent-str]]
leiningen.ring.util)
(:import [java.util.jar Manifest
JarEntry
@@ -114,31 +112,6 @@
[:servlet-name (servlet-name project)]
[:url-pattern (url-pattern project)]]])))))
-(defn source-file [project namespace]
- (io/file (:compile-path project)
- (-> (str namespace)
- (string/replace "-" "_")
- (string/replace "." java.io.File/separator)
- (str ".clj"))))
-
-(defn compile-form [project namespace form]
- ;; We need to ensure that deps has already run before
- ;; we write anything to :target-dir, which is otherwise
- ;; cleaned by deps if it runs for the first time as a
- ;; side effect of eval-in-project
- ;; Ideally, generated sources would be going into a
- ;; dedicated directory and thus be immune from the lifecycle
- ;; around :target-dir; that would be straightforward using
- ;; lein 2.x middlewares, but not so easy with 1.x.
- (leiningen.deps/deps project)
- (let [out-file (source-file project namespace)]
- (.mkdirs (.getParentFile out-file))
- (with-open [out (io/writer out-file)]
- (binding [*out* out] (prn form))))
- (eval-in-project project
- `(do (clojure.core/compile '~namespace) nil)
- nil))
-
(defn generate-handler [project handler-sym]
(if (get-in project [:ring :servlet-path-info?] true)
`(fn [request#]

0 comments on commit a695dc4

Please sign in to comment.