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); } }
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; }
@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()); } } }
ScssStylesheet scss = ScssStylesheet.get(cache.getAbsolutePath()); scss.addResolver(new ScssStylesheetResolver() { scss.compile(); SassCompiler.writeFile(css.getAbsolutePath(), scss.printState());
stylesheet.setCharset(getEncoding()); stylesheet.addSourceUris(Collections.singletonList(resource.getUri())); stylesheet.compile(); List<Node> children = stylesheet.getChildren(); if (children.size() > 0) { string.append(ScssStylesheet.PRINT_STRATEGY.build(children.get(0)));
try { StringBuilder filePathBuilder = new StringBuilder( styleSheet.getFileName()); filePathBuilder.append(File.separatorChar).append( importNode.getUri()); ScssStylesheet imported = ScssStylesheet.get( filePathBuilder.toString(), styleSheet.getCharset()); if (imported == null) { imported = ScssStylesheet.get(importNode.getUri()); + ScssStylesheet.get().getFileName() + ")"); new ArrayList<Node>(imported.getChildren()), importNode); node.removeChild(importNode);
/** * 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); }
ScssStylesheet stylesheet = handler.getStyleSheet(); InputSource source = stylesheet.resolveStylesheet(identifier); if (source == null) { return null; stylesheet.setCharset(parser.getInputSource().getEncoding()); return stylesheet;
ScssStylesheet scss = ScssStylesheet.get(sassFile); if (scss == null) { throw new IllegalArgumentException("SASS file: " + sassFile + " not found"); scss.compile(); String filteredScss = scss.printState().replace("@version@", version);
ScssStylesheet scss = ScssStylesheet.get(sassFile); if (scss == null) { throw new IllegalArgumentException("SASS file: " + sassFile + " not found"); scss.compile(); BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName)); out.write(cssHeader.toString()); out.write(scss.toString().replace("@version@", version)); out.close(); + scss.toString().length() + " bytes)");
public static void traverse(ExtendNode node) throws Exception { buildExtendsMap(node); modifyTree(ScssStylesheet.get()); }
@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); } }