public RuleNode createNewRuleNodeFromChild(RuleNode child) { StringBuilder builder = new StringBuilder(name); builder.append("-").append(child.getVariable()); RuleNode newRuleNode = new RuleNode(builder.toString(), child.getValue(), child.isImportant(), null); return newRuleNode; }
@Override public void replaceVariables(ArrayList<VariableNode> variables) { for (Node child : getChildren()) { if (child instanceof RuleNode) { ((RuleNode) child).replaceVariables(variables); } } }
@Override public void property(String name, LexicalUnitImpl value, boolean important, String comment) { RuleNode node = new RuleNode(name, value, important, comment); nodeStack.peek().appendChild(node); }
private static void updateUrlInImportedSheet(Node node, String prefix) { for (Node child : node.getChildren()) { if (child instanceof RuleNode) { LexicalUnit value = ((RuleNode) child).getValue(); while (value != null) { if (value.getLexicalUnitType() == LexicalUnit.SAC_URI) { String path = value.getStringValue() .replaceAll("^\"|\"$", "") .replaceAll("^'|'$", ""); if (!path.startsWith("/") && !path.contains(":")) { path = prefix + path; path = StringUtil.cleanPath(path); ((LexicalUnitImpl) value).setStringValue(path); } } value = value.getNextLexicalUnit(); } } updateUrlInImportedSheet(child, prefix); } } }
@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()); } } }