Skip to content

Commit

Permalink
Merge pull request #41 from DanThiffault/UpgradeLibs
Browse files Browse the repository at this point in the history
Removing dependancy on fs lib
  • Loading branch information
pbiggar committed Mar 6, 2013
2 parents 74034ac + 1f34582 commit f617392
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 64 deletions.
6 changes: 3 additions & 3 deletions dieter-core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:url "http://github.com/edgecase/dieter"
:scm {:name "git" :dir ".."}
:dependencies [[ring "1.0.1"]
[fs "0.11.1"]
:dependencies [[ring/ring-core "1.1.8"]
[clj-time "0.4.4"]
[com.google.javascript/closure-compiler "r1592"]
[clj-v8 "0.1.4"]
[clj-v8-native "0.1.4"]
[org.mozilla/rhino "1.7R4"]]
[org.mozilla/rhino "1.7R4"]
[org.clojure/clojure "1.4.0"]]
:dev-dependencies [[org.clojure/clojure "1.4.0"]])
5 changes: 4 additions & 1 deletion dieter-core/src/dieter/asset.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ Contents can be a String, StringBuilder, or byte[]"))
(defn make-asset [file]
"returns a newly constructed asset of the proper type as determined by the file extension.
defaults to Static if extension is not registered."
((get @types (file-ext file) (:default @types)) {:file file}))
((get @types
(file-ext file)
(:default @types))
{:file file}))
26 changes: 7 additions & 19 deletions dieter-core/src/dieter/asset/manifest.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
(ns dieter.asset.manifest
(:require [clojure.java.io :as io]
[clojure.string :as s]
[dieter.asset :as asset]
[dieter.path :as path]
[fs])
[dieter.asset :as asset])
(:use [dieter.util :only [slurp-into string-builder]])
(:import [java.io FileReader PushbackReader FileNotFoundException]))

Expand All @@ -14,30 +12,20 @@ namely a vector or list of file names or directory paths."
(let [stream (PushbackReader. (FileReader. file))]
(read stream)))

(defn recursive-files [dir]
(->> dir
fs/iterdir
(map (fn [[root _ files]]
(doall (map #(fs/join root %)
(sort files))))))) ;; sort because of file-ordering bugs

(defn manifest-files
"return a sequence of files specified by the given manifest."
[manifest-file]
(->> (load-manifest manifest-file)
(map (fn [filename]
(let [dir (.getParent manifest-file)
file (path/find-file filename :root dir)]
(when (nil? file)
(let [base-dir (.getParent (io/file manifest-file))
file (io/file base-dir filename)]
(when-not (.exists file)
(throw (FileNotFoundException. (str "Could not find " filename " from " manifest-file))))
(if (-> file io/file .isDirectory)
(recursive-files file)
file))))
doall
(file-seq file))))
flatten
(map io/file)
(remove #(or (re-matches #".*\.swp$" (.getCanonicalPath %))
(re-matches #"/.*\.#.*$" (.getCanonicalPath %))))))
(re-matches #"/.*\.#.*$" (.getCanonicalPath %))
(.isDirectory %)))))

(defn compile-manifest [file]
(let [builder (string-builder)
Expand Down
4 changes: 1 addition & 3 deletions dieter-core/src/dieter/core.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(ns dieter.core
(:require [clojure.java.io :as io]
[fs]
[dieter.settings :as settings]
(:require [dieter.settings :as settings]
[dieter.asset :as asset]
[dieter.path :as path]
[dieter.cache :as cache]
Expand Down
10 changes: 1 addition & 9 deletions dieter-core/src/dieter/path.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(:use dieter.settings)
(:require [clojure.string :as cstr]
[clojure.java.io :as io]
[dieter.settings :as settings]
[fs])
[dieter.settings :as settings])
(:import [java.security MessageDigest]))

;;;; TODO
Expand All @@ -24,13 +23,6 @@
(cstr/replace-first path (re-pattern (str ".*" (settings/cache-root))) ""))


(defn relative-path [root file]
(let [absroot (fs/abspath root)
absfile (fs/abspath file)
root-length (count absroot)]
(.substring absfile (inc root-length))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; String-types used
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
69 changes: 42 additions & 27 deletions dieter-core/src/dieter/precompile.clj
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
(ns dieter.precompile
(:require [fs]
(:require [clojure.java.io :as io]
[dieter.cache :as cache]
[dieter.path :as path]
[dieter.asset :as asset]
[dieter.settings :as settings]))

(defn foreach-file
"Iterate through the assets directory"
[dir f]
(fs/walk
dir
(fn [root _ files]
(doseq [filename files]
(f (->> filename
(fs/join root)))))))
(defn relative-path [root file]
(let [absroot (.getCanonicalPath (io/file root))
absfile (.getCanonicalPath (io/file file))
root-length (count absroot)]
(.substring absfile (inc root-length))))

(defn load-precompiled-assets
"Load any assets already in the cache directory"
[]
(foreach-file
(settings/cache-root)
(fn [cached]
(let [cached (->> cached
(path/relative-path (settings/cache-root))
(str "/"))
uncached (->> cached
(path/uncachify-path))]
(cache/add-cached-uri uncached cached)))))
(->> (settings/cache-root)
file-seq
flatten
(remove #(.isDirectory %))
(map (fn [cached]
(let [cached (->> cached
(relative-path (settings/cache-root))
(str "/"))
uncached (->> cached
(path/uncachify-path))]
(cache/add-cached-uri uncached cached))))
dorun))

(defn find-and-cache-asset [& args]
(apply (ns-resolve 'dieter.core 'find-and-cache-asset) args))

(defn delete-dir [directory]
(->> directory
io/file
file-seq
flatten
(remove #(= directory (.getPath %1)))
reverse
(map #(.delete %1))
dorun
))

(defn precompile [options]
(settings/with-options options
(-> (settings/cache-root) (fs/join "assets") fs/deltree)
(-> (settings/cache-root) (str "assets") delete-dir)
(if (settings/precompiles)
(doseq [filename (settings/precompiles)]
(->> filename
(find-and-cache-asset)))
(doseq [asset-root (settings/asset-roots)]
(foreach-file
(fs/join asset-root "assets")
(fn [filename]
(try (->> filename
(path/relative-path asset-root)
(->>
(io/file asset-root "assets")
file-seq
flatten
(remove #(.isDirectory %))
(map (fn [filename]
(try (->> filename
(relative-path asset-root)
(str "./")
(find-and-cache-asset))
(print ".")
(catch Exception e
(println "Not built" filename)))))
nil))))
(println "Not built" filename)))

))
dorun)))))
3 changes: 1 addition & 2 deletions dieter-core/src/dieter/v8.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(ns dieter.v8
(:require [v8.core :as v8]
[clojure.java.io :as io]
[fs]
[clojure.string :as str]
[dieter.settings :as settings]))

(defn load-vendor [files]
(apply str (map (fn [f]
(->> f
(fs/join "vendor")
(str "vendor/")
io/resource
io/reader
line-seq
Expand Down
2 changes: 2 additions & 0 deletions dieter-core/test/dieter/test/asset/coffeescript.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

(deftest test-preprocess-coffeescript
(h/with-both-engines
(testing "we have a chance to succeed"
(is (.exists (io/file "test/fixtures/assets/javascripts/test.js.coffee"))))
(testing "basic coffee file"
(is (= "(function() {\n\n (function(param) {\n return alert(\"x\");\n });\n\n}).call(this);\n"
(cs/preprocess-coffeescript
Expand Down

0 comments on commit f617392

Please sign in to comment.