net.oneandone.ssass.scss.Output Maven / Gradle / Ivy
/**
* Copyright 1&1 Internet AG, https://github.com/1and1/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.oneandone.ssass.scss;
import net.oneandone.mork.misc.GenericException;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Output {
public static String compress(Stylesheet s) throws GenericException {
return toCss(s, true);
}
public static String prettyprint(Stylesheet s) throws GenericException {
return toCss(s, false);
}
public static String toCss(Stylesheet s, boolean compress) throws GenericException {
StringWriter sw;
Output output;
sw = new StringWriter();
output = new Output(sw, compress);
s.toCss(output);
try {
output.result().close();
} catch (IOException e) {
throw new IllegalStateException("unexpected io exception while writing to StringWriter", e);
}
return sw.toString();
}
//--
private final Writer dest;
private boolean compress;
private boolean first;
private int indent;
private String declaration;
private final List selectorContext;
private final List propertyContext;
private final List delayedContexts;
private final List delayedRulesets;
private final Map mixins;
private final Map variables;
private final List