Skip to content

Commit

Permalink
Sort out watch functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianBirch committed Feb 12, 2012
1 parent 364ec33 commit 4c75a2b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
13 changes: 0 additions & 13 deletions README

This file was deleted.

72 changes: 72 additions & 0 deletions 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.
9 changes: 3 additions & 6 deletions src/hendrix/core.clj
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/hendrix/watch.clj
Expand Up @@ -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
Expand All @@ -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)]
Expand Down

0 comments on commit 4c75a2b

Please sign in to comment.