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); } }
public SCSSDocumentHandlerImpl() { this(new ScssStylesheet()); }
public static void traverse(VariableNode node) { VariableNode variable = ScssStylesheet.getVariable(node.getName()); if (!node.isGuarded() || variable == null || variable.getExpr() == null || (variable.getExpr().getLexicalUnitType() == SCSSLexicalUnit.SCSS_NULL && variable .getExpr().getNextLexicalUnit() == null)) { ScssStylesheet.addVariable(node); } node.getParentNode().removeChild(node); } }
public static void traverse(ExtendNode node) throws Exception { buildExtendsMap(node); modifyTree(ScssStylesheet.get()); }
/** * 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); }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); ScssStylesheet.addVariable(getModifiedList()); getParentNode().removeChild(this); }
@Override public void traverse() { try { // limit variable scope to the mixin Map<String, VariableNode> variableScope = ScssStylesheet .openVariableScope(); replaceVariables(ScssStylesheet.getVariables()); replaceVariablesForChildren(); MixinNodeHandler.traverse(this); ScssStylesheet.closeVariableScope(variableScope); } catch (Exception e) { e.printStackTrace(); } }
@Override public void traverse() { /* * "replaceVariables(ScssStylesheet.getVariables());" seems duplicated * and can be extracted out of if, but it is not. * containsArithmeticalOperator must be called before replaceVariables. * Because for the "/" operator, it needs to see if its predecessor or * successor is a Variable or not, to determine it is an arithmetic * operator. */ if (ArithmeticExpressionEvaluator.get().containsArithmeticalOperator( value)) { replaceVariables(ScssStylesheet.getVariables()); value = ArithmeticExpressionEvaluator.get().evaluate(value); } else { replaceVariables(ScssStylesheet.getVariables()); } } }
public void removeEmptyBlocks(Node node) { // depth first for avoiding re-checking parents of removed nodes for (Node child : new ArrayList<Node>(node.getChildren())) { removeEmptyBlocks(child); } Node parent = node.getParentNode(); if (node instanceof BlockNode && node.getChildren().isEmpty() && parent != null) { // remove empty block parent.removeChild(node); } }
protected void replaceVariablesForChildren() { for (Node child : getChildren()) { if (child instanceof IVariableNode) { ((IVariableNode) child).replaceVariables(ScssStylesheet .getVariables()); } } }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); EachNodeHandler.traverse(this); } }
@Override public void traverse() { try { BlockNodeHandler.traverse(this); replaceVariables(ScssStylesheet.getVariables()); } catch (Exception e) { e.printStackTrace(); } }
private static void replaceMixins(MixinNode node) throws Exception { MixinDefNode mixinDef = ScssStylesheet.getMixinDefinition(node .getName()); if (mixinDef == null) { throw new Exception("Mixin Definition: " + node.getName() + " not found"); } replaceMixinNode(node, mixinDef); }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); } }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); } }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); } }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); }
@Override public void traverse() { replaceVariables(ScssStylesheet.getVariables()); }
@Override public void traverse() { if (!arglist.isEmpty()) { for (final VariableNode arg : arglist) { if (arg.getExpr() != null) { ScssStylesheet.addVariable(arg); } } } }