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()); }
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile sass to css log.trace("Send css for '{}'", resourceUrl); ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE; String identifier = resourceUrl.getFile(); ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier); if (scssStylesheet == null) { throw new Exception("ScssStylesheet is null for '" + identifier + "'"); } String content = scssStylesheet.toString(); String result = sourceMap.get(content); if (result == null) { scssStylesheet.compile(urlMode); Writer writer = new StringWriter(); scssStylesheet.write(writer, minify); result = writer.toString(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
/** * Main entry point for the SASS compiler. Takes in a file and 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. * @return * @throws CSSException * @throws IOException */ public static ScssStylesheet get(String identifier) throws CSSException, IOException { return get(identifier, null); }
public static void traverse(ExtendNode node) throws Exception { buildExtendsMap(node); modifyTree(ScssStylesheet.get()); }
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; }
ScssStylesheet scss = ScssStylesheet.get(sassFile); if (scss == null) { throw new IllegalArgumentException("SASS file: " + sassFile
ScssStylesheet scss = ScssStylesheet.get(sassFile); if (scss == null) { throw new IllegalArgumentException("SASS file: " + sassFile
ScssStylesheet scss = ScssStylesheet.get(input); if (scss == null) { System.err.println("The scss file " + input
@TaskAction void compile(IncrementalTaskInputs incrementalTaskInputs) throws Exception { File outputDir = getOutputDirectory(); outputDir.mkdirs(); Path srcDirPath = getSrcDir().toPath(); // only delete removed files if(incrementalTaskInputs.isIncremental()) { incrementalTaskInputs.outOfDate(inputFileDetails -> {}); incrementalTaskInputs.removed(inputFileDetails -> { File outputFile = getOutputFile(srcDirPath,outputDir,inputFileDetails.getFile()); if(outputFile.exists()) outputFile.delete(); }); } for(File f : getSassFiles()) { File outputFile = getOutputFile(srcDirPath,outputDir,f); outputFile.getParentFile().mkdirs(); try(OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile))) { ScssStylesheet sass = ScssStylesheet.get(f.getAbsolutePath()); sass.setFile(f); sass.setCharset("UTF-8"); // TODO: inteligent sass.addResolver(new FilesystemResolver(getSrcDir().getAbsolutePath())); sass.compile(); sass.write(out,getMinify()); } } }
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile sass to css log.trace("Send css for '{}'", resourceUrl); ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE; String identifier = resourceUrl.getFile(); ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier); if (scssStylesheet == null) { throw new Exception("ScssStylesheet is null for '" + identifier + "'"); } String content = scssStylesheet.toString(); String result = sourceMap.get(content); if (result == null) { scssStylesheet.compile(urlMode); Writer writer = new StringWriter(); scssStylesheet.write(writer, minify); result = writer.toString(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
ScssStylesheet scss = ScssStylesheet.get(cache.getAbsolutePath()); scss.addResolver(new ScssStylesheetResolver() {