Browse files

Sort out watch functionality.

  • Loading branch information...
1 parent 364ec33 commit 4c75a2be06ae5724dcffbc75d2602fe3efbe3da8 @JulianBirch committed Feb 12, 2012
Showing with 77 additions and 21 deletions.
  1. +0 −13 README
  2. +72 −0 readme.md
  3. +3 −6 src/hendrix/core.clj
  4. +2 −2 src/hendrix/watch.clj
View
13 README
@@ -1,13 +0,0 @@
-# hendrix
-
-FIXME: write description
-
-## Usage
-
-FIXME: write
-
-## License
-
-Copyright (C) 2011 FIXME
-
-Distributed under the Eclipse Public License, the same as Clojure.
View
72 readme.md
@@ -0,0 +1,72 @@
+# hendrix - clojure asset pipeline
+
+Hendrix is intended to be a web asset pipeline for Clojure, solving
+the same problem as the rails asset pipeline, but not necessarily in
+the same way. It's motivated by my experience of ASP.NET MVC and its
+deficiencies.
+
+## What it can do
+
+At the moment, the honest answer is very little. There's
+<ul>
+<li>a pretty basic make (called execute) missing task scheduling</li>
+<li>a generalized watch infrastructure</li>
+<li>a neat way of handling temporary directories</li>
+<li>some fairly cool test code that enables you to fake out the file system</li>
+</ul>
+
+So, a lot of meta. In fact, the only actual use of it right now is to
+compile bootstrap with your own variable file.
+
+## How to use it
+
+At the moment, its best used through a lein run command. Later
+versions will hopefully support more magic. Here's some actual
+working code:
+
+<pre>
+(ns semele.commands
+ (:use [hendrix core command watch]
+ [clojure pprint]))
+
+(def bootstrap
+ (new-merge-rule
+ "assets/variables.less"
+ "checkouts/bootstrap/lib/*.less"))
+
+(def cb (new-rule (bootstrap "bootstrap.less")
+ "resources/public/site.css"
+ lessc
+ bootstrap))
+
+(defn compile-bootstrap [] (execute bootstrap cb))
+
+(defn watch [] (start compile-bootstrap))
+</pre>
+
+"bootstrap" defines rule for a temporary directory with the contents
+of the two expressions following. Earlier items take precedence over
+later ones. "cb" is the actual rule to compile bootstrap. The order
+of parameters is
+
+<ul>
+<li>The main file. Observe the way the temporary directory is referenced.</li>
+<li>The output file</li>
+<li>The command to use, defined in hendrix.command</li>
+<li>Implicit inputs to check. Here, the entire contents of the temporary directory are referenced.</li>
+</ul>
+
+## What's next?
+
+Things I'd like it to be able to do, roughly in order:
+<ul>
+<li>cljs-watch functionality</li>
+<li>Minify</li>
+<li>Switching between uncompressed and minified versions</li>
+<li>Allowing live-reloading of CSS</li>
+</ul>
+
+Adding test watching functionality would be cool, but would require
+some thought. I don't think I need a general aggregation strategy
+like rails, given that less and cljs already have their own, but I
+could be proved wrong.
View
9 src/hendrix/core.clj
@@ -10,7 +10,7 @@
(defmulti last-updated class)
(defmulti resolve-items class)
(defmulti evaluate-rule class)
-(println "HELLO")
+
(defrecord FileRule [last-evaluated
inputs all-inputs
output action])
@@ -56,7 +56,7 @@
(file/->MergeRule inputs
(-> "hendrix" file/create-temp-directory file)))
-(defn execute [rules]
+(defn execute [& rules]
(doseq [r rules] (evaluate-rule r)))
(defmethod resolve-items
@@ -92,8 +92,6 @@
(defmethod evaluate-rule
hendrix.file.MergeRule
[{:keys [inputs output] :as rule} ]
- (pprint "OUTPUT")
- (pprint (-> inputs first to-finder))
(let [input-files (->> inputs
(map to-finder)
(mapcat resolve-items)
@@ -102,8 +100,7 @@
(apply hash-map))
output-files (resolve-items output)
copies (for [[file-name input-file] input-files
- :let [output-file (rule file-name)
- _ (pprint output-file)]
+ :let [output-file (rule file-name)]
:when (or (-> output-file file/file-exists not)
(> (last-updated input-file) (last-updated output-file)))]
(copy input-file output-file))
View
4 src/hendrix/watch.clj
@@ -2,7 +2,7 @@
(def processes (ref {}))
-(def sleep-time 100) ; Sleep time for processes in milliseconds.
+(def sleep-time 1000) ; Sleep time for processes in milliseconds.
(defn execute-repeatedly [command enabled]
(when @enabled
@@ -15,7 +15,7 @@
(let [enabled (atom true)]
(dosync (when-not (get processes command)
(alter processes assoc command enabled)
- (future execute-repeatedly command enabled)))))
+ (future (execute-repeatedly command enabled))))))
(defn finish [command]
(let [enabled (get processes command)]

0 comments on commit 4c75a2b

Please sign in to comment.