Skip to content

Commit

Permalink
Use less builtin compression
Browse files Browse the repository at this point in the history
  • Loading branch information
DanThiffault committed Mar 5, 2013
1 parent 1f34582 commit 76a6c4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -57,7 +57,7 @@ In order to include links to your assets you may use the link-to-asset function.
## Configuration Options

:engine :rhino ; defaults to :rhino; :v8 is much much faster
:compress false ; minify using Google Closure Compiler
:compress false ; minify using Google Closure Compiler & Less compression
:asset-roots ["resources"] ; must have a folder called 'assets'. Searched for assets in the order listed.
:cache-root "resources/asset-cache" ; compiled assets are cached here
:cache-mode :development ; or :production. :development disables cacheing
Expand Down Expand Up @@ -113,4 +113,4 @@ Distributed under the Eclipse Public License, the same as Clojure.
* Add mime type headers for dieter files

### Version 0.2.0
* Handlebars templates are now a separate library. [dieter-ember](https://github.com/edgecase/dieter-ember)
* Handlebars templates are now a separate library. [dieter-ember](https://github.com/edgecase/dieter-ember)
14 changes: 11 additions & 3 deletions dieter-core/resources/vendor/less-wrapper.js
Expand Up @@ -30,9 +30,9 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
});
}

function compileLess(input, name) {
function compileLess(input, name, shouldCompress) {
var output,
compress = false,
compress = shouldCompress,
i;

startingName = name;
Expand All @@ -49,9 +49,17 @@ function compileLess(input, name) {
var parser = new less.Parser();
parser.parse(input, function (e, root) {
if (e) { throw(e); }
result = root.toCSS();
result = root.toCSS({compress: compress});
});
}
catch(e) { throw format_error(e); }
return result;
};

function compileLessNoCompress(input, name) {
return compileLess(input, name, false);
}

function compileLessCompress(input, name) {
return compileLess(input, name, true);
}
2 changes: 1 addition & 1 deletion dieter-core/src/dieter/asset/less.clj
Expand Up @@ -12,7 +12,7 @@
(if (-> settings/*settings* :engine (= :rhino))
["less-rhino-wrapper.js" "less-wrapper.js" "less-rhino-1.3.3.js"]
["less-wrapper.js" "less-rhino-1.3.3.js"])
"compileLess"
(if (settings/compress?) "compileLessCompress" "compileLessNoCompress")
file))

(defrecord Less [file]
Expand Down
11 changes: 7 additions & 4 deletions dieter-core/test/dieter/test/asset/less.clj
@@ -1,19 +1,22 @@
(ns dieter.test.asset.less
(:require [clojure.java.io :as io]
[dieter.asset.less :as less]
[dieter.settings :as settings]
[dieter.test.helpers :as h])
(:use clojure.test))

(deftest test-preprocess-less
(testing "basic less file"
(settings/with-options
{:compress false}
(testing "basic less file"
(is (= "#header {\n color: #4d926f;\n}\n" (less/preprocess-less (io/file "test/fixtures/assets/stylesheets/basic.less")))))
(testing "file with imports"
(testing "file with imports"
(is (= "#includee {\n color: white;\n}\n#includee-three {\n color: white;\n}\n#includee-two {\n color: white;\n}\n#includer {\n color: black;\n}\n"
(less/preprocess-less (io/file "test/fixtures/assets/stylesheets/includes.less")))))
(testing "bad less syntax"
(testing "bad less syntax"
(try
(less/preprocess-less (io/file "test/fixtures/assets/stylesheets/bad.less"))
(is false) ; test it throws
(catch Exception e
(is (h/has-text? (.toString e) "Syntax Error on line 1"))
(is (h/has-text? (.toString e) "@import \"includeme.less\""))))))
(is (h/has-text? (.toString e) "@import \"includeme.less\"")))))))

0 comments on commit 76a6c4c

Please sign in to comment.