private ScssCacheEntry compileScssOnTheFly(String filename, String scssFilename, ServletContext sc) throws IOException { String realFilename = sc.getRealPath(scssFilename); ScssStylesheet scss = ScssStylesheet.get(realFilename); if (scss == null) { // Not a file in the file system (WebContent directory). Use the // identifier directly (VAADIN/themes/.../styles.css) so // ScssStylesheet will try using the class loader. if (scssFilename.startsWith("/")) { scssFilename = scssFilename.substring(1); } scss = ScssStylesheet.get(scssFilename); } if (scss == null) { getLogger().log(Level.WARNING, "Scss file {0} exists but ScssStylesheet was not able to find it", scssFilename); return null; } try { getLogger().log(Level.FINE, "Compiling {0} for request to {1}", new Object[] { realFilename, filename }); scss.compile(); } catch (Exception e) { getLogger().log(Level.WARNING, "Scss compilation failed", e); return null; } return new ScssCacheEntry(realFilename, scss.printState(), scss.getSourceUris()); }
private String wrapCSS(String cssContent, String wrapperClass) { try { String wrappedContent = wrapperClass == null ? cssContent : "." + wrapperClass + "{\n" + cssContent + "\n}"; File tmpFile = File.createTempFile("annis-stylesheet", ".scss"); Files.write(wrappedContent, tmpFile, Charsets.UTF_8); ScssStylesheet styleSheet = ScssStylesheet.get(tmpFile.getCanonicalPath()); styleSheet.compile(); return styleSheet.printState(); } catch (IOException ex) { log.error("IOException when compiling wrapped CSS", ex); } catch (Exception ex) { log.error("Could not compile wrapped CSS", ex); } return null; }
String filteredScss = scss.printState().replace("@version@", version);
SassCompiler.writeFile(css.getAbsolutePath(), scss.printState());