Exemplo n.º 1
0
  protected void writeCssTo(Writer writer, Output output) throws IOException {
    Object[] results;
    Mapper mapper;
    Node node;

    if (output.getMuted()) {
      throw new IllegalArgumentException();
    }
    mapper = SSASS.newInstance();
    mapper.setErrorHandler(new ExceptionErrorHandler());
    for (int i = 0; i < nodes.size(); i++) {
      node = nodes.get(i);
      if (i > 0) {
        writer.write(LF);
      }
      if (!overallMinimize) {
        writer.write(type.comment(location(node)));
      }
      results = mapper.run(node);
      if (results == null) {
        throw new IOException(node.toString() + ": css/sass error");
      }
      output.setMuted(declarationsOnly.get(i));
      try {
        ((Stylesheet) results[0]).toCss(output);
      } catch (GenericException e) {
        throw new IOException(node.toString() + ": css generation failed: " + e.getMessage(), e);
      }
      if (output.getMuted() != declarationsOnly.get(i)) {
        throw new IllegalStateException();
      }
    }
  }
Exemplo n.º 2
0
  /** core method */
  private void writeJsTo(Writer writer) throws IOException {
    Compiler compiler;
    CompilerOptions options;
    List<SourceFile> externals;
    List<SourceFile> sources;
    Result result;
    boolean first;
    int i;
    Node node;

    compiler = new Compiler(new LoggerErrorManager());
    options = new CompilerOptions();
    options.setOutputCharset(Engine.ENCODING);
    sources = new ArrayList<>();
    externals = new ArrayList<>();
    for (i = 0; i < nodes.size(); i++) {
      node = nodes.get(i);
      sources.add(
          SourceFile.fromCode(
              location(node) + /* to get unique names, which is checked by the compiler: */ "_" + i,
              readString(node)));
    }
    result = compiler.compile(externals, sources, options);
    if (!result.success) {
      if (result.errors.length < 1) {
        throw new IllegalStateException();
      }
      throw new IOException(
          result.errors[0].sourceName
              + ":"
              + result.errors[0].lineNumber
              + ":"
              + result.errors[0].description);
    }
    if (overallMinimize) {
      writer.write(compiler.toSource());
    } else {
      first = true;
      for (SourceFile source : sources) {
        if (first) {
          first = false;
        } else {
          writer.write(LF);
        }
        if (!overallMinimize) {
          writer.write(type.comment(source.getName()));
        }
        writer.write(source.getCode());
      }
    }
  }