Skip to content

Commit

Permalink
Load previously precompiled assets. Fixed bug in new file scanning. F…
Browse files Browse the repository at this point in the history
…ixed string based dieter config options
  • Loading branch information
DanThiffault committed Mar 5, 2013
1 parent 76a6c4c commit f72ae61
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dieter-core/src/dieter/asset.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Contents can be a String, StringBuilder, or byte[]"))
(let [new-content (f file)]
(dosync
(swap! memoized assoc filename {:content new-content
:timestamp (time/now)}))
:timestamp current-timestamp}))
new-content))))

;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
1 change: 1 addition & 0 deletions dieter-core/src/dieter/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
(settings/with-options options
(if (settings/production?)
(-> app
(precompile/load-precompiled-assets)

This comment has been minimized.

Copy link
@pbiggar

pbiggar Mar 11, 2013

Can you explain this change? I think I can guess, but not positive.

This comment has been minimized.

Copy link
@DanThiffault

DanThiffault Mar 11, 2013

Author Owner

If you're in production mode, load the assets from disk (created using lein-precompile).

This comment has been minimized.

Copy link
@pbiggar

pbiggar Mar 11, 2013

Why do they need to be loaded? Shouldn't they be served via wrap-file?

This comment has been minimized.

Copy link
@DanThiffault

DanThiffault Mar 11, 2013

Author Owner

They need to get loaded at some time during startup so that they are available before link-to-asset is called. Otherwise when cache-busting-uri is calculated it will re-md5 the files (currently based off the date of request rather than the content) while trying to load the page the first time. Especially once edgecase#39 is fixed I imagine this will be an expensive operation. Right now link-to-asset isn't properly generating hashed urls anyways so I can remove and figure out where initialization should happen at some other point. I can understand if its easier for all these changes to be separate.

This comment has been minimized.

Copy link
@DanThiffault

DanThiffault Mar 11, 2013

Author Owner

actually I agree this is not the right spot so I'll remove. I do think it needs to happen somewhere right now though. Or the readme should get updated to make an explicit call to core/init.

This comment has been minimized.

Copy link
@pbiggar

pbiggar Mar 20, 2013

Maybe that's the right answer here: make it clear that a call to dieter-precompile/load-precompiled-assets is needed. THis is what we do at @circleci.

(wrap-file (settings/cache-root))
(asset-builder options)
(wrap-file-expires-never (settings/cache-root))
Expand Down
1 change: 1 addition & 0 deletions dieter-core/src/dieter/precompile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Load any assets already in the cache directory"
[]
(->> (settings/cache-root)
io/file
file-seq
flatten
(remove #(.isDirectory %))
Expand Down
29 changes: 9 additions & 20 deletions lein-dieter-precompile/src/leiningen/dieter_precompile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,19 @@
(:require [clojure.string :as string]
[leiningen.core.eval :as eval]))

(defn ns-resolve-string
"Given a string "
[ns-string]
`(let [pair# (map symbol (string/split ~ns-string #"/"))
ns# (first pair#)
sym# (second pair#)]
(require ns#)
@(ns-resolve ns# sym#)))
(defn eval-opt [project opt]
(eval/eval-in-project project `(var-get (resolve (symbol ~opt))) `(require (symbol (namespace (symbol ~opt))))))

(defn resolve-dieter-options [opt]
`(let [opt# ~opt]
(cond
(map? opt#) opt#
(string? opt#) (let [val# ~(ns-resolve-string opt)]
(cond
(map? val#) val#
(fn? val#) (val#))))))
(defn resolve-dieter-options [project opt]
(cond
(map? opt) opt
(string? opt) (eval-opt project opt)))

(defn dieter-precompile
[project]
(let [options (:dieter-options project)
options (->> project
:dieter-options
resolve-dieter-options)]
(let [option-param (:dieter-options project)
options (resolve-dieter-options project option-param)]
(println (nil? options))
(println "options=" options)

This comment has been minimized.

Copy link
@pbiggar

pbiggar Mar 11, 2013

Not sure about println nil?

This comment has been minimized.

Copy link
@DanThiffault

DanThiffault Mar 11, 2013

Author Owner

Yes removed this in the next commit. I could have done an amend, but it would have globbed a bunch of changes together.

(eval/eval-in-project
project
Expand Down

0 comments on commit f72ae61

Please sign in to comment.