aboutsummaryrefslogtreecommitdiffstats
path: root/theme-compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'theme-compiler/src')
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java45
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java24
2 files changed, 55 insertions, 14 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
index 7213553e18..ed6b98f5ac 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
@@ -93,19 +93,49 @@ public class ScssStylesheet extends Node {
}
/**
- * Main entry point for the SASS compiler. Takes in a file and encoding then
- * builds up a ScssStylesheet tree out of it. Calling compile() on it will
- * transform SASS into CSS. Calling toString() will print out the SCSS/CSS.
+ * Main entry point for the SASS compiler. Takes in a file and an optional
+ * parent style sheet, then builds up a ScssStylesheet tree out of it.
+ * Calling compile() on it will transform SASS into CSS. Calling toString()
+ * will print out the SCSS/CSS.
*
* @param identifier
* The file path. If null then null is returned.
- * @param encoding
+ * @param parentStylesheet
+ * Style sheet from which to inherit resolvers and encoding. May
+ * be null.
* @return
* @throws CSSException
* @throws IOException
*/
public static ScssStylesheet get(String identifier,
ScssStylesheet parentStylesheet) throws CSSException, IOException {
+ return get(identifier, parentStylesheet, new SCSSDocumentHandlerImpl(),
+ new SCSSErrorHandler());
+ }
+
+ /**
+ * Main entry point for the SASS compiler. Takes in a file, an optional
+ * parent stylesheet, and document and error handlers. Then builds up a
+ * ScssStylesheet tree out of it. Calling compile() on it will transform
+ * SASS into CSS. Calling toString() will print out the SCSS/CSS.
+ *
+ * @param identifier
+ * The file path. If null then null is returned.
+ * @param parentStylesheet
+ * Style sheet from which to inherit resolvers and encoding. May
+ * be null.
+ * @param documentHandler
+ * Instance of document handler. May not be null.
+ * @param errorHandler
+ * Instance of error handler. May not be null.
+ * @return
+ * @throws CSSException
+ * @throws IOException
+ */
+ public static ScssStylesheet get(String identifier,
+ ScssStylesheet parentStylesheet,
+ SCSSDocumentHandler documentHandler, SCSSErrorHandler errorHandler)
+ throws CSSException, IOException {
/*
* The encoding to be used is passed through "encoding" parameter. the
* imported children scss node will have the same encoding as their
@@ -123,8 +153,7 @@ public class ScssStylesheet extends Node {
File file = new File(identifier);
file = file.getCanonicalFile();
- SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
- ScssStylesheet stylesheet = handler.getStyleSheet();
+ ScssStylesheet stylesheet = documentHandler.getStyleSheet();
if (parentStylesheet == null) {
// Use default resolvers
stylesheet.addResolver(new FilesystemResolver());
@@ -143,8 +172,8 @@ public class ScssStylesheet extends Node {
}
Parser parser = new Parser();
- parser.setErrorHandler(new SCSSErrorHandler());
- parser.setDocumentHandler(handler);
+ parser.setErrorHandler(errorHandler);
+ parser.setDocumentHandler(documentHandler);
try {
parser.parseStyleSheet(source);
diff --git a/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java b/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
index 2e51c686d4..0d48da34e4 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
@@ -15,34 +15,46 @@
*/
package com.vaadin.sass.internal.handler;
+import java.io.PrintStream;
+
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;
public class SCSSErrorHandler implements ErrorHandler {
+ private PrintStream errorStream;
+
+ public SCSSErrorHandler(PrintStream errorStream) {
+ this.errorStream = errorStream;
+ }
+
+ public SCSSErrorHandler() {
+ this(System.out);
+ }
+
@Override
public void error(CSSParseException arg0) throws CSSException {
- System.out.println("Error when parsing file \n" + arg0.getURI()
+ errorStream.println("Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
@Override
public void fatalError(CSSParseException arg0) throws CSSException {
- System.out.println("FATAL Error when parsing file \n" + arg0.getURI()
+ errorStream.println("FATAL Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
@Override
public void warning(CSSParseException arg0) throws CSSException {
- System.out.println("Warning when parsing file \n" + arg0.getURI()
+ errorStream.println("Warning when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
}