Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dieter-core/resources/vendor/coffee-script.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions dieter-core/resources/vendor/coffee-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@ function formatError(e, filename) {
}

function compileCoffeeScript(input, filename) {
try {
return CoffeeScript.compile(input);
} catch (e) {
throw formatError(e, filename);
}
return CoffeeScript.compile(input, {filename: filename});
}
5 changes: 5 additions & 0 deletions dieter-core/resources/vendor/livescript.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dieter-core/resources/vendor/ls-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function compileLiveScript(input, filename) {
return LiveScript.compile(input, {filename: filename});
}
23 changes: 23 additions & 0 deletions dieter-core/src/dieter/asset/livescript.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns dieter.asset.livescript
(:require [dieter.asset :as asset]
dieter.asset.javascript
[dieter.pools :as pools])
(:use [dieter.jsengine :only (run-compiler)]))

(def pool (pools/make-pool))

(defn compile-livescript [file]
(run-compiler pool
["livescript.js" "ls-wrapper.js"]
"compileLiveScript"
file))

(defn preprocess-livescript [file]
(asset/memoize-file file compile-livescript))

(defrecord LiveScript [file]
dieter.asset.Asset
(read-asset [this]
(dieter.asset.javascript.Js. (:file this) (preprocess-livescript (:file this)))))

(asset/register "ls" map->LiveScript)
6 changes: 3 additions & 3 deletions dieter-core/test/dieter/test/asset/coffeescript.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(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"
(is (= "(function() {\n (function(param) {\n return alert(\"x\");\n });\n\n}).call(this);\n"
(cs/preprocess-coffeescript
(io/file "test/fixtures/assets/javascripts/test.js.coffee")))))
(testing "syntax error"
Expand All @@ -18,5 +18,5 @@
(io/file "test/fixtures/assets/javascripts/bad.js.coffee"))
(is false) ; must throw
(catch Exception e
(is (h/has-text? (.toString e) "on line 2"))
(is (h/has-text? (.toString e) "unmatched ]")))))))
(is (h/has-text? (.toString e) "2:5"))
(is (h/has-text? (.toString e) "unmatched ]")))))))
9 changes: 5 additions & 4 deletions dieter-core/test/dieter/test/asset/hamlcoffee.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
(deftest test-preprocess-hamlcoffee
(h/with-both-engines
(testing "basic hamlc file"
(is (= (wrap "basic" "<!DOCTYPE html>\\n<html>\\n <head>\\n <title>\\n Title\\n </title>\\n </head>\\n <body>\\n <h1>\\n Header\\n </h1>\\n </body>\\n</html>")
(hc/preprocess-hamlcoffee
(io/file "test/fixtures/assets/javascripts/basic.hamlc")))))))
(let [expected (slurp (io/file "test/fixtures/assets/javascripts/basic.hamlc.js"))]
(is (= (.trim expected)
(.trim (hc/preprocess-hamlcoffee
(io/file "test/fixtures/assets/javascripts/basic.hamlc")))))))))

(deftest test-caching
(h/with-both-engines
Expand Down Expand Up @@ -57,4 +58,4 @@
;; (is (has-text?
;; (preprocess-hamlcoffee
;; (io/file "test/fixtures/assets/javascripts/badcoffee.hamlc"))
;; "@import \"includeme.less\""))))
;; "@import \"includeme.less\""))))
34 changes: 34 additions & 0 deletions dieter-core/test/dieter/test/asset/livescript.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns dieter.test.asset.livescript
(:require [dieter.test.helpers :as h]
[dieter.asset.livescript :as ls]
[clojure.java.io :as io])
(:use clojure.test))

(deftest test-preprocess-livescript
(h/with-both-engines
(let [fixture (io/file "test/fixtures/assets/javascripts/test.js.ls")
bad-file (io/file "test/fixtures/assets/javascripts/bad.js.ls")]
(testing "we have a chance to succeed"
(is (.exists fixture)))
(testing "basic ls file"
(let [expected (clojure.string/join "\n" ["(function(){"
" (function(it){"
" return it + \"!\";"
" })("
" function(it){"
" return it.x;"
" }("
" {"
" x: 'foo'"
" }));"
"}).call(this);"
""])]
(is (= expected
(ls/preprocess-livescript fixture)))))
(testing "syntax error"
(try
(ls/preprocess-livescript bad-file)
(is false) ; must throw
(catch Exception e
(is (h/has-text? (.toString e) "line 1"))
(is (h/has-text? (.toString e) "unmatched"))))))))
1 change: 1 addition & 0 deletions dieter-core/test/fixtures/assets/javascripts/bad.js.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f = -> ]]
16 changes: 16 additions & 0 deletions dieter-core/test/fixtures/assets/javascripts/basic.hamlc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(function() {
if (window.HAML == null) {
window.HAML = {};
}

window.HAML['basic'] = function(context) {
return (function() {
var $o;
$o = [];
$o.push("<!DOCTYPE html>\n<html>\n <head>\n <title>\n Title\n </title>\n </head>\n <body>\n <h1>\n Header\n </h1>\n </body>\n</html>");
return $o.join("\n");
}).call(context);
};

}).call(this);

1 change: 1 addition & 0 deletions dieter-core/test/fixtures/assets/javascripts/test.js.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{x: \foo} |> (.x) |> (+ "!")