List of usage examples for com.google.common.css.compiler.ast GssParser GssParser
public GssParser(SourceCode source)
From source file:com.google.gwt.resources.converter.GssGenerationVisitor.java
@Override public boolean visit(CssProperty x, Context ctx) { maybePrintOpenBrace();// w ww . j av a 2 s . c om StringBuilder propertyBuilder = new StringBuilder(); if (noFlip) { propertyBuilder.append(NO_FLIP); propertyBuilder.append(' '); } propertyBuilder.append(x.getName()); propertyBuilder.append(": "); propertyBuilder.append(printValuesList(x.getValues().getValues())); if (x.isImportant()) { propertyBuilder.append(IMPORTANT); } String cssProperty = propertyBuilder.toString(); if (lenient) { // lenient mode: Try to parse the css rule and if an error occurs, // print a warning message and don't print the rule. try { new GssParser(new SourceCode(null, "body{" + cssProperty + "}")).parse(); } catch (GssParserException e) { System.err .println("[WARN] The following property is not valid and will be skipped: " + cssProperty); return false; } } out.print(cssProperty); semiColon(); return true; }
From source file:com.log4ic.compressor.utils.Compressor.java
public static String parseGss(JobDescription job) throws GssParserException { logger.debug("?GSS..."); try {//from w w w . j av a2 s. c om GssParser parser = new GssParser(job.inputs); CssTree cssTree = parser.parse(); CompilerErrorManager errorManager = new CompilerErrorManager(); PassRunner passRunner = new ExtendedPassRunner(job, errorManager); passRunner.runPasses(cssTree); PrettyPrinter prettyPrinterPass = new PrettyPrinter(cssTree.getVisitController()); prettyPrinterPass.runPass(); return prettyPrinterPass.getPrettyPrintedString(); } finally { logger.debug("?GSS..."); } }
From source file:com.log4ic.compressor.utils.Compressor.java
/** * css/*ww w . j a va 2 s. c o m*/ * * @param job * @return * @throws GssParserException */ public static String compressGss(JobDescription job) throws GssParserException { logger.debug("CSS..."); try { GssParser parser = new GssParser(job.inputs); CssTree cssTree = parser.parse(); if (job.outputFormat != JobDescription.OutputFormat.DEBUG) { CompilerErrorManager errorManager = new CompilerErrorManager(); PassRunner passRunner = new ExtendedPassRunner(job, errorManager); passRunner.runPasses(cssTree); } if (job.outputFormat == JobDescription.OutputFormat.COMPRESSED) { CompactPrinter compactPrinterPass = new CompactPrinter(cssTree); compactPrinterPass.runPass(); return compactPrinterPass.getCompactPrintedString(); } else { PrettyPrinter prettyPrinterPass = new PrettyPrinter(cssTree.getVisitController()); prettyPrinterPass.runPass(); return prettyPrinterPass.getPrettyPrintedString(); } } finally { logger.debug("CSS..."); } }
From source file:com.google.gwt.resources.rg.GssResourceGenerator.java
private ExtendedCssTree parseResources(List<URL> resources, TreeLogger logger) throws UnableToCompleteException { List<SourceCode> sourceCodes = new ArrayList<SourceCode>(resources.size()); // assert that we only support either gss or css on one resource. boolean css = ensureEitherCssOrGss(resources, logger); if (css && !allowLegacy) { // TODO(dankurka): add link explaining the situation in detail. logger.log(Type.ERROR,/*from w ww. j a v a 2s .co m*/ "Your ClientBundle is referencing css files instead of gss. " + "You will need to either convert these files to gss using the " + "converter tool or turn on auto convertion in your gwt.xml file. " + "Note: Autoconversion will be removed after 2.7, you will need to move to gss." + "Add this line to your gwt.xml file to temporary avoid this:" + "<set-configuration-property name=\"CssResource.legacy\" value=\"true\" />"); throw new UnableToCompleteException(); } if (css) { String concatenatedCss = concatCssFiles(resources, logger); String gss = convertToGss(concatenatedCss, logger); sourceCodes.add(new SourceCode("[auto-converted gss files]", gss)); } else { for (URL stylesheet : resources) { TreeLogger branchLogger = logger.branch(TreeLogger.DEBUG, "Parsing GSS stylesheet " + stylesheet.toExternalForm()); try { // TODO : always use UTF-8 to read the file ? String fileContent = Resources.asByteSource(stylesheet).asCharSource(Charsets.UTF_8).read(); sourceCodes.add(new SourceCode(stylesheet.getFile(), fileContent)); continue; } catch (IOException e) { branchLogger.log(TreeLogger.ERROR, "Unable to parse CSS", e); } throw new UnableToCompleteException(); } } CssTree tree; try { tree = new GssParser(sourceCodes).parse(); } catch (GssParserException e) { logger.log(TreeLogger.ERROR, "Unable to parse CSS", e); throw new UnableToCompleteException(); } List<String> permutationAxes = finalizeTree(tree); checkErrors(); return new ExtendedCssTree(tree, permutationAxes); }