Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use less builtin compression #42

Merged
merged 2 commits into from
Mar 21, 2013
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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\"")))))))