All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bit3.jsass.importer.JsassCustomHeaderImporter Maven / Gradle / Ivy

There is a newer version: 5.11.1
Show newest version
package io.bit3.jsass.importer;

import io.bit3.jsass.context.ImportStack;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class JsassCustomHeaderImporter implements Importer {

  private final ImportStack importStack;

  public JsassCustomHeaderImporter(ImportStack importStack) {
    this.importStack = importStack;
  }

  @Override
  public Collection apply(String url, Import previous) {
    List list = new LinkedList<>();

    list.add(createCustomHeaderImport(previous));

    return list;
  }

  private Import createCustomHeaderImport(Import previous) {
    int id = importStack.register(previous);

    StringBuilder source = new StringBuilder();

    // $jsass-void: jsass_import_stack_push() !global;
    source.append(
        String.format(
            "$jsass-void: jsass_import_stack_push(%d) !global;%n",
            id
        )
    );

    try {
      return new Import(
          new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"),
          new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"),
          source.toString()
      );
    } catch (URISyntaxException e) {
      throw new ImportException(e);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy