Ejemplo n.º 1
0
  public boolean appendComposedExpression(BinaryExpression expression) {
    append(expression.getLeft());
    append(expression.getOperator());
    append(expression.getRight());

    return true;
  }
Ejemplo n.º 2
0
 private boolean appendSupports(Supports node) {
   cssOnly.append(node.getDialect()).ensureSeparator();
   append(node.getCondition());
   cssOnly.ensureSeparator();
   append(node.getBody());
   return true;
 }
Ejemplo n.º 3
0
  private void appendBodySortDeclarations(Body node) {
    // this is sort of hack, bypass the usual append method
    appendComments(node.getOpeningComments(), true);

    if (!isCompressing()) cssOnly.ensureSeparator();
    append(node.getOpeningCurlyBrace());
    if (!isCompressing()) cssOnly.ensureNewLine().increaseIndentationLevel();

    Iterator<ASTCssNode> declarations = node.getDeclarations().iterator();
    List<ASTCssNode> notDeclarations = node.getNotDeclarations();
    while (declarations.hasNext()) {
      ASTCssNode declaration = declarations.next();
      append(declaration);
      if (!isCompressing() && (declarations.hasNext() || notDeclarations.isEmpty()))
        cssOnly.ensureNewLine();
    }

    appendAll(notDeclarations);

    appendComments(node.getOrphanComments(), false);
    if (!isCompressing()) cssOnly.decreaseIndentationLevel();
    append(node.getClosingCurlyBrace());

    // this is sort of hack, bypass the usual append method
    appendComments(node.getTrailingComments(), false);
  }
Ejemplo n.º 4
0
  public boolean appendSelectorAttribute(SelectorAttribute node) {
    cssOnly.append('[');
    cssOnly.append(node.getName());
    append(node.getOperator());
    append(node.getValue());
    cssOnly.append(']');

    return true;
  }
Ejemplo n.º 5
0
  private boolean appendUnknownAtRule(UnknownAtRule node) {
    cssOnly.append(node.getName()).ensureSeparator();

    appendCommaSeparated(node.getNames());

    append(node.getBody());
    append(node.getSemicolon());
    return true;
  }
Ejemplo n.º 6
0
  public boolean appendListExpression(ListExpression expression) {
    Iterator<Expression> iterator = expression.getExpressions().iterator();
    if (!iterator.hasNext()) return false;

    append(iterator.next());
    while (iterator.hasNext()) {
      append(expression.getOperator());
      append(iterator.next());
    }
    return true;
  }
Ejemplo n.º 7
0
 public boolean appendMediaExpression(FixedMediaExpression expression) {
   cssOnly.ensureSeparator().append('(');
   append(expression.getFeature());
   if (expression.getExpression() != null) {
     cssOnly.append(':');
     if (!isCompressing()) cssOnly.ensureSeparator();
     append(expression.getExpression());
   }
   cssOnly.append(')');
   return true;
 }
Ejemplo n.º 8
0
  public boolean appendMediaQuery(MediaQuery mediaQuery) {
    cssOnly.ensureSeparator();
    append(mediaQuery.getMedium());
    boolean needSeparator = (mediaQuery.getMedium() != null);
    for (MediaExpression mediaExpression : mediaQuery.getExpressions()) {
      if (needSeparator) {
        cssOnly.ensureSeparator().append("and");
      }
      append(mediaExpression);
      needSeparator = true;
    }

    return true;
  }
Ejemplo n.º 9
0
  private boolean appendSupportsConditionLogical(SupportsLogicalCondition node) {
    Iterator<SupportsLogicalOperator> operators = node.getLogicalOperators().iterator();
    Iterator<SupportsCondition> conditions = node.getConditions().iterator();

    append(conditions.next());

    while (operators.hasNext()) {
      cssOnly.ensureSeparator();
      append(operators.next());
      cssOnly.ensureSeparator();
      append(conditions.next());
    }
    return true;
  }
Ejemplo n.º 10
0
  private boolean appendPage(Page node) {
    cssOnly.append("@page").ensureSeparator();
    if (node.hasName()) {
      append(node.getName());
      if (!node.hasDockedPseudopage()) cssOnly.ensureSeparator();
    }

    if (node.hasPseudopage()) {
      append(node.getPseudopage());
      cssOnly.ensureSeparator();
    }

    appendBodySortDeclarations(node.getBody());
    return true;
  }
Ejemplo n.º 11
0
  private boolean appendSimpleSelector(SimpleSelector selector) {
    if (selector.hasLeadingCombinator()) append(selector.getLeadingCombinator());

    appendSimpleSelectorHead(selector);
    appendSimpleSelectorTail(selector);
    return true;
  }
Ejemplo n.º 12
0
  private boolean appendDocument(Document node) {
    cssOnly.append(node.getDialect()).ensureSeparator();

    appendCommaSeparated(node.getUrlMatchFunctions());
    append(node.getBody());
    return true;
  }
Ejemplo n.º 13
0
  private boolean appendKeyframes(Keyframes node) {
    cssOnly.append(node.getDialect()).ensureSeparator();

    appendCommaSeparated(node.getNames());
    append(node.getBody());
    return true;
  }
Ejemplo n.º 14
0
  public boolean appendCharsetDeclaration(CharsetDeclaration node) {
    cssAndSM.append("@charset", node.getUnderlyingStructure()).ensureSeparator();
    append(node.getCharset());
    cssOnly.append(';');

    return true;
  }
Ejemplo n.º 15
0
  public boolean appendNamedExpression(NamedExpression expression) {
    cssOnly.append(expression.getName());
    cssOnly.append('=');
    append(expression.getExpression());

    return true;
  }
Ejemplo n.º 16
0
  private boolean appendBodyOptimizeDuplicates(Body body) {
    if (body.isEmpty()) return false;

    if (!isCompressing()) cssOnly.ensureSeparator();
    append(body.getOpeningCurlyBrace());
    if (!isCompressing()) cssOnly.ensureNewLine().increaseIndentationLevel();
    Iterable<CssPrinter> declarationsBuilders = collectUniqueBodyMembersStrings(body);
    for (CssPrinter miniBuilder : declarationsBuilders) {
      append(miniBuilder);
    }

    appendComments(body.getOrphanComments(), false);
    cssOnly.decreaseIndentationLevel();
    append(body.getClosingCurlyBrace());

    return true;
  }
Ejemplo n.º 17
0
  private boolean appendFunctionExpression(FunctionExpression node) {
    cssOnly.append(node.getName());
    cssOnly.append('(');
    append(node.getParameter());
    cssOnly.append(')');

    return true;
  }
Ejemplo n.º 18
0
  private boolean appendNth(Nth node) {
    switch (node.getForm()) {
      case EVEN:
        cssOnly.append("even");
        return true;

      case ODD:
        cssOnly.append("odd");
        return true;

      case STANDARD:
        if (node.getRepeater() != null) append(node.getRepeater());
        if (node.getMod() != null) append(node.getMod());
    }

    return true;
  }
Ejemplo n.º 19
0
  public boolean appendRuleset(RuleSet ruleSet) {
    if (ruleSet.hasEmptyBody()) return false;

    appendSelectors(ruleSet.getSelectors());
    append(ruleSet.getBody());

    return true;
  }
Ejemplo n.º 20
0
  private boolean appendImport(Import node) {
    cssOnly.append("@import").ensureSeparator();
    append(node.getUrlExpression());
    appendCommaSeparated(node.getMediums());
    cssOnly.append(';');

    return true;
  }
Ejemplo n.º 21
0
  public boolean appendPseudoClass(PseudoClass node) {
    cssAndSM.append(node.getFullName(), node.getUnderlyingStructure());
    if (node.hasParameters()) {
      cssOnly.append('(');
      append(node.getParameter());
      cssOnly.append(')');
    }

    return true;
  }
Ejemplo n.º 22
0
  public boolean appendDeclaration(Declaration declaration) {
    cssOnly.appendIgnoreNull(declaration.getNameAsString());
    cssOnly.append(':');
    if (!isCompressing()) cssOnly.ensureSeparator();
    if (declaration.getExpression() != null) append(declaration.getExpression());

    if (shouldHaveSemicolon(declaration)) cssOnly.appendIgnoreNull(";");

    return true;
  }
Ejemplo n.º 23
0
  private Iterable<CssPrinter> collectUniqueBodyMembersStrings(Body body) {
    // the same declaration must be printed only once
    LastOfKindSet<String, CssPrinter> declarationsStrings = new LastOfKindSet<String, CssPrinter>();
    for (ASTCssNode declaration : body.getMembers()) {
      CssPrinter miniPrinter = new CssPrinter(this);

      miniPrinter.append(declaration);
      if (!isCompressing()) miniPrinter.cssOnly.ensureNewLine();

      declarationsStrings.add(miniPrinter.toCss().toString(), miniPrinter);
    }

    return declarationsStrings;
  }
Ejemplo n.º 24
0
  private String doCompile(String lessContent) throws Less4jException {

    ANTLRParser.ParseResult result = parser.parseStyleSheet(lessContent);
    if (result.hasErrors()) {
      CompilationResult compilationResult =
          new CompilationResult("Errors during parsing phase, partial result is not available.");
      throw new Less4jException(result.getErrors(), compilationResult);
    }
    StyleSheet lessStyleSheet = astBuilder.parse(result.getTree());
    ASTCssNode cssStyleSheet = compiler.compileToCss(lessStyleSheet);

    CssPrinter builder = new CssPrinter();
    builder.append(cssStyleSheet);
    return builder.toString();
  }
Ejemplo n.º 25
0
  public boolean appendCommaSeparated(List<? extends ASTCssNode> values) {
    boolean result = false;
    Iterator<? extends ASTCssNode> names = values.iterator();
    if (names.hasNext()) {
      result |= append(names.next());
    }
    while (names.hasNext()) {
      cssOnly.append(',');
      if (!isCompressing()) cssOnly.ensureSeparator();
      append(names.next());
      result = true;
    }

    return result;
  }
Ejemplo n.º 26
0
  public void appendSelectors(List<Selector> selectors) {
    selectors = filterSilent(selectors);
    // follow less.js formatting in special case - only one empty selector
    if (selectors.size() == 1 && isEmptySelector(selectors.get(0))) {
      cssOnly.append(' ');
    }

    Iterator<Selector> iterator = selectors.iterator();
    while (iterator.hasNext()) {
      Selector selector = iterator.next();
      append(selector);

      if (iterator.hasNext()) cssOnly.append(',').newLine();
    }
  }
Ejemplo n.º 27
0
 private boolean appendViewport(Viewport node) {
   cssOnly.append(node.getDialect());
   append(node.getBody());
   return true;
 }
Ejemplo n.º 28
0
 public boolean appendSelector(Selector selector) {
   for (SelectorPart part : selector.getParts()) {
     append(part);
   }
   return true;
 }
Ejemplo n.º 29
0
  public boolean appendFontFace(FontFace node) {
    cssAndSM.append("@font-face", node.getUnderlyingStructure()).ensureSeparator();
    append(node.getBody());

    return true;
  }
Ejemplo n.º 30
0
  public boolean appendMedium(Medium medium) {
    append(medium.getModifier());
    append(medium.getMediumType());

    return true;
  }