Permalink
Browse files

more refactoring / cleanup

  • Loading branch information...
hofmeister committed Feb 2, 2013
1 parent c35e725 commit 1e511c7e68a03614fa77e0acdd1dc50f1fd75aa6
Showing with 14 additions and 15 deletions.
  1. +14 −15 src/main/java/com/vonhof/webi/file/LESSHandler.java
@@ -1,32 +1,35 @@
package com.vonhof.webi.file;
import com.asual.lesscss.LessEngine;
-import com.asual.lesscss.LessException;
import com.asual.lesscss.LessOptions;
import com.google.common.io.Files;
-import com.google.javascript.jscomp.JSModule;
-import com.google.javascript.jscomp.SourceFile;
import com.vonhof.webi.WebiContext;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import org.apache.commons.io.IOUtils;
/**
*
* @author Henrik Hofmeister <@vonhofdk>
*/
public class LESSHandler extends PreprocessingRequestHandler {
+ final LessEngine css;
+ final LessEngine less;
public LESSHandler() {
super("text/css");
+
+ //Setup 2 engines - 1 for CSS and 1 for LESS
+ LessOptions cssOptions = new LessOptions();
+ cssOptions.setCss(true);
+ css = new LessEngine(cssOptions);
+
+ LessOptions lessOptions = new LessOptions();
+ lessOptions.setCss(false);
+ less = new LessEngine(lessOptions );
}
@Override
@@ -37,17 +40,13 @@ protected boolean isValid(File file) {
@Override
protected void outputFiles(WebiContext req, List<File> files) throws IOException {
- LessOptions cssOptions = new LessOptions();
- cssOptions.setCss(true);
- final LessEngine css = new LessEngine(cssOptions);
-
- LessOptions lessOptions = new LessOptions();
- lessOptions.setCss(false);
- final LessEngine less = new LessEngine(lessOptions );
+ //Run through all files that should be compiled
for(File file:files) {
+ //Actual source
String cssLess = Files.toString(file, Charset.forName("UTF-8"));
try {
+ //Compiled source
String compiled = "";
if (getFileExt(file).equalsIgnoreCase("less")) {
compiled = less.compile(cssLess, req.getParameterMap().contains("compressed"));

0 comments on commit 1e511c7

Please sign in to comment.