Skip to content
Browse files

support asset cacheing

  • Loading branch information...
1 parent 218508e commit ec4e79f8a705efae1ea126adbe689acf9c39f2ed @jxa jxa committed
Showing with 26 additions and 8 deletions.
  1. +14 −7 src/dieter/asset/ember.clj
  2. +12 −1 test/dieter/test/asset/ember.clj
View
21 src/dieter/asset/ember.clj
@@ -1,18 +1,20 @@
(ns dieter.asset.ember
(:require
- dieter.asset
- dieter.asset.javascript
[clojure.string :as s])
(:use
+ [dieter.asset :only [wrap-content]]
+ [dieter.util :only [string-builder]]
+ [dieter.asset.javascript :only [map->Js]]
[dieter.rhino :only [with-scope call make-pool]]))
(defn filename-without-ext [file]
(s/replace (.getName file) #"\..*$" ""))
(defn compile-ember [string filename]
- (str "Ember.TEMPLATES[\"" filename "\"]=Ember.Handlebars.template("
- (call "precompileEmber" string)
- ");"))
+ (string-builder
+ "Ember.TEMPLATES[\"" filename "\"]=Ember.Handlebars.template("
+ (call "precompileEmber" string)
+ ");\n"))
(def pool (make-pool))
(defn preprocess-handlebars [file]
@@ -21,7 +23,12 @@
filename (filename-without-ext file)]
(compile-ember hbs filename))))
-(defrecord Handlebars [file]
+(defrecord Handlebars [file last-modified]
dieter.asset.Asset
(read-asset [this options]
- (dieter.asset.javascript.Js. (:file this) (preprocess-handlebars (:file this)))))
+ (let [file (:file this)
+ mod (.lastModified file)]
+ (map->Js {:file file
+ :content (wrap-content file (preprocess-handlebars file))
+ :last-modified mod
+ :composed-of [(assoc this :last-modified mod)]}))))
View
13 test/dieter/test/asset/ember.clj
@@ -1,9 +1,20 @@
(ns dieter.test.asset.ember
(:use dieter.asset.ember)
(:use clojure.test)
+ (:use dieter.asset)
+ (:require dieter.asset.javascript)
(:require [clojure.java.io :as io]))
(deftest test-preprocess-handlebars
(is (not= -1 (.indexOf
(preprocess-handlebars (io/file "test/fixtures/assets/javascripts/view.hbs"))
- "Ember.TEMPLATES[\"view\"]=Ember.Handlebars.template"))))
+ "Ember.TEMPLATES[\"view\"]=Ember.Handlebars.template"))))
+
+(deftest test-handlebars-record
+ (let [asset (map->Handlebars {:file (io/file "test/fixtures/assets/javascripts/view.hbs")})
+ after-read (read-asset asset {})]
+ (is (= dieter.asset.javascript.Js (class after-read)))
+ (is (not= nil (:last-modified after-read)))
+ (is (not= nil (:content after-read)))
+ (is (= (:file asset) (:file (first (:composed-of after-read)))))
+ (is (not= nil (:last-modified (first (:composed-of after-read)))))))

0 comments on commit ec4e79f

Please sign in to comment.
Something went wrong with that request. Please try again.